Arize AI
Search…
⌃K

Feature Importance

Assign a certain score to each feature to weigh how much or how little it impacted the outcome

Overview

Feature importance is a compilation of a class of techniques that take in all the features related to making a model prediction and assign a certain score to each feature to weigh how much or how little it impacted the outcome.
Important: Arize does NOT REQUIRE a model artifact upload to use feature importance. Feature Importance values should be calculated by the user or a surrogate model and then logged to Arize.
SHAP Values (a feature importance technique) can be logged along with the inferences or after.

How to Send Feature Importance to Arize

Arize supports 2 methods for ingesting and visualizing feature importance, with tradeoffs:
Tradeoffs of feature importance generation methods

Code Example

# 1. Generate the Shap Values and save as Dataframe
explainer = shap.TreeExplainer(tree_model)
shap_values = explainer.shap_values(X_data)
shap_dataframe = pd.DataFrame(
shap_values, columns=[f"{fn}_shap" for fn in data["feature_names"]]
)
# 2.Define the Schema. Link the feature column with its corresponding shap column
feature_cols = ["MERCHANT_TYPE", "ENTRY_MODE", "STATE", "MEAN_AMOUNT", "STD_AMOUNT", "TX_AMOUNT"]
shap_cols = shap_dataframe.columns
schema = Schema(
prediction_id_column_name="prediction_id",
...
feature_column_names= feature_cols,
shap_values_column_names=dict(zip(feature_cols, shap_cols)),
)
# Log the dataframe with the schema mapping
response = arize_client.log(
model_id="sample-model-1",
model_version= "v1",
model_type=ModelTypes.SCORE_CATEGORICAL,
environment=Environments.PRODUCTION,
dataframe=test_dataframe,
schema=schema,
)
Questions? Email us at [email protected]com or Slack us in the #arize-support channel
Last modified 30d ago