Skip to content

digideskio/sklearn-evaluation

 
 

Repository files navigation

#sklearn-evaluation

Build Status

Utilities for evaluating scikit-learn models.

#Install

pip install sklearn-evaluation

#Usage

The package is divided in modules that have specific functionality.

##Plots module

Generate evaluation plots with a single function call.

from sklearn_evaluation import plots

#code for data loading and model training

plots.confusion_matrix(y_true, y_pred, target_names=target_names)

confusion matrix

There's also an object-oriented interface:

from sklearn_evaluation.model_results import ClassificationModelResults

#code for data loading and model training

tm = ClassificationModelResults(classifier, y_test, y_pred, y_score,
    feature_list, target_names)

#this will produce the sample plot as the first example
tm.plots.confusion_matrix()

See this Jupyter notebook for examples using the funcional interface and this notebook for the object-oriented interface.

##Tables module

Generate good looking tables from your model results.

from sklearn_evaluation import tables

#code for data loading and training

tables.feature_importances(model, feature_list)
+-----------+--------------+-----------+
| name      |   importance |       std |
+===========+==============+===========+
| Feature 0 |    0.250398  | 0.0530907 |
+-----------+--------------+-----------+
| Feature 1 |    0.232397  | 0.0523836 |
+-----------+--------------+-----------+
| Feature 2 |    0.148898  | 0.0331814 |
+-----------+--------------+-----------+
| Feature 3 |    0.0553634 | 0.0128296 |
+-----------+--------------+-----------+
| Feature 8 |    0.05401   | 0.0122248 |
+-----------+--------------+-----------+
| Feature 5 |    0.053878  | 0.01289   |
+-----------+--------------+-----------+
| Feature 6 |    0.0525828 | 0.0130225 |
+-----------+--------------+-----------+
| Feature 9 |    0.0510197 | 0.0129436 |
+-----------+--------------+-----------+
| Feature 7 |    0.0509633 | 0.0117197 |
+-----------+--------------+-----------+
| Feature 4 |    0.0504887 | 0.012844  |
+-----------+--------------+-----------+

Also, running this in Jupyter will generate a pandas-like output. See notebook

##Report generation module

Generate HTML reports.

from sklearn_evaluation.model_results import ClassificationModelResults
from sklearn_evaluation.report import ReportGenerator

#code for data loading and model training

#Created a ClassificationModelResults that packs everything about your model
tm = ClassificationModelResults(classifier, y_test, y_pred, y_score,
    feature_list, target_names, model_name='sample_model_report')

#Instantiate a ReportGenerator which takes a ClassificationModelResults
#instance and generates HTML reports
report_gen = ReportGenerator(savepath='~/models')
#Save HTML file
report_gen(tm)

The code above will generate a report like this one.

Reports are self-contained, all images are included in the html file using base64.

About

Toolkit for scikit-learn model evaluation: plots, tables and reports

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HTML 82.6%
  • Python 15.5%
  • CSS 1.9%