from sklearn import metrics
def scoring(y_true, y_pred):
r2 = round(metrics.r2_score(y_true, y_pred) * 100, 3)
# mae = round(metrics.mean_absolute_error(y_true, y_pred),3)
corr = round(np.corrcoef(y_true, y_pred)[0, 1], 3)
mape = round(
metrics.mean_absolute_percentage_error(y_true, y_pred) * 100, 3)
rmse = round(metrics.mean_squared_error(y_true, y_pred, squared=False), 3)
df = pd.DataFrame({
'R2': r2,
"Corr": corr,
"RMSE": rmse,
"MAPE": mape
},
index=[0])
return df
#####################################################
def abline(slope, intercept):
"""Plot a line from slope and intercept"""
axes = plt.gca()
x_vals = np.array(axes.get_xlim())
y_vals = intercept + slope * x_vals
plt.plot(x_vals, y_vals, '--')
def MinMax(y_true, y_pred, m="min") :
if(m == "min") :
return min(min(y_true),min(y_pred)) -2
else :
return max(max(y_true),max(y_pred)) +2
def myGraph(temp) :
fig, axs = plt.subplots(1,2,figsize=(20,5), gridspec_kw={'width_ratios': [2.5, 1]})
axs[0].plot(temp.Date, temp.y_true, label = "Original")
axs[0].plot(temp.Date, temp.y_pred, label = " Predicted")
axs[0].legend(loc='upper right')
# axs[0].title.set_text(title)
axs[0].set_xlabel("Date")
axs[0].set_ylabel("Sales")
axs[1].plot(temp.y_true,temp.y_pred,'.')
plt.xlim(MinMax(temp.y_true,temp.y_pred),MinMax(temp.y_true,temp.y_pred,"max"))
plt.ylim(MinMax(temp.y_true,temp.y_pred),MinMax(temp.y_true,temp.y_pred,"max"))
abline(1,0)
# plt.title(title)
plt.xlabel("Original")
plt.ylabel("Predicted")
########################################################
def myGrape(y_valid, y_pred) :
fig, axs = plt.subplots(1,2,figsize=(20,5), gridspec_kw={'width_ratios': [2.5, 1]})
axs[0].plot(range(len(y_valid)),y_valid,'-o', label='true')
axs[0].plot(range(len(y_valid)),y_pred,'-o', label='predict')
axs[0].legend(loc='upper right')
plt.yticks(np.arange(0.052,0.065,0.001))
axs[0].set_xlabel('sample')
axs[0].set_xlabel('unsat')
axs[1].plot(y_valid,y_pred,'.')
abline(1,0)
'Python' 카테고리의 다른 글
Class 이해하기 :: Class를 쓰는 이유, Class vs function (13) | 2022.04.07 |
---|---|
[numpy tutorial] numpy에서 대각선 값 채우기 in python (0) | 2021.01.19 |
[Python] Pandas 기초 (0) | 2020.01.17 |
[python] 파이썬으로 순열, 조합 구하기 :: permutation in python/ combination in python (3) | 2019.11.20 |
[python] 튜플 정렬하기(두 번째 원소로 정렬하기) :: tuple sorting in python (1) | 2019.11.16 |