1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| from sklearn.metrics import roc_curve,auc from sklearn.metrics import make_scorer,f1_score scorer = make_scorer(f1_score,pos_label=0) gs = GridSearchCV(estimator=pipe_svc,param_grid=param_grid,scoring=scorer,cv=10) y_pred = gs.fit(X_train,y_train).decision_function(X_test)
fpr,tpr,threshold = roc_curve(y_test, y_pred) roc_auc = auc(fpr,tpr) plt.figure() lw = 2 plt.figure(figsize=(7,5)) plt.plot(fpr, tpr, color='darkorange', lw=lw, label='ROC curve (area = %0.2f)' % roc_auc) plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--') plt.xlim([-0.05, 1.0]) plt.ylim([-0.05, 1.05]) plt.xlabel('False Positive Rate') plt.ylabel('True Positive Rate') plt.title('Receiver operating characteristic ') plt.legend(loc="lower right") plt.show()
|