I am using Isolation forest for anomaly detection on multidimensional data. The algorithm is detecting anomalous records with good accuracy. Apart from detecting anomalous records I also need to find out which features are contributing the most for a data point to be anomalous. Is there any way we can get this?
import shap from sklearn.ensemble import IsolationForest # Load data and train Anomaly Detector as usual X_train, X_test, ... est = IsolationForest() est.fit(...) # Create shap values and plot them X_explain = X_test shap_values = shap.TreeExplainer(est).shap_values(X_explain) shap.summary_plot(shap_values, X_explain)
You can also get partial dependence plots for a particular feature, or a plot showing the feature contributions for a single X instance. Examples for this is given in the shap project README.
One possible describing feature importance in unsupervised outlier detecion is described in Contextual Outlier Interpretation. Similar as in the Lime approach, local linearity is assumed and by sampling a data points around the outlier of interest a classification problem is generated. The authors suggest to apply a SVM with linear kernel and use estimeited weights for feature importance.