Created
June 27, 2022 09:23
-
-
Save oguzhari/6818afa803ae9648f125aec211689fe2 to your computer and use it in GitHub Desktop.
ROC-AUC Curve'u
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Daha önce hazırlamış olduğumuz ROC-AUC oranlarını bir de ROC-AUC grafiği olarak gösteriyoruz. | |
| plt=reload(plt) | |
| plt.style.use('seaborn') | |
| #dtc rfc gradient xgb clf lr <-- algoritmalarının isimleri | |
| pred_prob_dtc = dtc.predict_proba(X_test) | |
| pred_prob_rfc = rfc.predict_proba(X_test) | |
| pred_prob_gradient = gradient.predict_proba(X_test) | |
| pred_prob_xgb = xgb.predict_proba(X_test) | |
| pred_prob_clf = clf.predict_proba(X_test) | |
| pred_prob_lr = lr.predict_proba(X_test) | |
| #fpr, tpr <-- false-positive-rate true-positive-rate | |
| fpr_dtc, tpr_dtc, thresh_dtc = roc_curve(y_test, pred_prob_dtc[:,1], pos_label=1) | |
| fpr_rfc, tpr_rfc, thresh_rfc = roc_curve(y_test, pred_prob_rfc[:,1], pos_label=1) | |
| fpr_gradient, tpr_gradient, thresh_gradient = roc_curve(y_test, pred_prob_gradient[:,1], pos_label=1) | |
| fpr_xgb, tpr_xgb, thresh_xgb = roc_curve(y_test, pred_prob_xgb[:,1], pos_label=1) | |
| fpr_clf, tpr_clf, thresh_clf = roc_curve(y_test, pred_prob_clf[:,1], pos_label=1) | |
| fpr_lr, tpr_lr, thresh_lr = roc_curve(y_test, pred_prob_lr[:,1], pos_label=1) | |
| #random probs <-- rastgele ihtimaller. Bu ihtimallerin ROC-AUC oranlarının ortalamasını bulmak için kullanılır. | |
| #Figürdeki 45 Derecelik açıyla olan yatay çizgi, bu oranı gösterir. | |
| random_probs = [0 for i in range(len(y_test))] | |
| p_fpr, p_tpr, _ = roc_curve(y_test, random_probs, pos_label=1) | |
| #plot roc curves <-- Değerleri ROC-AUC grafiğine ekler. | |
| plt.plot(fpr_dtc, tpr_dtc, linestyle='--',color='green', label='Karar Ağacı') | |
| plt.plot(fpr_rfc, tpr_rfc, linestyle='--',color='red', label='Rassal Orman') | |
| plt.plot(fpr_gradient, tpr_gradient, linestyle='--',color='purple', label='Gradyan Arttırma') | |
| plt.plot(fpr_xgb, tpr_xgb, linestyle='--',color='brown', label='XGBoost') | |
| plt.plot(fpr_clf, tpr_clf, linestyle='--',color='blue', label='Naive Bayes') | |
| plt.plot(fpr_lr, tpr_lr, linestyle='--',color='orange', label='Logistic Regression') | |
| plt.plot(p_fpr, p_tpr, linestyle='--', color='black') | |
| plt.title('ROC Eğrisi') | |
| # x label | |
| plt.xlabel('Sahte Pozitif Oranı') | |
| # y label | |
| plt.ylabel('Gerçek Pozitif Oranı') | |
| plt.legend(loc='best') | |
| plt.savefig('fig/ROC',dpi=600) | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment