Advertisement
Danila_lipatov

AUC_test

Apr 29th, 2023
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.42 KB | None | 0 0
  1. #https://statisticaloddsandends.wordpress.com/2020/06/07/what-is-the-delong-test-for-comparing-aucs/
  2. #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/
  3. #https://www.researchgate.net/figure/Area-under-the-Curve-AUC-and-Accuracy-Ratio-AR-One-year-prior-to-actual-event-
  4. #https://www.researchgate.net/figure/Area-under-the-Curve-AUC-and-Accuracy-Ratio-AR-One-year-prior-to-actual-event-of_tbl3_309658392
  5. #https://www.openriskmanual.org/wiki/Accuracy_Ratio
  6. #https://www.ibm.com/docs/ru/spss-modeler/saas?topic=node-analysis-analysis-tab
  7. #http://www.machinelearning.ru/wiki/images/1/1c/sem06_metrics.pdf
  8. #https://cyberleninka.ru/article/n/intervalnye-doveritelnye-otsenki-dlya-pokazateley-kachestva-binarnyh-klassifikatorov-roc-krivyh-auc-dlya-sluchaya-malyh-vyborok/viewer
  9. #https://pythonru.com/baza-znanij/sklearn-roc-auc
  10.  
  11.  
  12. from sklearn.datasets import make_classification
  13. from sklearn.linear_model import LogisticRegression
  14. from sklearn.model_selection import train_test_split
  15. from sklearn.metrics import roc_curve, auc
  16. from sklearn.metrics import roc_auc_score
  17. from matplotlib import pyplot as plt
  18. # генерируем датасет на 2 класса
  19. X, y = make_classification(n_samples=1000, n_classes=2, random_state=1)
  20. # разделяем его на 2 выборки
  21. trainX, testX, trainy, testy = train_test_split(X, y, test_size=0.5, random_state=2)
  22. # обучаем модель
  23. model = LogisticRegression(solver='lbfgs')
  24. model.fit(trainX, trainy)
  25. # получаем предказания
  26. lr_probs = model.predict_proba(testX)
  27. # сохраняем вероятности только для положительного исхода
  28. lr_probs = lr_probs[:, 1]
  29. # рассчитываем ROC AUC
  30. lr_auc = roc_auc_score(testy, lr_probs)
  31. print('LogisticRegression: ROC AUC=%.3f' % (lr_auc))
  32. # рассчитываем roc-кривую
  33. fpr, tpr, treshold = roc_curve(testy, lr_probs)
  34. roc_auc = auc(fpr, tpr)
  35. # строим график
  36. plt.plot(fpr, tpr, color='darkorange',
  37.          label='ROC кривая (area = %0.2f)' % roc_auc)
  38. plt.plot([0, 1], [0, 1], color='navy', linestyle='--')
  39. plt.xlim([0.0, 1.0])
  40. plt.ylim([0.0, 1.05])
  41. plt.xlabel('False Positive Rate')
  42. plt.ylabel('True Positive Rate')
  43. plt.title('Пример ROC-кривой')
  44. plt.legend(loc="lower right")
  45. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement