generated from VicariousVision/load-shortfall-regression-predict-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regression code.txt
45 lines (37 loc) · 1.65 KB
/
regression code.txt
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
#MLR:
#loading data
X= df.drop(['load_shortfall_3h','time','Seville_pressure','Valencia_wind_deg','Unnamed: 0','Valencia_pressure'],axis=1)
y= df['load_shortfall_3h']
#Training model
linear_regression = LinearRegression()
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.20,random_state=1)
linear_regression.fit(X_train,y_train)
#The parameters of the best fit line:
beta_0 = float(linear_regression.intercept_)
beta_js = pd.DataFrame(linear_regression.coef_, X.columns, columns=['Coefficient'])
print("Intercept:", beta_0)
beta_js
#SLR:
slr = LinearRegression()
slr.fit(X_train[['Madrid_temp_min']], y_train)
from sklearn import metrics
import math
#Results:
results_dict = {'Training MSE':
{
"SLR": metrics.mean_squared_error(y_train, slr.predict(X_train[['Madrid_temp_min']])),
"MLR": metrics.mean_squared_error(y_train, linear_regression.predict(X_train))
},
'Test MSE':
{
"SLR": metrics.mean_squared_error(y_test, slr.predict(X_test[['Madrid_temp_min']])),
"MLR": metrics.mean_squared_error(y_test, linear_regression.predict(X_test))
},
'Test RMSE':
{
"SLR": math.sqrt(metrics.mean_squared_error(y_test, slr.predict(X_test[['Madrid_temp_min']]))),
"MLR": math.sqrt(metrics.mean_squared_error(y_test, linear_regression.predict(X_test)))
}
}
results_df = pd.DataFrame(data=results_dict)
round(results_df,1)