2024-10-05 13:08:25 发布
网友
我想使用Python和sklearn绘制随机森林分类器的出袋(oob)真阳性率和假阳性率的ROC曲线。你知道吗
我知道这在R中是可能的,但似乎找不到任何关于如何在Python中实现这一点的信息。你知道吗
.oob_decision_function_
附言:这可以在scikit-learn==0.22
scikit-learn==0.22
小例子:
import matplotlib.pyplot as plt from sklearn.ensemble import RandomForestClassifier from sklearn.metrics import plot_roc_curve from sklearn.datasets import load_wine from sklearn.model_selection import train_test_split X, y = load_wine(return_X_y=True) y = y == 2 X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42) rfc = RandomForestClassifier(n_estimators=10, random_state=42, oob_score=True) rfc.fit(X_train, y_train) from sklearn import metrics pred_train = np.argmax(rfc.oob_decision_function_,axis=1) metrics.roc_auc_score(y_train, pred_train)
您需要
.oob_decision_function_
,它在拟合后返回袋外样本的预测概率附言:这可以在
scikit-learn==0.22
小例子:
相关问题 更多 >
编程相关推荐