3

I followed a tutorial for displaying the roc curves and the corresponding auc; I never used the ggplot library, thus I cannot understand where is my error. Here the code below:

    from sklearn import metrics
    import pandas as pd
    from ggplot import *

    preds = clf.predict_proba(Xtest)[:,1]
    fpr, tpr, _ = metrics.roc_curve(ytest, preds)

    df = pd.DataFrame(dict(fpr=fpr, tpr=tpr))
    ggplot(df, aes(x='fpr', y='tpr')) + geom_line() + geom_abline(linetype='dashed')

This is the error:

   slope needed for <ggplot.geoms.geom_abline.geom_abline object at 0x7fae7e7f8d90>

how could I fix this?

ElenaPhys
  • 443
  • 2
  • 5
  • 16
  • Do you really need to use the ggplot library? See http://scikit-learn.org/stable/auto_examples/model_selection/plot_roc_crossval.html or http://scikit-learn.org/stable/auto_examples/model_selection/plot_roc.html for matplotlib examples – dukebody Jul 17 '16 at 11:05

3 Answers3

0
ggplot(df, aes(x='fpr', y='tpr',ymin=0, ymax='tpr'))+ \
geom_area(alpha=0.2)+\
geom_line(x,y,aes(y='tpr'))+\
ggtitle("ROC Curve w/ AUC=%s" % str(auc))
import matplotlib.pyplot as plt
plt.plot(x,y,'--',color='grey')
0
ggplot(df, aes(x='fpr', y='tpr'))+\
geom_line()+\
geom_abline(linetype='dashed',slope=1,intercept=0)

the error said you must add the args slope=? and intercept=?.after that it works

0

This is the simplest way to plot an ROC curve, given a set of ground truth labels and predicted probabilities. Best part is, it plots the ROC curve for ALL classes, so you get multiple neat-looking curves as well. Modifying your code...

import scikitplot.plotters as skplt
import matplotlib.pyplot as plt

preds = clf.predict_proba(Xtest)
skplt.plot_roc_curve(ytest, preds)
plt.show()

Literally all you need is the predicted probabilities and true labels.

Here's a sample curve generated by plot_roc_curve. I used the sample digits dataset from scikit-learn so there are 10 classes. Notice that one ROC curve is plotted for each class.

ROC Curves

Disclaimer: Note that this uses the scikit-plot library, which I built.

Reii Nakano
  • 1,318
  • 1
  • 9
  • 9