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