In [1]:
from sklearn import datasets
import pandas as pd

In [2]:
# build a model

ds = datasets.load_breast_cancer();
from sklearn.ensemble import RandomForestClassifier
clf = RandomForestClassifier(n_estimators=12, random_state = 1960)

X = ds.data
clf.fit(X , ds.target)


Out[2]:
RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
            max_depth=None, max_features='auto', max_leaf_nodes=None,
            min_impurity_decrease=0.0, min_impurity_split=None,
            min_samples_leaf=1, min_samples_split=2,
            min_weight_fraction_leaf=0.0, n_estimators=12, n_jobs=1,
            oob_score=False, random_state=1960, verbose=0,
            warm_start=False)

In [3]:
# Explain the score


import sklearn_explain.explainer as expl
lExplainer = expl.cModelScoreExplainer(clf)
lExplainer.mFeatureNames = ds.feature_names
lExplainer.fit(X)
df_rc = lExplainer.explain(X)

df_rc.sample(12, random_state = 1960)


USING_PROBABILITY_AS_SCORE
USING_PROBABILITY_AS_SCORE
Out[3]:
mean radius mean texture mean perimeter mean area mean smoothness mean compactness mean concavity mean concave points mean symmetry mean fractal dimension ... reason_ep1 detailed_reason_1 reason_ep2 detailed_reason_2 reason_ep3 detailed_reason_3 reason_ep4 detailed_reason_4 reason_ep5 detailed_reason_5
50 11.76 21.60 74.72 427.9 0.08637 0.04966 0.01657 0.01115 0.1495 0.05888 ... mean fractal dimension_concavity error [(0.04996 < 'mean fractal dimension' <= 0.0568... mean symmetry_symmetry error [(0.106 < 'mean symmetry' <= 0.15876), (0.0078... mean texture_smoothness error [(9.71 < 'mean texture' <= 15.656), (0.001713 ... perimeter error_area error [(0.757 < 'perimeter error' <= 1.5166), (6.802... mean texture_perimeter error [(9.71 < 'mean texture' <= 15.656), (0.757 < '...
457 13.21 25.25 84.10 537.9 0.08791 0.05205 0.02772 0.02068 0.1619 0.05584 ... compactness error_worst symmetry [(0.002252 < 'compactness error' <= 0.0118), (... mean texture_worst smoothness [(9.71 < 'mean texture' <= 15.656), (0.07117 <... mean fractal dimension_worst texture [(0.04996 < 'mean fractal dimension' <= 0.0568... mean texture_smoothness error [(9.71 < 'mean texture' <= 15.656), (0.001713 ... worst texture_worst perimeter [(12.02 < 'worst texture' <= 20.176), (50.41 <...
259 15.53 33.56 103.70 744.9 0.10630 0.16390 0.17510 0.08399 0.2091 0.06650 ... mean compactness_radius error [(0.01938 < 'mean compactness' <= 0.059638), (... concavity error_symmetry error [(0.0 < 'concavity error' <= 0.013212), (0.007... perimeter error_area error [(0.757 < 'perimeter error' <= 1.5166), (6.802... mean area_perimeter error [(143.5 < 'mean area' <= 396.56), (0.757 < 'pe... mean area_radius error [(143.5 < 'mean area' <= 396.56), (0.1115 < 'r...
85 18.46 18.52 121.10 1075.0 0.09874 0.10530 0.13350 0.08795 0.2132 0.06022 ... mean compactness_worst concavity [(0.01938 < 'mean compactness' <= 0.059638), (... symmetry error_worst compactness [(0.007882 < 'symmetry error' <= 0.01454), (0.... mean texture_worst smoothness [(9.71 < 'mean texture' <= 15.656), (0.07117 <... mean compactness_symmetry error [(0.01938 < 'mean compactness' <= 0.059638), (... mean texture_smoothness error [(9.71 < 'mean texture' <= 15.656), (0.001713 ...
348 11.47 16.03 73.02 402.7 0.09076 0.05886 0.02587 0.02322 0.1634 0.06372 ... mean concavity_texture error [(0.0 < 'mean concavity' <= 0.02493), (0.3602 ... mean concavity_worst texture [(0.0 < 'mean concavity' <= 0.02493), (12.02 <... texture error_worst concavity [(0.3602 < 'texture error' <= 0.7806), (0.0 < ... mean smoothness_worst smoothness [(0.05263 < 'mean smoothness' <= 0.084206), (0... worst texture_worst symmetry [(12.02 < 'worst texture' <= 20.176), (0.1565 ...
462 14.40 26.99 92.25 646.1 0.06995 0.05223 0.03476 0.01737 0.1707 0.05433 ... mean compactness_worst area [(0.01938 < 'mean compactness' <= 0.059638), (... concavity error_worst area [(0.0 < 'concavity error' <= 0.013212), (185.2... mean perimeter_worst area [(43.79 < 'mean perimeter' <= 73.292), (185.2 ... mean texture_worst perimeter [(9.71 < 'mean texture' <= 15.656), (50.41 < '... worst texture_worst perimeter [(12.02 < 'worst texture' <= 20.176), (50.41 <...
451 19.59 25.00 127.70 1191.0 0.10320 0.09871 0.16550 0.09063 0.1663 0.05391 ... fractal dimension error_worst concave points [(0.0008948 < 'fractal dimension error' <= 0.0... symmetry error_worst compactness [(0.007882 < 'symmetry error' <= 0.01454), (0.... perimeter error_worst compactness [(0.757 < 'perimeter error' <= 1.5166), (0.027... worst concave points_worst symmetry [(0.0 < 'worst concave points' <= 0.058086), (... worst compactness_worst concave points [(0.02729 < 'worst compactness' <= 0.12566), (...
293 11.85 17.46 75.54 432.7 0.08372 0.05642 0.02688 0.02280 0.1875 0.05715 ... mean area_mean smoothness [(143.5 < 'mean area' <= 396.56), (0.05263 < '... mean fractal dimension_worst texture [(0.04996 < 'mean fractal dimension' <= 0.0568... mean smoothness_symmetry error [(0.05263 < 'mean smoothness' <= 0.084206), (0... smoothness error_worst fractal dimension [(0.001713 < 'smoothness error' <= 0.004871), ... texture error_concave points error [(0.3602 < 'texture error' <= 0.7806), (0.0 < ...
218 19.80 21.56 129.70 1230.0 0.09383 0.13060 0.12720 0.08691 0.2094 0.05581 ... area error_concavity error [(6.802 < 'area error' <= 16.64), (0.0 < 'conc... mean fractal dimension_worst compactness [(0.04996 < 'mean fractal dimension' <= 0.0568... mean texture_mean compactness [(9.71 < 'mean texture' <= 15.656), (0.01938 <... mean texture_fractal dimension error [(9.71 < 'mean texture' <= 15.656), (0.0008948... mean fractal dimension_fractal dimension error [(0.04996 < 'mean fractal dimension' <= 0.0568...
219 19.53 32.47 128.00 1223.0 0.08420 0.11300 0.11450 0.06637 0.1428 0.05313 ... mean symmetry_texture error [(0.106 < 'mean symmetry' <= 0.15876), (0.3602... mean fractal dimension_worst compactness [(0.04996 < 'mean fractal dimension' <= 0.0568... concave points error_worst smoothness [(0.0 < 'concave points error' <= 0.0068934), ... mean concavity_concave points error [(0.0 < 'mean concavity' <= 0.02493), (0.0 < '... mean fractal dimension_fractal dimension error [(0.04996 < 'mean fractal dimension' <= 0.0568...
133 15.71 13.93 102.00 761.7 0.09462 0.09462 0.07135 0.05933 0.1816 0.05723 ... mean radius_worst fractal dimension [(6.981 < 'mean radius' <= 11.366), (0.05504 <... mean perimeter_mean smoothness [(43.79 < 'mean perimeter' <= 73.292), (0.0526... mean perimeter_worst symmetry [(43.79 < 'mean perimeter' <= 73.292), (0.1565... mean radius_smoothness error [(6.981 < 'mean radius' <= 11.366), (0.001713 ... mean compactness_worst area [(0.01938 < 'mean compactness' <= 0.059638), (...
192 9.72 18.22 60.73 288.1 0.06950 0.02344 0.00000 0.00000 0.1653 0.06447 ... smoothness error_worst concavity [(0.001713 < 'smoothness error' <= 0.004871), ... smoothness error_worst compactness [(0.001713 < 'smoothness error' <= 0.004871), ... mean fractal dimension_concavity error [(0.04996 < 'mean fractal dimension' <= 0.0568... mean symmetry_symmetry error [(0.106 < 'mean symmetry' <= 0.15876), (0.0078... compactness error_worst symmetry [(0.002252 < 'compactness error' <= 0.0118), (...

12 rows × 1382 columns


In [ ]: