-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
38 lines (28 loc) · 823 Bytes
/
Copy pathplot.py
File metadata and controls
38 lines (28 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import csv
import json
import matplotlib.pyplot as plt
mileages = []
prices = []
with open("data.csv", "r") as file:
reader = csv.DictReader(file)
for row in reader:
mileages.append(float(row["km"]))
prices.append(float(row["price"]))
with open("model.json", "r") as file:
model = json.load(file)
theta0 = model["theta0"]
theta1 = model["theta1"]
min_km = model["min_km"]
max_km = model["max_km"]
x_values = [min(mileages), max(mileages)]
y_values = []
for mileage in x_values:
mileage_normalized = (mileage - min_km) / (max_km - min_km)
predicted_price = theta0 + theta1 * mileage_normalized
y_values.append(predicted_price)
plt.scatter(mileages, prices)
plt.plot(x_values, y_values)
plt.xlabel("Mileage")
plt.ylabel("Price")
plt.title("Linear regression")
plt.show()