You can download this code by clicking the button below.
This code is now available for download.
This function uses Eli5's PermutationImportance to evaluate feature importance and visualizes the results through eli5.show_weights.
Technology Stack : Eli5, PermutationImportance
Code Type : Python Function
Code Difficulty : Intermediate
def visualize_feature_importances(model, X, feature_names):
"""
Visualize feature importances from a fitted model using Eli5.
Args:
model: Fitted machine learning model.
X: Input features.
feature_names: Names of the input features.
"""
import eli5
from eli5.sklearn import PermutationImportance
# Fit the PermutationImportance model
perm = PermutationImportance(model, random_state=42).fit(X, y)
# Create a permutation feature importance visualization
eli5.show_weights(perm, feature_names=feature_names, top=10)