-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredict.py
58 lines (49 loc) · 1.51 KB
/
predict.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sys
from colors import colors
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
def main():
try:
import theta
theta1 = theta.theta1
theta0 = theta.theta0
except:
theta1 = 0
theta0 = 0
while 42:
try:
input_mileage = int(input(f"{colors().BLUE}Which mileage do you want to have a price estimation for? {colors().END}"))
if input_mileage < 0 or input_mileage > 1000000:
print(f"{colors().RED}Invalid input, please enter a positive integer value!{colors().END}")
continue
break
except:
print(f"{colors().RED}Invalid input, please enter a positive integer value!{colors().END}")
prediction = round(theta1 * int(input_mileage) + theta0)
if prediction < 0:
prediction = 0
print(f"\n{colors().BLUE}ESTIMATED PRICE: ${prediction}{colors().END}\n")
if theta0 and theta1:
# Plot the resulting regression line
try:
data = pd.read_csv('data.csv')
except:
print(f"{colors().RED}Error: could not read file{colors().END}")
exit()
max_km = data['km'].max()
max_price = data['price'].max()
tmp_max_km = max_km
if input_mileage > max_km:
tmp_max_km = input_mileage
plt.plot(
list(range(0, tmp_max_km)),
[theta1 * x + theta0 for x in range(0, tmp_max_km)],
color="green")
# uncomment below for prediction marker
plt.plot(input_mileage, prediction, marker="s", markersize=10, markerfacecolor="lightblue")
plt.scatter(data.km, data.price, color="black")
plt.show()
if __name__ == '__main__':
main()