Skip to content

Instantly share code, notes, and snippets.

@sh16ma
Last active January 10, 2022 23:43
Show Gist options
  • Save sh16ma/ddcb573bbeb86f40cc22166ed1cb31a2 to your computer and use it in GitHub Desktop.
Save sh16ma/ddcb573bbeb86f40cc22166ed1cb31a2 to your computer and use it in GitHub Desktop.
#🐍 #Python #評価指標 #混同行列 #正解率 #適合率 #再現率 #F値 #自作関数
from sklearn.metrics import accuracy_score # 正解率
from sklearn.metrics import precision_score # 適合率
from sklearn.metrics import recall_score # 再現率
from sklearn.metrics import f1_score # F値
def evaluations(y_test, y_predict, average) -> dict: # 辞書型で返す
"""
y_test:
予測したいデータ
y_predict:
アルゴリズムで予測したデータ
average:
macro/micro/
"""
accuracy = accuracy_score(test, predict)
precision = precision_score(test, predict, average=average)
recall = recall_score(test, predict, average=average)
f1 = f1_score(test, predict, average=average)
evaluations = {
"正解率" : round(accuracy, 3),
"適合率" : round(precision, 3),
"再現率" : round(recall, 3),
"F値" : round(f1, 3)
}
return evaluations
@sh16ma
Copy link
Author

sh16ma commented Feb 1, 2021

スクリーンショット 2021-02-01 19 57 30

スクリーンショット 2021-02-01 19 55 36

PandasのDataFrame型にすれば綺麗に見えるよ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment