-
Notifications
You must be signed in to change notification settings - Fork 1
/
GenSet_2.py
82 lines (52 loc) · 2.2 KB
/
GenSet_2.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
# -*- 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
#%%
data = pd.read_excel('Data_Base.xls', index_col=0, Header=None)
y = pd.DataFrame()
target= 'Max Demand' # 'Renewable Capacity' 'Renewable Penetration'
y[target] = data[target]*0.75
y=y.astype('float')
X = pd.DataFrame()
X['Renewable Invesment Cost'] = data['Renewable Unitary Invesment Cost']
X['Battery Unitary Invesment Cost'] = data['Battery Unitary Invesment Cost']
X['Deep of Discharge'] = data['Deep of Discharge']
X['Battery Cycles'] = data['Battery Cycles']
X['GenSet Unitary Invesment Cost'] = data['GenSet Unitary Invesment Cost']
X['Generator Efficiency'] = data['Generator Efficiency']
X['Low Heating Value'] = data['Low Heating Value']
X['Fuel Cost'] = data['Fuel Cost']
#X['Generator Nominal capacity'] = data['Generator Nominal capacity']
X['HouseHolds'] = data['HouseHolds']
X['Renewable Energy Unit Total'] = data['Renewable Energy Unit Total']
#X['Max Demand'] = data['Max Demand']
#%%
scoring = ['r2', 'neg_mean_absolute_error', 'neg_mean_squared_error'] #'r2' 'neg_mean_absolute_error' # 'neg_mean_squared_error'
for i in scoring:
lm = linear_model.LinearRegression(fit_intercept=False)
scores = cross_val_score(lm, X, y, cv=5,scoring=i)
score = round(scores.mean(),2)
if i == 'neg_mean_squared_error':
score = sq(-score)
print(i + ' for the gaussian process with the test data set is ' + str(score))
else:
print(i + ' for the gaussian process 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')