Python Calculates AUC metrics

Source: Internet
Author: User

This article and everyone to share is mainly Python to calculate the AUC index related content, together to see it, hope to learn python to help you.

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 directly

Pip Install-u Scikit-learn

Perform the installation.

2. Calculate the AUC indicator

1 Import numpy as NP

2 from Sklearn.metrics 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 Roc_auc_score (Y_true, Y_scores)

Output: 0.75

3. Calculate the ROC curve

1 Import numpy as NP

2 from Sklearn Import metrics

3 y = np. Array ([1, 1, 2, 2]) #实际值

4 scores = NP. Array ([0.1, 0.4, 0.35, 0.8]) #预测值

5 FPR, TPR, thresholds = Metrics.roc_curve (y, scores, pos_label=2) #pos_label = 2, representing the actual value of 2 as a positive sample

6 Print FPR

7 Print TPR

8 Print thresholds

Output:

Array ([0., 0.5, 0.5, 1.])

Array ([0.5, 0.5, 1., 1.])

Array ([0.8, 0.4, 0.35, 0.1])

Source: Blog Park

Python Calculates AUC metrics

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.