scikit-viz aims to provide a collection of templates to make producing plots to evaluate models built using scikit-learn much simpler.
$ pip install scikit-viz
-
plot_roc(y, y_pred, spacing=0.2, indifference=None)
- y actual value (1 or 0)
- y_pred probability of 1
- spacing governs the spacing between threshold labels
- indifference is a dictionary defined as follows:
Provide this dictionary describing the economic utility and frequency of false positives and false negatives, and it will produce an indifference curve on the plot which provides a threshold above which the classifier is economically useful. For more information on this extremely interesting concept, see this blog post (http://blog.mldb.ai/blog/posts/2016/01/ml-meets-economics/)
{ 'rate_positive': 0.95, # rate of 1 case 'rate_negative': 0.05, # rate of 0 case 'tp_util': 20, # utility of true positives 'tn_util': -50, # utility of true negatives 'fp_util': -300, # utility of false positives 'fn_util': -50 # utility of false negatives }
-
plot_precision_recall(y, y_pred, spacing=0.2)
- y actual value (1 or 0)
- y_pred probability of 1
- spacing governs the spacing between threshold labels
from sklearnviz import plot_roc
from sklearn import datasets
iris = datasets.load_iris()
X = iris.data
y = iris.target
y[y==2] = 0
from sklearn.linear_model import LogisticRegression
clf = LogisticRegression().fit(X,y)
y_pred = clf.predict_proba(X)[:,1]
# this is where the magic happens
plot_roc(y, y_pred, spacing=0.1)
plot_precision_recall(y, y_pred, spacing=0.15)