-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
41 lines (30 loc) · 933 Bytes
/
model.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
import pandas as pd
import joblib
'''
from sklearn.ensemble import RandomForestRegressor
def train_model():
data = pd.read_csv("ResponseTimes.csv")
X = data[["EmergencyStations", "Area", "Urban"]]
Y = data[["ResponseTime"]]
Y = Y.to_numpy()
Y = Y.flatten()
clf = RandomForestRegressor()
clf.fit(X, Y)
predicted = clf.predict(X)
avg=0
for i in range(len(predicted)-1):
avg = avg + abs(predicted[i] - Y[[i]])
print(avg)
print("Loss: ", avg/len(predicted))
ans = input("Save?")
if ans == "y":
filename = 'model.sav'
joblib.dump(clf, "./random_forest.joblib")
'''
def predict(stations, area, urban):
clf = joblib.load("./random_forest.joblib")
prediction = clf.predict([[stations, area, urban]])
prediction = prediction.flatten()
return prediction[0].item()
'''print(predict(429,789,0.5))
print(type(predict(429,789,0.5)))'''