aboutsummaryrefslogtreecommitdiff
path: root/src/predict.py
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-23 09:57:39 +0100
committerCharles <sircharlesaze@gmail.com>2020-01-23 09:57:39 +0100
commit4537bdbebb5fe64c50080e7874d407f10a0676b7 (patch)
tree8466528ae9c3865e2543e7fdb9e9301bfef40490 /src/predict.py
parent1e45848f0b84218dfbdb62e313b4c33791a98555 (diff)
downloadft_linear_regression-4537bdbebb5fe64c50080e7874d407f10a0676b7.tar.gz
ft_linear_regression-4537bdbebb5fe64c50080e7874d407f10a0676b7.tar.bz2
ft_linear_regression-4537bdbebb5fe64c50080e7874d407f10a0676b7.zip
WIP: CLI interface interact with Model class, subprogram call Model methods to satisfy the subject
Diffstat (limited to 'src/predict.py')
-rw-r--r--src/predict.py29
1 files changed, 11 insertions, 18 deletions
diff --git a/src/predict.py b/src/predict.py
index 85c7eac..329382a 100644
--- a/src/predict.py
+++ b/src/predict.py
@@ -1,22 +1,15 @@
-class Predictor:
- def __init__(self, filename='theta'):
- self.filename = filename
- self.theta1, self.theta0 = self.read_theta()
+from model import Model
- def make_prediction(self, x):
- return x * self.theta1 + self.theta0
-
- def read_theta(self):
+def predict_input(m):
+ while True:
try:
- with open(self.filename, 'r') as file:
- strs = file.read().strip().split(",")
- if len(strs) != 2:
- raise "wrong theta file format"
- return int(strs[0]), int(strs[1])
- except IOError:
- print(self.filename, "do not exist")
+ x = int(input("Enter a mileage: "))
+ except ValueError:
+ print("Bad input, you should enter a number")
+ else:
+ break
+ print("The predicted price for this mileage is", m.hypothesis(x))
if __name__ == "__main__":
- p = Predictor()
- x = int(input("Enter a mileage: "))
- print("The predicted price for this mileage is", p.make_prediction(x))
+ m = Model(thetafilename="./theta")
+ predict_input(m)