GBMs

At this time we do not provide functionality specific to gradient boosted machines, but we want to support scikit-learn-like interfaces in popular libraries, including catboost, lightgbm, and xgboost.

# LightGBM and XGBoost are not Model Inspector requirements. CatBoost is
# because it requires a small shim.
! pip install lightgbm xgboost
import numpy as np
import sklearn.datasets
import sklearn.metrics
from catboost import CatBoostClassifier, CatBoostRegressor
from lightgbm import LGBMClassifier, LGBMRegressor
from xgboost import XGBClassifier, XGBRegressor

from model_inspector import get_inspector

CatBoost

CatBoostRegressor

X, y = sklearn.datasets.load_diabetes(return_X_y=True, as_frame=True)
inspector = get_inspector(CatBoostRegressor(n_estimators=5).fit(X, y), X, y)
Learning rate set to 0.5
0:  learn: 63.4011144   total: 896us    remaining: 3.59ms
1:  learn: 56.1323417   total: 1.42ms   remaining: 2.14ms
2:  learn: 52.9311271   total: 1.88ms   remaining: 1.25ms
3:  learn: 50.5129302   total: 2.39ms   remaining: 596us
4:  learn: 49.1286322   total: 2.77ms   remaining: 0us
inspector.methods
['permutation_importance',
 'plot_feature_clusters',
 'plot_partial_dependence',
 'plot_permutation_importance',
 'plot_pred_vs_act',
 'plot_residuals',
 'show_correlation']
inspector.permutation_importance()
s5     0.253769
bmi    0.250723
bp     0.130111
sex    0.059715
s3     0.051180
s2     0.038155
s1     0.020064
s4     0.018919
s6     0.015744
age    0.015219
dtype: float64
ax = inspector.plot_feature_clusters()

axes = inspector.plot_partial_dependence(features=["bmi"])

ax = inspector.plot_pred_vs_act()

ax = inspector.plot_residuals()

inspector.show_correlation()
  age sex bmi bp s1 s2 s3 s4 s5 s6 target
age 1.00 0.17 0.19 0.34 0.26 0.22 -0.08 0.20 0.27 0.30 0.19
sex 0.17 1.00 0.09 0.24 0.04 0.14 -0.38 0.33 0.15 0.21 0.04
bmi 0.19 0.09 1.00 0.40 0.25 0.26 -0.37 0.41 0.45 0.39 0.59
bp 0.34 0.24 0.40 1.00 0.24 0.19 -0.18 0.26 0.39 0.39 0.44
s1 0.26 0.04 0.25 0.24 1.00 0.90 0.05 0.54 0.52 0.33 0.21
s2 0.22 0.14 0.26 0.19 0.90 1.00 -0.20 0.66 0.32 0.29 0.17
s3 -0.08 -0.38 -0.37 -0.18 0.05 -0.20 1.00 -0.74 -0.40 -0.27 -0.39
s4 0.20 0.33 0.41 0.26 0.54 0.66 -0.74 1.00 0.62 0.42 0.43
s5 0.27 0.15 0.45 0.39 0.52 0.32 -0.40 0.62 1.00 0.46 0.57
s6 0.30 0.21 0.39 0.39 0.33 0.29 -0.27 0.42 0.46 1.00 0.38
target 0.19 0.04 0.59 0.44 0.21 0.17 -0.39 0.43 0.57 0.38 1.00

CatBoostClassifier

X, y = sklearn.datasets.load_breast_cancer(return_X_y=True, as_frame=True)
inspector = get_inspector(CatBoostClassifier(n_estimators=5).fit(X, y), X, y)
Learning rate set to 0.5
0:  learn: 0.2068913    total: 2.79ms   remaining: 11.2ms
1:  learn: 0.1073211    total: 4.88ms   remaining: 7.32ms
2:  learn: 0.0762370    total: 6.91ms   remaining: 4.61ms
3:  learn: 0.0572005    total: 8.96ms   remaining: 2.24ms
4:  learn: 0.0464524    total: 15.5ms   remaining: 0us
inspector.methods
['calculate_metrics_by_thresh',
 'confusion_matrix',
 'permutation_importance',
 'plot_feature_clusters',
 'plot_partial_dependence',
 'plot_permutation_importance',
 'show_correlation']
ax = inspector.calculate_metrics_by_thresh(
    sklearn.metrics.accuracy_score, np.linspace(0, 1, 11)
).plot(x="thresh")
100%|██████████| 11/11 [00:00<00:00, 2964.93it/s]

inspector.confusion_matrix()
  Predicted 0 Predicted 1 Totals
Actual 0 208 4 212
Actual 1 0 357 357
Totals 208 361 569
inspector.permutation_importance()
worst area                 0.069947
mean texture               0.024605
worst smoothness           0.016872
worst concavity            0.014411
worst concave points       0.009490
mean radius                0.008436
mean smoothness            0.004921
mean area                  0.003866
mean concavity             0.003515
perimeter error            0.003163
mean concave points        0.003163
area error                 0.002812
compactness error          0.002812
worst fractal dimension    0.002109
worst perimeter            0.002109
worst texture              0.001757
mean perimeter             0.001054
worst compactness          0.000351
concavity error            0.000000
concave points error       0.000000
symmetry error             0.000000
fractal dimension error    0.000000
worst radius               0.000000
smoothness error           0.000000
radius error               0.000000
mean fractal dimension     0.000000
mean symmetry              0.000000
mean compactness           0.000000
worst symmetry             0.000000
texture error              0.000000
dtype: float64
ax = inspector.plot_feature_clusters()

axes = inspector.plot_partial_dependence(features=["worst texture"])

ax = inspector.plot_permutation_importance()

inspector.show_correlation()
  mean radius mean texture mean perimeter mean area mean smoothness mean compactness mean concavity mean concave points mean symmetry mean fractal dimension radius error texture error perimeter error area error smoothness error compactness error concavity error concave points error symmetry error fractal dimension error worst radius worst texture worst perimeter worst area worst smoothness worst compactness worst concavity worst concave points worst symmetry worst fractal dimension target
mean radius 1.00 0.32 1.00 0.99 0.17 0.51 0.68 0.82 0.15 -0.31 0.68 -0.10 0.67 0.74 -0.22 0.21 0.19 0.38 -0.10 -0.04 0.97 0.30 0.97 0.94 0.12 0.41 0.53 0.74 0.16 0.01 -0.73
mean texture 0.32 1.00 0.33 0.32 -0.02 0.24 0.30 0.29 0.07 -0.08 0.28 0.39 0.28 0.26 0.01 0.19 0.14 0.16 0.01 0.05 0.35 0.91 0.36 0.34 0.08 0.28 0.30 0.30 0.11 0.12 -0.42
mean perimeter 1.00 0.33 1.00 0.99 0.21 0.56 0.72 0.85 0.18 -0.26 0.69 -0.09 0.69 0.74 -0.20 0.25 0.23 0.41 -0.08 -0.01 0.97 0.30 0.97 0.94 0.15 0.46 0.56 0.77 0.19 0.05 -0.74
mean area 0.99 0.32 0.99 1.00 0.18 0.50 0.69 0.82 0.15 -0.28 0.73 -0.07 0.73 0.80 -0.17 0.21 0.21 0.37 -0.07 -0.02 0.96 0.29 0.96 0.96 0.12 0.39 0.51 0.72 0.14 0.00 -0.71
mean smoothness 0.17 -0.02 0.21 0.18 1.00 0.66 0.52 0.55 0.56 0.58 0.30 0.07 0.30 0.25 0.33 0.32 0.25 0.38 0.20 0.28 0.21 0.04 0.24 0.21 0.81 0.47 0.43 0.50 0.39 0.50 -0.36
mean compactness 0.51 0.24 0.56 0.50 0.66 1.00 0.88 0.83 0.60 0.57 0.50 0.05 0.55 0.46 0.14 0.74 0.57 0.64 0.23 0.51 0.54 0.25 0.59 0.51 0.57 0.87 0.82 0.82 0.51 0.69 -0.60
mean concavity 0.68 0.30 0.72 0.69 0.52 0.88 1.00 0.92 0.50 0.34 0.63 0.08 0.66 0.62 0.10 0.67 0.69 0.68 0.18 0.45 0.69 0.30 0.73 0.68 0.45 0.75 0.88 0.86 0.41 0.51 -0.70
mean concave points 0.82 0.29 0.85 0.82 0.55 0.83 0.92 1.00 0.46 0.17 0.70 0.02 0.71 0.69 0.03 0.49 0.44 0.62 0.10 0.26 0.83 0.29 0.86 0.81 0.45 0.67 0.75 0.91 0.38 0.37 -0.78
mean symmetry 0.15 0.07 0.18 0.15 0.56 0.60 0.50 0.46 1.00 0.48 0.30 0.13 0.31 0.22 0.19 0.42 0.34 0.39 0.45 0.33 0.19 0.09 0.22 0.18 0.43 0.47 0.43 0.43 0.70 0.44 -0.33
mean fractal dimension -0.31 -0.08 -0.26 -0.28 0.58 0.57 0.34 0.17 0.48 1.00 0.00 0.16 0.04 -0.09 0.40 0.56 0.45 0.34 0.35 0.69 -0.25 -0.05 -0.21 -0.23 0.50 0.46 0.35 0.18 0.33 0.77 0.01
radius error 0.68 0.28 0.69 0.73 0.30 0.50 0.63 0.70 0.30 0.00 1.00 0.21 0.97 0.95 0.16 0.36 0.33 0.51 0.24 0.23 0.72 0.19 0.72 0.75 0.14 0.29 0.38 0.53 0.09 0.05 -0.57
texture error -0.10 0.39 -0.09 -0.07 0.07 0.05 0.08 0.02 0.13 0.16 0.21 1.00 0.22 0.11 0.40 0.23 0.19 0.23 0.41 0.28 -0.11 0.41 -0.10 -0.08 -0.07 -0.09 -0.07 -0.12 -0.13 -0.05 0.01
perimeter error 0.67 0.28 0.69 0.73 0.30 0.55 0.66 0.71 0.31 0.04 0.97 0.22 1.00 0.94 0.15 0.42 0.36 0.56 0.27 0.24 0.70 0.20 0.72 0.73 0.13 0.34 0.42 0.55 0.11 0.09 -0.56
area error 0.74 0.26 0.74 0.80 0.25 0.46 0.62 0.69 0.22 -0.09 0.95 0.11 0.94 1.00 0.08 0.28 0.27 0.42 0.13 0.13 0.76 0.20 0.76 0.81 0.13 0.28 0.39 0.54 0.07 0.02 -0.55
smoothness error -0.22 0.01 -0.20 -0.17 0.33 0.14 0.10 0.03 0.19 0.40 0.16 0.40 0.15 0.08 1.00 0.34 0.27 0.33 0.41 0.43 -0.23 -0.07 -0.22 -0.18 0.31 -0.06 -0.06 -0.10 -0.11 0.10 0.07
compactness error 0.21 0.19 0.25 0.21 0.32 0.74 0.67 0.49 0.42 0.56 0.36 0.23 0.42 0.28 0.34 1.00 0.80 0.74 0.39 0.80 0.20 0.14 0.26 0.20 0.23 0.68 0.64 0.48 0.28 0.59 -0.29
concavity error 0.19 0.14 0.23 0.21 0.25 0.57 0.69 0.44 0.34 0.45 0.33 0.19 0.36 0.27 0.27 0.80 1.00 0.77 0.31 0.73 0.19 0.10 0.23 0.19 0.17 0.48 0.66 0.44 0.20 0.44 -0.25
concave points error 0.38 0.16 0.41 0.37 0.38 0.64 0.68 0.62 0.39 0.34 0.51 0.23 0.56 0.42 0.33 0.74 0.77 1.00 0.31 0.61 0.36 0.09 0.39 0.34 0.22 0.45 0.55 0.60 0.14 0.31 -0.41
symmetry error -0.10 0.01 -0.08 -0.07 0.20 0.23 0.18 0.10 0.45 0.35 0.24 0.41 0.27 0.13 0.41 0.39 0.31 0.31 1.00 0.37 -0.13 -0.08 -0.10 -0.11 -0.01 0.06 0.04 -0.03 0.39 0.08 0.01
fractal dimension error -0.04 0.05 -0.01 -0.02 0.28 0.51 0.45 0.26 0.33 0.69 0.23 0.28 0.24 0.13 0.43 0.80 0.73 0.61 0.37 1.00 -0.04 -0.00 -0.00 -0.02 0.17 0.39 0.38 0.22 0.11 0.59 -0.08
worst radius 0.97 0.35 0.97 0.96 0.21 0.54 0.69 0.83 0.19 -0.25 0.72 -0.11 0.70 0.76 -0.23 0.20 0.19 0.36 -0.13 -0.04 1.00 0.36 0.99 0.98 0.22 0.48 0.57 0.79 0.24 0.09 -0.78
worst texture 0.30 0.91 0.30 0.29 0.04 0.25 0.30 0.29 0.09 -0.05 0.19 0.41 0.20 0.20 -0.07 0.14 0.10 0.09 -0.08 -0.00 0.36 1.00 0.37 0.35 0.23 0.36 0.37 0.36 0.23 0.22 -0.46
worst perimeter 0.97 0.36 0.97 0.96 0.24 0.59 0.73 0.86 0.22 -0.21 0.72 -0.10 0.72 0.76 -0.22 0.26 0.23 0.39 -0.10 -0.00 0.99 0.37 1.00 0.98 0.24 0.53 0.62 0.82 0.27 0.14 -0.78
worst area 0.94 0.34 0.94 0.96 0.21 0.51 0.68 0.81 0.18 -0.23 0.75 -0.08 0.73 0.81 -0.18 0.20 0.19 0.34 -0.11 -0.02 0.98 0.35 0.98 1.00 0.21 0.44 0.54 0.75 0.21 0.08 -0.73
worst smoothness 0.12 0.08 0.15 0.12 0.81 0.57 0.45 0.45 0.43 0.50 0.14 -0.07 0.13 0.13 0.31 0.23 0.17 0.22 -0.01 0.17 0.22 0.23 0.24 0.21 1.00 0.57 0.52 0.55 0.49 0.62 -0.42
worst compactness 0.41 0.28 0.46 0.39 0.47 0.87 0.75 0.67 0.47 0.46 0.29 -0.09 0.34 0.28 -0.06 0.68 0.48 0.45 0.06 0.39 0.48 0.36 0.53 0.44 0.57 1.00 0.89 0.80 0.61 0.81 -0.59
worst concavity 0.53 0.30 0.56 0.51 0.43 0.82 0.88 0.75 0.43 0.35 0.38 -0.07 0.42 0.39 -0.06 0.64 0.66 0.55 0.04 0.38 0.57 0.37 0.62 0.54 0.52 0.89 1.00 0.86 0.53 0.69 -0.66
worst concave points 0.74 0.30 0.77 0.72 0.50 0.82 0.86 0.91 0.43 0.18 0.53 -0.12 0.55 0.54 -0.10 0.48 0.44 0.60 -0.03 0.22 0.79 0.36 0.82 0.75 0.55 0.80 0.86 1.00 0.50 0.51 -0.79
worst symmetry 0.16 0.11 0.19 0.14 0.39 0.51 0.41 0.38 0.70 0.33 0.09 -0.13 0.11 0.07 -0.11 0.28 0.20 0.14 0.39 0.11 0.24 0.23 0.27 0.21 0.49 0.61 0.53 0.50 1.00 0.54 -0.42
worst fractal dimension 0.01 0.12 0.05 0.00 0.50 0.69 0.51 0.37 0.44 0.77 0.05 -0.05 0.09 0.02 0.10 0.59 0.44 0.31 0.08 0.59 0.09 0.22 0.14 0.08 0.62 0.81 0.69 0.51 0.54 1.00 -0.32
target -0.73 -0.42 -0.74 -0.71 -0.36 -0.60 -0.70 -0.78 -0.33 0.01 -0.57 0.01 -0.56 -0.55 0.07 -0.29 -0.25 -0.41 0.01 -0.08 -0.78 -0.46 -0.78 -0.73 -0.42 -0.59 -0.66 -0.79 -0.42 -0.32 1.00

LightGBM

LGMBRegressor

X, y = sklearn.datasets.load_diabetes(return_X_y=True, as_frame=True)
inspector = get_inspector(LGBMRegressor(n_estimators=5).fit(X, y), X, y)
Learning rate set to 0.5
0:  learn: 63.4011144   total: 896us    remaining: 3.59ms
1:  learn: 56.1323417   total: 1.42ms   remaining: 2.14ms
2:  learn: 52.9311271   total: 1.88ms   remaining: 1.25ms
3:  learn: 50.5129302   total: 2.39ms   remaining: 596us
4:  learn: 49.1286322   total: 2.77ms   remaining: 0us
inspector.methods
['permutation_importance',
 'plot_feature_clusters',
 'plot_partial_dependence',
 'plot_permutation_importance',
 'plot_pred_vs_act',
 'plot_residuals',
 'show_correlation']
inspector.permutation_importance()
s5     0.253769
bmi    0.250723
bp     0.130111
sex    0.059715
s3     0.051180
s2     0.038155
s1     0.020064
s4     0.018919
s6     0.015744
age    0.015219
dtype: float64
ax = inspector.plot_feature_clusters()

axes = inspector.plot_partial_dependence(features=["bmi"])

ax = inspector.plot_pred_vs_act()

ax = inspector.plot_residuals()

inspector.show_correlation()
  age sex bmi bp s1 s2 s3 s4 s5 s6 target
age 1.00 0.17 0.19 0.34 0.26 0.22 -0.08 0.20 0.27 0.30 0.19
sex 0.17 1.00 0.09 0.24 0.04 0.14 -0.38 0.33 0.15 0.21 0.04
bmi 0.19 0.09 1.00 0.40 0.25 0.26 -0.37 0.41 0.45 0.39 0.59
bp 0.34 0.24 0.40 1.00 0.24 0.19 -0.18 0.26 0.39 0.39 0.44
s1 0.26 0.04 0.25 0.24 1.00 0.90 0.05 0.54 0.52 0.33 0.21
s2 0.22 0.14 0.26 0.19 0.90 1.00 -0.20 0.66 0.32 0.29 0.17
s3 -0.08 -0.38 -0.37 -0.18 0.05 -0.20 1.00 -0.74 -0.40 -0.27 -0.39
s4 0.20 0.33 0.41 0.26 0.54 0.66 -0.74 1.00 0.62 0.42 0.43
s5 0.27 0.15 0.45 0.39 0.52 0.32 -0.40 0.62 1.00 0.46 0.57
s6 0.30 0.21 0.39 0.39 0.33 0.29 -0.27 0.42 0.46 1.00 0.38
target 0.19 0.04 0.59 0.44 0.21 0.17 -0.39 0.43 0.57 0.38 1.00

LGBMClassifier

X, y = sklearn.datasets.load_breast_cancer(return_X_y=True, as_frame=True)
inspector = get_inspector(LGBMClassifier(n_estimators=5).fit(X, y), X, y)
Learning rate set to 0.5
0:  learn: 0.2068913    total: 2.79ms   remaining: 11.2ms
1:  learn: 0.1073211    total: 4.88ms   remaining: 7.32ms
2:  learn: 0.0762370    total: 6.91ms   remaining: 4.61ms
3:  learn: 0.0572005    total: 8.96ms   remaining: 2.24ms
4:  learn: 0.0464524    total: 15.5ms   remaining: 0us
inspector.methods
['calculate_metrics_by_thresh',
 'confusion_matrix',
 'permutation_importance',
 'plot_feature_clusters',
 'plot_partial_dependence',
 'plot_permutation_importance',
 'show_correlation']
ax = inspector.calculate_metrics_by_thresh(
    sklearn.metrics.accuracy_score, np.linspace(0, 1, 11)
).plot(x="thresh")
100%|██████████| 11/11 [00:00<00:00, 2964.93it/s]

inspector.confusion_matrix()
  Predicted 0 Predicted 1 Totals
Actual 0 208 4 212
Actual 1 0 357 357
Totals 208 361 569
inspector.permutation_importance()
worst area                 0.069947
mean texture               0.024605
worst smoothness           0.016872
worst concavity            0.014411
worst concave points       0.009490
mean radius                0.008436
mean smoothness            0.004921
mean area                  0.003866
mean concavity             0.003515
perimeter error            0.003163
mean concave points        0.003163
area error                 0.002812
compactness error          0.002812
worst fractal dimension    0.002109
worst perimeter            0.002109
worst texture              0.001757
mean perimeter             0.001054
worst compactness          0.000351
concavity error            0.000000
concave points error       0.000000
symmetry error             0.000000
fractal dimension error    0.000000
worst radius               0.000000
smoothness error           0.000000
radius error               0.000000
mean fractal dimension     0.000000
mean symmetry              0.000000
mean compactness           0.000000
worst symmetry             0.000000
texture error              0.000000
dtype: float64
ax = inspector.plot_feature_clusters()

axes = inspector.plot_partial_dependence(features=["worst texture"])

ax = inspector.plot_permutation_importance()

inspector.show_correlation()
  mean radius mean texture mean perimeter mean area mean smoothness mean compactness mean concavity mean concave points mean symmetry mean fractal dimension radius error texture error perimeter error area error smoothness error compactness error concavity error concave points error symmetry error fractal dimension error worst radius worst texture worst perimeter worst area worst smoothness worst compactness worst concavity worst concave points worst symmetry worst fractal dimension target
mean radius 1.00 0.32 1.00 0.99 0.17 0.51 0.68 0.82 0.15 -0.31 0.68 -0.10 0.67 0.74 -0.22 0.21 0.19 0.38 -0.10 -0.04 0.97 0.30 0.97 0.94 0.12 0.41 0.53 0.74 0.16 0.01 -0.73
mean texture 0.32 1.00 0.33 0.32 -0.02 0.24 0.30 0.29 0.07 -0.08 0.28 0.39 0.28 0.26 0.01 0.19 0.14 0.16 0.01 0.05 0.35 0.91 0.36 0.34 0.08 0.28 0.30 0.30 0.11 0.12 -0.42
mean perimeter 1.00 0.33 1.00 0.99 0.21 0.56 0.72 0.85 0.18 -0.26 0.69 -0.09 0.69 0.74 -0.20 0.25 0.23 0.41 -0.08 -0.01 0.97 0.30 0.97 0.94 0.15 0.46 0.56 0.77 0.19 0.05 -0.74
mean area 0.99 0.32 0.99 1.00 0.18 0.50 0.69 0.82 0.15 -0.28 0.73 -0.07 0.73 0.80 -0.17 0.21 0.21 0.37 -0.07 -0.02 0.96 0.29 0.96 0.96 0.12 0.39 0.51 0.72 0.14 0.00 -0.71
mean smoothness 0.17 -0.02 0.21 0.18 1.00 0.66 0.52 0.55 0.56 0.58 0.30 0.07 0.30 0.25 0.33 0.32 0.25 0.38 0.20 0.28 0.21 0.04 0.24 0.21 0.81 0.47 0.43 0.50 0.39 0.50 -0.36
mean compactness 0.51 0.24 0.56 0.50 0.66 1.00 0.88 0.83 0.60 0.57 0.50 0.05 0.55 0.46 0.14 0.74 0.57 0.64 0.23 0.51 0.54 0.25 0.59 0.51 0.57 0.87 0.82 0.82 0.51 0.69 -0.60
mean concavity 0.68 0.30 0.72 0.69 0.52 0.88 1.00 0.92 0.50 0.34 0.63 0.08 0.66 0.62 0.10 0.67 0.69 0.68 0.18 0.45 0.69 0.30 0.73 0.68 0.45 0.75 0.88 0.86 0.41 0.51 -0.70
mean concave points 0.82 0.29 0.85 0.82 0.55 0.83 0.92 1.00 0.46 0.17 0.70 0.02 0.71 0.69 0.03 0.49 0.44 0.62 0.10 0.26 0.83 0.29 0.86 0.81 0.45 0.67 0.75 0.91 0.38 0.37 -0.78
mean symmetry 0.15 0.07 0.18 0.15 0.56 0.60 0.50 0.46 1.00 0.48 0.30 0.13 0.31 0.22 0.19 0.42 0.34 0.39 0.45 0.33 0.19 0.09 0.22 0.18 0.43 0.47 0.43 0.43 0.70 0.44 -0.33
mean fractal dimension -0.31 -0.08 -0.26 -0.28 0.58 0.57 0.34 0.17 0.48 1.00 0.00 0.16 0.04 -0.09 0.40 0.56 0.45 0.34 0.35 0.69 -0.25 -0.05 -0.21 -0.23 0.50 0.46 0.35 0.18 0.33 0.77 0.01
radius error 0.68 0.28 0.69 0.73 0.30 0.50 0.63 0.70 0.30 0.00 1.00 0.21 0.97 0.95 0.16 0.36 0.33 0.51 0.24 0.23 0.72 0.19 0.72 0.75 0.14 0.29 0.38 0.53 0.09 0.05 -0.57
texture error -0.10 0.39 -0.09 -0.07 0.07 0.05 0.08 0.02 0.13 0.16 0.21 1.00 0.22 0.11 0.40 0.23 0.19 0.23 0.41 0.28 -0.11 0.41 -0.10 -0.08 -0.07 -0.09 -0.07 -0.12 -0.13 -0.05 0.01
perimeter error 0.67 0.28 0.69 0.73 0.30 0.55 0.66 0.71 0.31 0.04 0.97 0.22 1.00 0.94 0.15 0.42 0.36 0.56 0.27 0.24 0.70 0.20 0.72 0.73 0.13 0.34 0.42 0.55 0.11 0.09 -0.56
area error 0.74 0.26 0.74 0.80 0.25 0.46 0.62 0.69 0.22 -0.09 0.95 0.11 0.94 1.00 0.08 0.28 0.27 0.42 0.13 0.13 0.76 0.20 0.76 0.81 0.13 0.28 0.39 0.54 0.07 0.02 -0.55
smoothness error -0.22 0.01 -0.20 -0.17 0.33 0.14 0.10 0.03 0.19 0.40 0.16 0.40 0.15 0.08 1.00 0.34 0.27 0.33 0.41 0.43 -0.23 -0.07 -0.22 -0.18 0.31 -0.06 -0.06 -0.10 -0.11 0.10 0.07
compactness error 0.21 0.19 0.25 0.21 0.32 0.74 0.67 0.49 0.42 0.56 0.36 0.23 0.42 0.28 0.34 1.00 0.80 0.74 0.39 0.80 0.20 0.14 0.26 0.20 0.23 0.68 0.64 0.48 0.28 0.59 -0.29
concavity error 0.19 0.14 0.23 0.21 0.25 0.57 0.69 0.44 0.34 0.45 0.33 0.19 0.36 0.27 0.27 0.80 1.00 0.77 0.31 0.73 0.19 0.10 0.23 0.19 0.17 0.48 0.66 0.44 0.20 0.44 -0.25
concave points error 0.38 0.16 0.41 0.37 0.38 0.64 0.68 0.62 0.39 0.34 0.51 0.23 0.56 0.42 0.33 0.74 0.77 1.00 0.31 0.61 0.36 0.09 0.39 0.34 0.22 0.45 0.55 0.60 0.14 0.31 -0.41
symmetry error -0.10 0.01 -0.08 -0.07 0.20 0.23 0.18 0.10 0.45 0.35 0.24 0.41 0.27 0.13 0.41 0.39 0.31 0.31 1.00 0.37 -0.13 -0.08 -0.10 -0.11 -0.01 0.06 0.04 -0.03 0.39 0.08 0.01
fractal dimension error -0.04 0.05 -0.01 -0.02 0.28 0.51 0.45 0.26 0.33 0.69 0.23 0.28 0.24 0.13 0.43 0.80 0.73 0.61 0.37 1.00 -0.04 -0.00 -0.00 -0.02 0.17 0.39 0.38 0.22 0.11 0.59 -0.08
worst radius 0.97 0.35 0.97 0.96 0.21 0.54 0.69 0.83 0.19 -0.25 0.72 -0.11 0.70 0.76 -0.23 0.20 0.19 0.36 -0.13 -0.04 1.00 0.36 0.99 0.98 0.22 0.48 0.57 0.79 0.24 0.09 -0.78
worst texture 0.30 0.91 0.30 0.29 0.04 0.25 0.30 0.29 0.09 -0.05 0.19 0.41 0.20 0.20 -0.07 0.14 0.10 0.09 -0.08 -0.00 0.36 1.00 0.37 0.35 0.23 0.36 0.37 0.36 0.23 0.22 -0.46
worst perimeter 0.97 0.36 0.97 0.96 0.24 0.59 0.73 0.86 0.22 -0.21 0.72 -0.10 0.72 0.76 -0.22 0.26 0.23 0.39 -0.10 -0.00 0.99 0.37 1.00 0.98 0.24 0.53 0.62 0.82 0.27 0.14 -0.78
worst area 0.94 0.34 0.94 0.96 0.21 0.51 0.68 0.81 0.18 -0.23 0.75 -0.08 0.73 0.81 -0.18 0.20 0.19 0.34 -0.11 -0.02 0.98 0.35 0.98 1.00 0.21 0.44 0.54 0.75 0.21 0.08 -0.73
worst smoothness 0.12 0.08 0.15 0.12 0.81 0.57 0.45 0.45 0.43 0.50 0.14 -0.07 0.13 0.13 0.31 0.23 0.17 0.22 -0.01 0.17 0.22 0.23 0.24 0.21 1.00 0.57 0.52 0.55 0.49 0.62 -0.42
worst compactness 0.41 0.28 0.46 0.39 0.47 0.87 0.75 0.67 0.47 0.46 0.29 -0.09 0.34 0.28 -0.06 0.68 0.48 0.45 0.06 0.39 0.48 0.36 0.53 0.44 0.57 1.00 0.89 0.80 0.61 0.81 -0.59
worst concavity 0.53 0.30 0.56 0.51 0.43 0.82 0.88 0.75 0.43 0.35 0.38 -0.07 0.42 0.39 -0.06 0.64 0.66 0.55 0.04 0.38 0.57 0.37 0.62 0.54 0.52 0.89 1.00 0.86 0.53 0.69 -0.66
worst concave points 0.74 0.30 0.77 0.72 0.50 0.82 0.86 0.91 0.43 0.18 0.53 -0.12 0.55 0.54 -0.10 0.48 0.44 0.60 -0.03 0.22 0.79 0.36 0.82 0.75 0.55 0.80 0.86 1.00 0.50 0.51 -0.79
worst symmetry 0.16 0.11 0.19 0.14 0.39 0.51 0.41 0.38 0.70 0.33 0.09 -0.13 0.11 0.07 -0.11 0.28 0.20 0.14 0.39 0.11 0.24 0.23 0.27 0.21 0.49 0.61 0.53 0.50 1.00 0.54 -0.42
worst fractal dimension 0.01 0.12 0.05 0.00 0.50 0.69 0.51 0.37 0.44 0.77 0.05 -0.05 0.09 0.02 0.10 0.59 0.44 0.31 0.08 0.59 0.09 0.22 0.14 0.08 0.62 0.81 0.69 0.51 0.54 1.00 -0.32
target -0.73 -0.42 -0.74 -0.71 -0.36 -0.60 -0.70 -0.78 -0.33 0.01 -0.57 0.01 -0.56 -0.55 0.07 -0.29 -0.25 -0.41 0.01 -0.08 -0.78 -0.46 -0.78 -0.73 -0.42 -0.59 -0.66 -0.79 -0.42 -0.32 1.00

XGBoost

XGBRegressor

X, y = sklearn.datasets.load_diabetes(return_X_y=True, as_frame=True)
inspector = get_inspector(XGBRegressor(n_estimators=5).fit(X, y), X, y)
inspector.methods
['permutation_importance',
 'plot_feature_clusters',
 'plot_partial_dependence',
 'plot_permutation_importance',
 'plot_pred_vs_act',
 'plot_residuals',
 'show_correlation']
inspector.permutation_importance()
s5     0.649371
bmi    0.445589
bp     0.137778
s6     0.103405
age    0.079496
s2     0.074219
s3     0.070875
s1     0.049026
sex    0.022239
s4     0.008080
dtype: float64
ax = inspector.plot_feature_clusters()

axes = inspector.plot_partial_dependence(features=["bmi"])

ax = inspector.plot_pred_vs_act()

axes = inspector.plot_residuals()

inspector.show_correlation()
  age sex bmi bp s1 s2 s3 s4 s5 s6 target
age 1.00 0.17 0.19 0.34 0.26 0.22 -0.08 0.20 0.27 0.30 0.19
sex 0.17 1.00 0.09 0.24 0.04 0.14 -0.38 0.33 0.15 0.21 0.04
bmi 0.19 0.09 1.00 0.40 0.25 0.26 -0.37 0.41 0.45 0.39 0.59
bp 0.34 0.24 0.40 1.00 0.24 0.19 -0.18 0.26 0.39 0.39 0.44
s1 0.26 0.04 0.25 0.24 1.00 0.90 0.05 0.54 0.52 0.33 0.21
s2 0.22 0.14 0.26 0.19 0.90 1.00 -0.20 0.66 0.32 0.29 0.17
s3 -0.08 -0.38 -0.37 -0.18 0.05 -0.20 1.00 -0.74 -0.40 -0.27 -0.39
s4 0.20 0.33 0.41 0.26 0.54 0.66 -0.74 1.00 0.62 0.42 0.43
s5 0.27 0.15 0.45 0.39 0.52 0.32 -0.40 0.62 1.00 0.46 0.57
s6 0.30 0.21 0.39 0.39 0.33 0.29 -0.27 0.42 0.46 1.00 0.38
target 0.19 0.04 0.59 0.44 0.21 0.17 -0.39 0.43 0.57 0.38 1.00

XGBClassifier

X, y = sklearn.datasets.load_breast_cancer(return_X_y=True, as_frame=True)
inspector = get_inspector(XGBClassifier(n_estimators=5).fit(X, y), X, y)
inspector.methods
['calculate_metrics_by_thresh',
 'confusion_matrix',
 'permutation_importance',
 'plot_feature_clusters',
 'plot_partial_dependence',
 'plot_permutation_importance',
 'show_correlation']
ax = inspector.calculate_metrics_by_thresh(
    sklearn.metrics.accuracy_score, np.linspace(0, 1, 11)
).plot(x="thresh")
100%|██████████| 11/11 [00:00<00:00, 3486.54it/s]

inspector.confusion_matrix()
  Predicted 0 Predicted 1 Totals
Actual 0 209 3 212
Actual 1 0 357 357
Totals 209 360 569
inspector.permutation_importance()
worst concave points       0.071353
worst radius               0.031283
mean concave points        0.017926
mean texture               0.017926
worst texture              0.013708
worst area                 0.007381
worst perimeter            0.004921
worst concavity            0.003515
mean radius                0.001757
area error                 0.001757
mean area                  0.001757
radius error               0.001757
mean concavity             0.001054
concave points error       0.000703
fractal dimension error    0.000000
worst compactness          0.000000
worst symmetry             0.000000
worst smoothness           0.000000
compactness error          0.000000
symmetry error             0.000000
concavity error            0.000000
smoothness error           0.000000
perimeter error            0.000000
texture error              0.000000
mean fractal dimension     0.000000
mean symmetry              0.000000
mean compactness           0.000000
mean smoothness            0.000000
mean perimeter             0.000000
worst fractal dimension    0.000000
dtype: float64
ax = inspector.plot_feature_clusters()

axes = inspector.plot_partial_dependence(features=["worst texture"])

ax = inspector.plot_permutation_importance()

inspector.show_correlation()
  mean radius mean texture mean perimeter mean area mean smoothness mean compactness mean concavity mean concave points mean symmetry mean fractal dimension radius error texture error perimeter error area error smoothness error compactness error concavity error concave points error symmetry error fractal dimension error worst radius worst texture worst perimeter worst area worst smoothness worst compactness worst concavity worst concave points worst symmetry worst fractal dimension target
mean radius 1.00 0.32 1.00 0.99 0.17 0.51 0.68 0.82 0.15 -0.31 0.68 -0.10 0.67 0.74 -0.22 0.21 0.19 0.38 -0.10 -0.04 0.97 0.30 0.97 0.94 0.12 0.41 0.53 0.74 0.16 0.01 -0.73
mean texture 0.32 1.00 0.33 0.32 -0.02 0.24 0.30 0.29 0.07 -0.08 0.28 0.39 0.28 0.26 0.01 0.19 0.14 0.16 0.01 0.05 0.35 0.91 0.36 0.34 0.08 0.28 0.30 0.30 0.11 0.12 -0.42
mean perimeter 1.00 0.33 1.00 0.99 0.21 0.56 0.72 0.85 0.18 -0.26 0.69 -0.09 0.69 0.74 -0.20 0.25 0.23 0.41 -0.08 -0.01 0.97 0.30 0.97 0.94 0.15 0.46 0.56 0.77 0.19 0.05 -0.74
mean area 0.99 0.32 0.99 1.00 0.18 0.50 0.69 0.82 0.15 -0.28 0.73 -0.07 0.73 0.80 -0.17 0.21 0.21 0.37 -0.07 -0.02 0.96 0.29 0.96 0.96 0.12 0.39 0.51 0.72 0.14 0.00 -0.71
mean smoothness 0.17 -0.02 0.21 0.18 1.00 0.66 0.52 0.55 0.56 0.58 0.30 0.07 0.30 0.25 0.33 0.32 0.25 0.38 0.20 0.28 0.21 0.04 0.24 0.21 0.81 0.47 0.43 0.50 0.39 0.50 -0.36
mean compactness 0.51 0.24 0.56 0.50 0.66 1.00 0.88 0.83 0.60 0.57 0.50 0.05 0.55 0.46 0.14 0.74 0.57 0.64 0.23 0.51 0.54 0.25 0.59 0.51 0.57 0.87 0.82 0.82 0.51 0.69 -0.60
mean concavity 0.68 0.30 0.72 0.69 0.52 0.88 1.00 0.92 0.50 0.34 0.63 0.08 0.66 0.62 0.10 0.67 0.69 0.68 0.18 0.45 0.69 0.30 0.73 0.68 0.45 0.75 0.88 0.86 0.41 0.51 -0.70
mean concave points 0.82 0.29 0.85 0.82 0.55 0.83 0.92 1.00 0.46 0.17 0.70 0.02 0.71 0.69 0.03 0.49 0.44 0.62 0.10 0.26 0.83 0.29 0.86 0.81 0.45 0.67 0.75 0.91 0.38 0.37 -0.78
mean symmetry 0.15 0.07 0.18 0.15 0.56 0.60 0.50 0.46 1.00 0.48 0.30 0.13 0.31 0.22 0.19 0.42 0.34 0.39 0.45 0.33 0.19 0.09 0.22 0.18 0.43 0.47 0.43 0.43 0.70 0.44 -0.33
mean fractal dimension -0.31 -0.08 -0.26 -0.28 0.58 0.57 0.34 0.17 0.48 1.00 0.00 0.16 0.04 -0.09 0.40 0.56 0.45 0.34 0.35 0.69 -0.25 -0.05 -0.21 -0.23 0.50 0.46 0.35 0.18 0.33 0.77 0.01
radius error 0.68 0.28 0.69 0.73 0.30 0.50 0.63 0.70 0.30 0.00 1.00 0.21 0.97 0.95 0.16 0.36 0.33 0.51 0.24 0.23 0.72 0.19 0.72 0.75 0.14 0.29 0.38 0.53 0.09 0.05 -0.57
texture error -0.10 0.39 -0.09 -0.07 0.07 0.05 0.08 0.02 0.13 0.16 0.21 1.00 0.22 0.11 0.40 0.23 0.19 0.23 0.41 0.28 -0.11 0.41 -0.10 -0.08 -0.07 -0.09 -0.07 -0.12 -0.13 -0.05 0.01
perimeter error 0.67 0.28 0.69 0.73 0.30 0.55 0.66 0.71 0.31 0.04 0.97 0.22 1.00 0.94 0.15 0.42 0.36 0.56 0.27 0.24 0.70 0.20 0.72 0.73 0.13 0.34 0.42 0.55 0.11 0.09 -0.56
area error 0.74 0.26 0.74 0.80 0.25 0.46 0.62 0.69 0.22 -0.09 0.95 0.11 0.94 1.00 0.08 0.28 0.27 0.42 0.13 0.13 0.76 0.20 0.76 0.81 0.13 0.28 0.39 0.54 0.07 0.02 -0.55
smoothness error -0.22 0.01 -0.20 -0.17 0.33 0.14 0.10 0.03 0.19 0.40 0.16 0.40 0.15 0.08 1.00 0.34 0.27 0.33 0.41 0.43 -0.23 -0.07 -0.22 -0.18 0.31 -0.06 -0.06 -0.10 -0.11 0.10 0.07
compactness error 0.21 0.19 0.25 0.21 0.32 0.74 0.67 0.49 0.42 0.56 0.36 0.23 0.42 0.28 0.34 1.00 0.80 0.74 0.39 0.80 0.20 0.14 0.26 0.20 0.23 0.68 0.64 0.48 0.28 0.59 -0.29
concavity error 0.19 0.14 0.23 0.21 0.25 0.57 0.69 0.44 0.34 0.45 0.33 0.19 0.36 0.27 0.27 0.80 1.00 0.77 0.31 0.73 0.19 0.10 0.23 0.19 0.17 0.48 0.66 0.44 0.20 0.44 -0.25
concave points error 0.38 0.16 0.41 0.37 0.38 0.64 0.68 0.62 0.39 0.34 0.51 0.23 0.56 0.42 0.33 0.74 0.77 1.00 0.31 0.61 0.36 0.09 0.39 0.34 0.22 0.45 0.55 0.60 0.14 0.31 -0.41
symmetry error -0.10 0.01 -0.08 -0.07 0.20 0.23 0.18 0.10 0.45 0.35 0.24 0.41 0.27 0.13 0.41 0.39 0.31 0.31 1.00 0.37 -0.13 -0.08 -0.10 -0.11 -0.01 0.06 0.04 -0.03 0.39 0.08 0.01
fractal dimension error -0.04 0.05 -0.01 -0.02 0.28 0.51 0.45 0.26 0.33 0.69 0.23 0.28 0.24 0.13 0.43 0.80 0.73 0.61 0.37 1.00 -0.04 -0.00 -0.00 -0.02 0.17 0.39 0.38 0.22 0.11 0.59 -0.08
worst radius 0.97 0.35 0.97 0.96 0.21 0.54 0.69 0.83 0.19 -0.25 0.72 -0.11 0.70 0.76 -0.23 0.20 0.19 0.36 -0.13 -0.04 1.00 0.36 0.99 0.98 0.22 0.48 0.57 0.79 0.24 0.09 -0.78
worst texture 0.30 0.91 0.30 0.29 0.04 0.25 0.30 0.29 0.09 -0.05 0.19 0.41 0.20 0.20 -0.07 0.14 0.10 0.09 -0.08 -0.00 0.36 1.00 0.37 0.35 0.23 0.36 0.37 0.36 0.23 0.22 -0.46
worst perimeter 0.97 0.36 0.97 0.96 0.24 0.59 0.73 0.86 0.22 -0.21 0.72 -0.10 0.72 0.76 -0.22 0.26 0.23 0.39 -0.10 -0.00 0.99 0.37 1.00 0.98 0.24 0.53 0.62 0.82 0.27 0.14 -0.78
worst area 0.94 0.34 0.94 0.96 0.21 0.51 0.68 0.81 0.18 -0.23 0.75 -0.08 0.73 0.81 -0.18 0.20 0.19 0.34 -0.11 -0.02 0.98 0.35 0.98 1.00 0.21 0.44 0.54 0.75 0.21 0.08 -0.73
worst smoothness 0.12 0.08 0.15 0.12 0.81 0.57 0.45 0.45 0.43 0.50 0.14 -0.07 0.13 0.13 0.31 0.23 0.17 0.22 -0.01 0.17 0.22 0.23 0.24 0.21 1.00 0.57 0.52 0.55 0.49 0.62 -0.42
worst compactness 0.41 0.28 0.46 0.39 0.47 0.87 0.75 0.67 0.47 0.46 0.29 -0.09 0.34 0.28 -0.06 0.68 0.48 0.45 0.06 0.39 0.48 0.36 0.53 0.44 0.57 1.00 0.89 0.80 0.61 0.81 -0.59
worst concavity 0.53 0.30 0.56 0.51 0.43 0.82 0.88 0.75 0.43 0.35 0.38 -0.07 0.42 0.39 -0.06 0.64 0.66 0.55 0.04 0.38 0.57 0.37 0.62 0.54 0.52 0.89 1.00 0.86 0.53 0.69 -0.66
worst concave points 0.74 0.30 0.77 0.72 0.50 0.82 0.86 0.91 0.43 0.18 0.53 -0.12 0.55 0.54 -0.10 0.48 0.44 0.60 -0.03 0.22 0.79 0.36 0.82 0.75 0.55 0.80 0.86 1.00 0.50 0.51 -0.79
worst symmetry 0.16 0.11 0.19 0.14 0.39 0.51 0.41 0.38 0.70 0.33 0.09 -0.13 0.11 0.07 -0.11 0.28 0.20 0.14 0.39 0.11 0.24 0.23 0.27 0.21 0.49 0.61 0.53 0.50 1.00 0.54 -0.42
worst fractal dimension 0.01 0.12 0.05 0.00 0.50 0.69 0.51 0.37 0.44 0.77 0.05 -0.05 0.09 0.02 0.10 0.59 0.44 0.31 0.08 0.59 0.09 0.22 0.14 0.08 0.62 0.81 0.69 0.51 0.54 1.00 -0.32
target -0.73 -0.42 -0.74 -0.71 -0.36 -0.60 -0.70 -0.78 -0.33 0.01 -0.57 0.01 -0.56 -0.55 0.07 -0.29 -0.25 -0.41 0.01 -0.08 -0.78 -0.46 -0.78 -0.73 -0.42 -0.59 -0.66 -0.79 -0.42 -0.32 1.00