Python Calculates AUC metrics

Source: Internet
Author: User

1. Installing Scikit-learn

1.1scikit-learn Dependency

    • Python (>= 2.6 or >= 3.3),
    • NumPy (>= 1.6.1),
    • SciPy (>= 0.9).

View each of the three dependent versions above,

Python-v Result: Python 2.7.3
Python-c ' Import scipy; Print scipy.version.version ' scipy version results: 0.9.0
Python-c "Import numpy; Print numpy.version.version "NumPy Result: 1.10.2
1.2 Scikit-learn Installation
If you have installed NumPy, scipy, and Python and all meet the required conditions in 1.1, you can run sudo pip install directly -U scikit-Learn perform the installation.

2. Calculate the AUC indicator

1 Import NumPy as NP 2  from Import Roc_auc_score 3 y_true = Np.array ([0, 0, 1, 1])4 y_scores = Np.array ([0.1, 0.4, 0.35, 0.8])5< /c11> Roc_auc_score (y_true, Y_scores)

Output: 0.75

3. Calculate the ROC curve

1 ImportNumPy as NP2  fromSklearnImportMetrics3y = Np.array ([1, 1, 2, 2]) #实际值4scores = Np.array ([0.1, 0.4, 0.35, 0.8]) #预测值5FPR, TPR, thresholds = Metrics.roc_curve (y, scores, pos_label=2) #pos_label = 2, which indicates that the actual value of 2 is a positive sample6 PrintFPR7 PrintTPR8 PrintThresholds

Output:
Array ([0., 0.5, 0.5, 1.])
Array ([0.5, 0.5, 1., 1.])
Array ([0.8, 0.4, 0.35, 0.1])

Python Calculates AUC metrics

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.