-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_prediction.py
More file actions
65 lines (54 loc) · 2.03 KB
/
Copy pathplot_prediction.py
File metadata and controls
65 lines (54 loc) · 2.03 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
64
65
from Li_metal_feature_extraction import *
from sklearn.model_selection import LeaveOneOut
from sklearn.pipeline import make_pipeline
from sklearn.linear_model import LinearRegression, ElasticNet
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import cross_validate
from sklearn.model_selection import cross_val_predict
from sklearn.dummy import DummyRegressor
from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_absolute_percentage_error
from sklearn import metrics as met
from sklearn.ensemble import RandomForestRegressor
import matplotlib.pyplot as plt
rmse_mean, rmse_std = [], []
true_rmse_mean, true_rmse_std = [], []
mape_mean, mape_std = [], []
true_mape_mean, true_mape_std = [], []
def true_RMSE(y_true, y_pred):
return mean_squared_error(np.power(10, y_true), np.power(10, y_pred), squared=False)
def true_MAPE(y_true, y_pred):
return mean_absolute_percentage_error(np.power(10, y_true), np.power(10, y_pred))
#eof: type of end of life condition:
# '80': reach 80%
# 'short' short circut
# 'all': full dataset
np.random.seed(42)
Xs, Ys = get_Li_metal_all_feature_dataset(eof='short')
p = np.random.permutation(len(Xs))
Xs = Xs[p]
Ys = Ys[p]
trainlen = int(0.8*len(Xs))
train_Xs = Xs[:trainlen]
train_Ys = Ys[:trainlen]
val_Xs = Xs[trainlen:]
val_Ys = Ys[trainlen:]
scaler = StandardScaler().fit(train_Xs)
X_train_scaled = scaler.transform(train_Xs)
X_val_scaled = scaler.transform(val_Xs)
enet=ElasticNet()
enet.fit(X_train_scaled, train_Ys)
y_train_pred = enet.predict(X_train_scaled)
y_val_pred = enet.predict(X_val_scaled)
fig = plt.figure(figsize=(10,10))
ax1 = fig.add_subplot(111)
ax1.scatter(train_Ys, y_train_pred, c='crimson',label='Train')
ax1.scatter(val_Ys, y_val_pred, c='blue',label='Validation')
p1 = max(max(y_train_pred), max(train_Ys))
p2 = min(min(y_train_pred), min(train_Ys))
ax1.plot([250, 30], [250, 30], 'b-')
ax1.legend()
plt.xlabel('True Values', fontsize=15)
plt.ylabel('Predictions', fontsize=15)
plt.axis('equal')
plt.savefig('plt/Pred_True_short_best.png')