-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGenSet_1.py
83 lines (49 loc) · 1.74 KB
/
GenSet_1.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
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 10 15:36:29 2020
@author: Dell
"""
import pandas as pd
from sklearn.utils import shuffle
from sklearn import linear_model
from sklearn.model_selection import cross_val_score, cross_validate, cross_val_predict
import numpy as np
from sklearn.gaussian_process.kernels import RBF
from sklearn.gaussian_process import GaussianProcessRegressor
from math import sqrt as sq
import matplotlib.pyplot as plt
import time
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
from joblib import dump,load
#%%
Demand = pd. DataFrame()
for i in range(50, 570,50):
Village = 'village_' + str(i)
Energy_Demand = pd.read_excel('Example/Demand.xls',sheet_name=Village
,index_col=0,Header=None)
Demand.loc[i, 'demand'] = round(Energy_Demand[1].max()/1000,2)
#%%
y = Demand['demand']
X = list(Demand.index)
#%%
y, X = shuffle(y, X, random_state=10)
#%%
X = np.array(X)
X = X.reshape(-1, 1)
#%%
scoring = 'r2' #'r2' 'neg_mean_absolute_error' # 'neg_mean_squared_error'
lm = linear_model.LinearRegression(fit_intercept=True)
Results = cross_validate(lm, X, y, cv=2,return_train_score=True,n_jobs=-1
, scoring = scoring )
scores = Results['test_score']
score = scores.mean()
if scoring == 'neg_mean_squared_error':
score = sq(-score)
print(scoring + ' for the linear regression with the test data set is ' + str(score))
else:
print(scoring + ' for the linear regression with the test data set is ' + str(score))
#%%
lm1= linear_model.LinearRegression(fit_intercept=True)
lm1 = lm1.fit(X,y)
dump(lm1, 'GenSet_Chaco.joblib')