diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-01-22 18:05:06 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-01-22 18:05:33 +0100 |
| commit | 1e45848f0b84218dfbdb62e313b4c33791a98555 (patch) | |
| tree | 727e277ef8c688801220eaa14d2b710126116c11 /src/predict.py | |
| parent | 79f3505b2611b0f6a210224d38d59002597379e6 (diff) | |
| download | ft_linear_regression-1e45848f0b84218dfbdb62e313b4c33791a98555.tar.gz ft_linear_regression-1e45848f0b84218dfbdb62e313b4c33791a98555.tar.bz2 ft_linear_regression-1e45848f0b84218dfbdb62e313b4c33791a98555.zip | |
Moved notebook to notebook/, Added predict.py and train.py template
Diffstat (limited to 'src/predict.py')
| -rw-r--r-- | src/predict.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/predict.py b/src/predict.py new file mode 100644 index 0000000..85c7eac --- /dev/null +++ b/src/predict.py @@ -0,0 +1,22 @@ +class Predictor: + def __init__(self, filename='theta'): + self.filename = filename + self.theta1, self.theta0 = self.read_theta() + + def make_prediction(self, x): + return x * self.theta1 + self.theta0 + + def read_theta(self): + 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") + +if __name__ == "__main__": + p = Predictor() + x = int(input("Enter a mileage: ")) + print("The predicted price for this mileage is", p.make_prediction(x)) |
