diff options
Diffstat (limited to 'predict.py')
| -rw-r--r-- | predict.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/predict.py b/predict.py new file mode 100644 index 0000000..3bbcb47 --- /dev/null +++ b/predict.py @@ -0,0 +1,40 @@ +import os +import sys + +THETAS_FILE = "thetas.csv" + + +def load_thetas(): + if not os.path.exists(THETAS_FILE): + return 0.0, 0.0 + with open(THETAS_FILE) as f: + lines = f.readlines() + return float(lines[0]), float(lines[1]) + + +def estimate_price(mileage, theta0, theta1): + return theta0 + theta1 * mileage + + +def main(): + theta0, theta1 = load_thetas() + if theta0 == 0.0 and theta1 == 0.0: + print(f"Warning: no trained model found ({THETAS_FILE}), using θ0=0 θ1=0") + else: + print(f"Loaded θ0={theta0}, θ1={theta1}") + while True: + try: + raw = input("\nMileage (km): ") + mileage = float(raw) + price = estimate_price(mileage, theta0, theta1) + print(f"Estimated price: {price:.2f}") + except ValueError: + print("Please enter a valid number.") + + +if __name__ == "__main__": + try: + main() + except (KeyboardInterrupt, EOFError): + print() + sys.exit(0) |
