def decision_plot(self, X, y): """Visualization of the additive feature attribution.""" # Automates single-target slicing y = super()._check_target_index(y=y) for index in range(_n_targets(y)): self.fit(X=X, y=y, index=index) explainer, shap_values = self.explainer(X=X) shap.decision_plot(base_value=explainer.expected_value, shap_values=shap_values, feature_names=list(X.columns), show=self.show)
def force_plot(self, X, y): """Interactive Javascript visualization of Shapley values.""" shap.initjs() # Automates single-target slicing y = super()._check_target_index(y=y) for index in range(_n_targets(y)): self.fit(X=X, y=y, index=index) explainer, shap_values = self.explainer(X=X) force_plot = display( shap.force_plot(base_value=explainer.expected_value, shap_values=shap_values, features=X, plot_cmap=['#52A267', '#F0693B'], feature_names=list(X.columns)))
def summary_plot(self, X, y, plot_type='dot'): """Visualizaion of the feature importance and feature effects.""" assert (plot_type in _SHAP_SUMMARY_PLOT_CHOICE) # Automates single-target slicing y = super()._check_target_index(y=y) for index in range(_n_targets(y)): self.fit(X=X, y=y, index=index) _, shap_values = self.explainer(X=X) shap.summary_plot(shap_values=shap_values, features=X, plot_type=plot_type, feature_names=list(X.columns), show=self.show)
def dependence_plot(self, X, y, interaction_index='auto', alpha=None, dot_size=None): """Visualization of a feature's effect on a regressor's prediction.""" # Automates single-target slicing y = super()._check_target_index(y=y) for index in range(_n_targets(y)): self.fit(X=X, y=y, index=index) _, shap_values = self.explainer(X=X) shap.dependence_plot(ind='rank(0)', shap_values=shap_values, features=X, feature_names=list(X.columns), cmap=plt.get_cmap('hot'), interaction_index=interaction_index, alpha=alpha, dot_size=dot_size, show=self.show)