From fd5fe70ce5271f09303b51dae34b42acc47f5730 Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Mon, 23 Mar 2026 21:17:11 +0100 Subject: Initial commit: linear regression for car price prediction Training, prediction, and visualization programs using gradient descent with min-max normalization. --- predict.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 predict.py (limited to 'predict.py') 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) -- cgit v1.2.3