Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #https://statisticaloddsandends.wordpress.com/2020/06/07/what-is-the-delong-test-for-comparing-aucs/
- #https://alexanderdyakonov.wordpress.com/2017/07/28/auc-roc-%D0%BF%D0%BB%D0%BE%D1%89%D0%B0%D0%B4%D1%8C-%D0%BF%D0%BE%D0%B4-%D0%BA%D1%80%D0%B8%D0%B2%D0%BE%D0%B9-%D0%BE%D1%88%D0%B8%D0%B1%D0%BE%D0%BA/
- #https://www.researchgate.net/figure/Area-under-the-Curve-AUC-and-Accuracy-Ratio-AR-One-year-prior-to-actual-event-
- #https://www.researchgate.net/figure/Area-under-the-Curve-AUC-and-Accuracy-Ratio-AR-One-year-prior-to-actual-event-of_tbl3_309658392
- #https://www.openriskmanual.org/wiki/Accuracy_Ratio
- #https://www.ibm.com/docs/ru/spss-modeler/saas?topic=node-analysis-analysis-tab
- #http://www.machinelearning.ru/wiki/images/1/1c/sem06_metrics.pdf
- #https://cyberleninka.ru/article/n/intervalnye-doveritelnye-otsenki-dlya-pokazateley-kachestva-binarnyh-klassifikatorov-roc-krivyh-auc-dlya-sluchaya-malyh-vyborok/viewer
- #https://pythonru.com/baza-znanij/sklearn-roc-auc
- from sklearn.datasets import make_classification
- from sklearn.linear_model import LogisticRegression
- from sklearn.model_selection import train_test_split
- from sklearn.metrics import roc_curve, auc
- from sklearn.metrics import roc_auc_score
- from matplotlib import pyplot as plt
- # генерируем датасет на 2 класса
- X, y = make_classification(n_samples=1000, n_classes=2, random_state=1)
- # разделяем его на 2 выборки
- trainX, testX, trainy, testy = train_test_split(X, y, test_size=0.5, random_state=2)
- # обучаем модель
- model = LogisticRegression(solver='lbfgs')
- model.fit(trainX, trainy)
- # получаем предказания
- lr_probs = model.predict_proba(testX)
- # сохраняем вероятности только для положительного исхода
- lr_probs = lr_probs[:, 1]
- # рассчитываем ROC AUC
- lr_auc = roc_auc_score(testy, lr_probs)
- print('LogisticRegression: ROC AUC=%.3f' % (lr_auc))
- # рассчитываем roc-кривую
- fpr, tpr, treshold = roc_curve(testy, lr_probs)
- roc_auc = auc(fpr, tpr)
- # строим график
- plt.plot(fpr, tpr, color='darkorange',
- label='ROC кривая (area = %0.2f)' % roc_auc)
- plt.plot([0, 1], [0, 1], color='navy', linestyle='--')
- plt.xlim([0.0, 1.0])
- plt.ylim([0.0, 1.05])
- plt.xlabel('False Positive Rate')
- plt.ylabel('True Positive Rate')
- plt.title('Пример ROC-кривой')
- plt.legend(loc="lower right")
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement