15
Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.
Tôi đang xây dựng 2 mô hình.
Mô hình 1
modelgb = GradientBoostingClassifier[]
modelgb.fit[x_train,y_train]
predsgb = modelgb.predict_proba[x_test][:,1]
metrics.roc_auc_score[y_test,predsgb, average='macro', sample_weight=None]
Mô hình 2
model = LogisticRegression[]
model = model.fit[x_train,y_train]
predslog = model.predict_proba[x_test][:,1]
metrics.roc_auc_score[y_test,predslog, average='macro', sample_weight=None]
Làm thế nào để tôi vẽ cả hai đường cong ROC trong một ô, với một huyền thoại & văn bản về điểm AUC cho mỗi mô hình?
Đã hỏi ngày 20 tháng 3 năm 2017 lúc 2:22Mar 20, 2017 at 2:22
Learner_seekerLearner_seekerLearner_seeker
5241 Huy hiệu vàng4 Huy hiệu bạc 20 Huy hiệu đồng1 gold badge4 silver badges20 bronze badges
4
Hãy thử điều chỉnh điều này với dữ liệu của bạn:
from sklearn import metrics
import numpy as np
import matplotlib.pyplot as plt
plt.figure[0].clf[]
pred = np.random.rand[1000]
label = np.random.randint[2, size=1000]
fpr, tpr, thresh = metrics.roc_curve[label, pred]
auc = metrics.roc_auc_score[label, pred]
plt.plot[fpr,tpr,label="data 1, auc="+str[auc]]
pred = np.random.rand[1000]
label = np.random.randint[2, size=1000]
fpr, tpr, thresh = metrics.roc_curve[label, pred]
auc = metrics.roc_auc_score[label, pred]
plt.plot[fpr,tpr,label="data 2, auc="+str[auc]]
plt.legend[loc=0]
Đã trả lời ngày 20 tháng 3 năm 2017 lúc 3:28Mar 20, 2017 at 3:28
1
Chỉ bằng cách thêm các mô hình vào danh sách sẽ vẽ nhiều đường cong ROC trong một ô. Hy vọng rằng điều này phù hợp với bạn!
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import GradientBoostingClassifier
from sklearn import metrics
import matplotlib.pyplot as plt
plt.figure[]
# Add the models to the list that you want to view on the ROC plot
models = [
{
'label': 'Logistic Regression',
'model': LogisticRegression[],
},
{
'label': 'Gradient Boosting',
'model': GradientBoostingClassifier[],
}
]
# Below for loop iterates through your models list
for m in models:
model = m['model'] # select the model
model.fit[x_train, y_train] # train the model
y_pred=model.predict[x_test] # predict the test data
# Compute False postive rate, and True positive rate
fpr, tpr, thresholds = metrics.roc_curve[y_test, model.predict_proba[x_test][:,1]]
# Calculate Area under the curve to display on the plot
auc = metrics.roc_auc_score[y_test,model.predict[x_test]]
# Now, plot the computed values
plt.plot[fpr, tpr, label='%s ROC [area = %0.2f]' % [m['label'], auc]]
# Custom settings for the plot
plt.plot[[0, 1], [0, 1],'r--']
plt.xlim[[0.0, 1.0]]
plt.ylim[[0.0, 1.05]]
plt.xlabel['1-Specificity[False Positive Rate]']
plt.ylabel['Sensitivity[True Positive Rate]']
plt.title['Receiver Operating Characteristic']
plt.legend[loc="lower right"]
plt.show[] # Display
Đã trả lời ngày 13 tháng 9 năm 2018 lúc 21:06Sep 13, 2018 at 21:06
RudrrudrRudr
3874 Huy hiệu bạc20 Huy hiệu Đồng4 silver badges20 bronze badges
1
Một cái gì đó như thế này ...
#ROC Curve
from sklearn.metrics import roc_curve
y_pred_prob1 = classifier1.predict_proba[X_test][:,1]
fpr1 , tpr1, thresholds1 = roc_curve[Y_test, y_pred_prob1]
y_pred_prob2 = classifier2.predict_proba[X_test][:,1]
fpr2 , tpr2, thresholds2 = roc_curve[Y_test, y_pred_prob2]
y_pred_prob3 = classifier3.predict_proba[X_test][:,1]
fpr3 , tpr3, thresholds3 = roc_curve[Y_test, y_pred_prob3]
y_pred_prob4 = classifier4.predict_proba[X_test][:,1]
fpr4 , tpr4, thresholds4 = roc_curve[Y_test, y_pred_prob4]
plt.plot[[0,1],[0,1], 'k--']
plt.plot[fpr1, tpr1, label= "Linear"]
plt.plot[fpr2, tpr2, label= "Poly"]
plt.plot[fpr3, tpr3, label= "RBF"]
plt.plot[fpr4, tpr4, label= "Sigmoid"]
plt.legend[]
plt.xlabel["FPR"]
plt.ylabel["TPR"]
plt.title['Receiver Operating Characteristic']
plt.show[]
Đã trả lời ngày 2 tháng 6 năm 2020 lúc 13:11Jun 2, 2020 at 13:11
Ali Aliali AliAli Ali
Huy hiệu Bạc 911 Huy hiệu Đồng1 silver badge4 bronze badges
from sklearn.metrics import plot_roc_curve
fig = plot_roc_curve[ clf, x_train_bow, y_train]
fig = plot_roc_curve[ clf, x_test_bow, y_test, ax = fig.ax_]
fig.figure_.suptitle["ROC curve comparison"]
plt.show[]
Về cơ bản, chức năng plot_roc_curve
vẽ sơ đồ ROC_CURVE cho trình phân loại. Vì vậy, nếu chúng ta sử dụng plot_roc_curve
hai lần mà không cần tham số ax
chỉ định, nó sẽ vẽ hai biểu đồ. Vì vậy, ở đây chúng tôi lưu trữ Gragh đầu tiên trong biến hình và truy cập trục của nó và cung cấp cho hàm ____77 tiếp theo, để biểu đồ xuất hiện của các trục chỉ của biểu đồ đầu tiên.
Đã trả lời ngày 21 tháng 4 năm 2021 lúc 11:57Apr 21, 2021 at 11:57
2
from sklearn.metrics import plot_roc_curve
classifiers = [log_reg, decision_tree, decision_forest]
ax = plt.gca[]
for i in classifiers:
plot_roc_curve[i, X_test, y_test, ax=ax]
David Buck
3.60033 huy hiệu vàng29 Huy hiệu bạc34 Huy hiệu đồng33 gold badges29 silver badges34 bronze badges
Đã trả lời ngày 22 tháng 5 năm 2020 lúc 10:34May 22, 2020 at 10:34
1