# Obtain my code package deal
# !pip set up git+https://github.com/Alyxx-The-Sniper/outlier_explainer.git@version-2
# Put together any dataset
from sklearn.datasets import load_breast_cancer
import pandas as pd
X = pd.DataFrame(load_breast_cancer().knowledge, columns=load_breast_cancer().feature_names)
print(X.form)# output
(569, 30)
from outlier_explainer import OutlierExplainerShap
explainer = OutlierExplainerShap(methodology='isolation_forest', contamination=0.001)explainer.match(X)
outliers = explainer.detect_outliers()
outliers
# output
array([461])
The Isolation Forest algorithm, utilizing a contamination fee of 0.001, detected an anomaly at index [461]. Why is that this thought-about an anomaly? SHAP may help clarify the underlying purpose.
# choose index from outliers
# present prime 5 options that making this occasion an anomaly (prime 5 in under dataframe)
explainer.explain_outlier(outliers[0], visualize=True, top_n=5)