あとAUCも追加

AUC(Area Under the ROC Curve)は、モデルの性能を評価する際に一般的に使用されるメトリックの1つです。以下は、AUCを追加してモデルの性能を評価する方法です。

python
from sklearn.metrics import roc_auc_score, roc_curve import matplotlib.pyplot as plt # テストデータでの予測確率を取得 y_pred_proba_test = rf_classifier.predict_proba(X_test)[:, 1] # AUCを計算 auc_score = roc_auc_score(y_test, y_pred_proba_test) print("AUC Score:", auc_score) # ROC曲線をプロット fpr, tpr, thresholds = roc_curve(y_test, y_pred_proba_test) plt.figure() plt.plot(fpr, tpr, label='ROC curve (area = %0.2f)' % auc_score) plt.plot([0, 1], [0, 1], 'k--') plt.xlim([0.0, 1.0]) plt.ylim([0.0, 1.05]) plt.xlabel('False Positive Rate') plt.ylabel('True Positive Rate') plt.title('Receiver Operating Characteristic (ROC) Curve') plt.legend(loc="lower right") plt.show()

このコードでは、roc_auc_score関数を使用してAUCを計算し、roc_curve関数を使用してROC曲線をプロットしています。ROC曲線は、真陽性率(True Positive Rate)と偽陽性率(False Positive Rate)の関係を示し、AUCはROC曲線の下の面積を表します。 AUCが1に近いほどモデルの性能が高いことを示します。

未分類

Posted by ぼっち