교재 : 파이썬 머신러닝 완벽 가이드, 위키북스
from sklearn.metrics import f1_score
def get_clf_eval(y_test, pred):
from sklearn.metrics import accuracy_score, precision_score, recall_score, confusion_matrix, f1_score
confusion = confusion_matrix(y_test,pred)
accuracy = accuracy_score(y_test,pred)
precision = precision_score(y_test,pred)
recall = recall_score(y_test,pred)
f1 = f1_score(y_test,pred)
print('오차행렬')
print(confusion)
print(f'정확도:{accuracy:.4f}, 정밀도:{precision:.4f}, 재현율{recall:.4f}, F1:{f1:.4f}')
thresholds = [0.4,0.45,0.5,0.55,0.6]
def get_eval_by_threshold(y_test,pred_proba_1,thresholds):
for custom_threshold in thresholds:
custom_predict = Binarizer(threshold=custom_threshold).fit_transform(pred_proba_1)
print(f'임계값:{custom_threshold}')
get_clf_eval(y_test,custom_predict)
get_eval_by_threshold(y_test,pred_proba_1,thresholds)
from sklearn.metrics import roc_curve
def roc_curve_plot(y_test,pred_proba_1):
from sklearn.metrics import roc_curve
import matplotlib.pyplot as plt
fprs, tprs, thresholds = roc_curve(y_test,pred_proba_1)
plt.plot(fprs, tprs,label='ROC')
plt.plot([0,1],[0,1],'k--',label='Random')
plt.legend()
plt.show()