LoginSignup
31
47

More than 5 years have passed since last update.

ROC曲線とAUCの出力

Posted at

PythonでROC曲線を描画してみた

前提

  1. Python
  2. ロジスティック回帰で予測値出力済み
  3. scikit-learnとmatplotlibを使う

コード

roc.py
from sklearn import metrics
import matplotlib.pyplot as plt
import numpy as np

# FPR, TPR(, しきい値) を算出
fpr, tpr, thresholds = metrics.roc_curve(test_y, predict_y)

# ついでにAUCも
auc = metrics.auc(fpr, tpr)

# ROC曲線をプロット
plt.plot(fpr, tpr, label='ROC curve (area = %.2f)'%auc)
plt.legend()
plt.title('ROC curve')
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.grid(True)

roc_curve.png

参考

ROC曲線とAUCについてはこちらを参考に。

【統計学】ROC曲線とは何か、アニメーションで理解する。
【ROC曲線とAUC】機械学習の評価指標についての基礎講座

31
47
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
47