1. Install scikit-learn
1.1 Scikit-learn depends on
python -c 'import scipy; print scipy.version.version' scipy version result: 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 requirements If the conditions required in 1.1 are met, you can directly run sudo
pip install -U scikit-learn Perform the installation.
2. Calculate auc indicator
sklearn.metrics y_true = np.array([0, 0, 1, 1 y_scores = np.array([0.1, 0.4, 0.35, 0.8 roc_auc_score(y_true, y_scores) 输出:0.75
<br>
3. Calculate roc curve
sklearn y = np.array([1, 1, 2, 2 scores = np.array([0.1, 0.4, 0.35, 0.8 fpr, tpr, thresholds = metrics.roc_curve(y, scores, pos_label=2 thresholds 输出: array([ 0. , 0.5, 0.5, 1. ]) array([ 0.5, 0.5, 1. , 1. ]) array([ 0.8 , 0.4 , 0.35, 0.1 ])
The above is the detailed content of How does python calculate the auc indicator?. For more information, please follow other related articles on the PHP Chinese website!