-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpm25_predict.py
More file actions
63 lines (57 loc) · 1.67 KB
/
pm25_predict.py
File metadata and controls
63 lines (57 loc) · 1.67 KB
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
59
60
61
62
63
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn import linear_model
name = "aqa_montesori_nivel_calle"
sumy = 0
mesures = pd.read_csv( name+".csv")
epochs = mesures["time"].values
#pm25s = mesures[name+".mean_pm25"].values
pm25s = mesures[name+".pm25"].values
lr = linear_model.LinearRegression()
#pm25s = [pm25 for pm25 in pm25s]
epochs = [epoch for epoch in range(len(epochs))]
epochs = np.asanyarray(epochs)
pm25s = np.asanyarray(pm25s)
epochs = epochs.reshape((1,-1))
pm25s = pm25s.reshape((1,-1))
lr.fit(epochs,pm25s )
print(epochs)
for i in epochs:
print(i,")",lr.predict(pm25s) )
print(i,")",pm25s)
#print("-----"*25)
print(pm25s)
print("-----"*25)
y = lr.predict(pm25s)
print(y)
for i in y:
sumy +=y
b = sumy/len(epochs)
for i in range (len(epochs)):
w = ((epochs[i]*epochs)-(pm25s[i]*pm25s))/((epochs[i]*epochs)**2)
prediction = w*epochs+b
#sumation=1/len(epochs)*sum(y-prediction*(epochs)**2,len(epochs))
#print(sumation)
for x in epochs:
for y2 in y:
filtred = np.polyfit(x, y2, 1)
print('Fitted Parameters:', filtred)
predictions = np.polyval(filtred, epochs)
absError = predictions - y
SE = np.square(absError) # squared errors
MSE = np.mean(SE) # mean squared errors
RMSE = np.sqrt(MSE) # Root Mean Squared Error, RMSE
Rsquared = 1.0 - (np.var(absError) / np.var(y))
plt.xlabel("epochs")
plt.ylabel("pm25")
plt.title("unloquer predict")
plt.plot(epochs,pm25s,'bo')
#plt.plot(epochs,,'go')
plt.plot(epochs,y,'g-')
plt.plot(epochs,prediction,'b-')
#X = np.linspace(min(epochs), max(epochs))
Y = np.polyval(predictions, epochs)
plt.plot(epochs*2,Y,"go",linewidth=2.0)
#plt.plot(epochs,prediction ,'ro',linewidth=2.0)
plt.show()