Skip to content

Add get_feature_importance() method to AutoML class#825

Open
TheChyeahhh wants to merge 2 commits into
mljar:masterfrom
TheChyeahhh:feature/get-feature-importance
Open

Add get_feature_importance() method to AutoML class#825
TheChyeahhh wants to merge 2 commits into
mljar:masterfrom
TheChyeahhh:feature/get-feature-importance

Conversation

@TheChyeahhh
Copy link
Copy Markdown

Description

Closes #809 (filed by maintainer @pplonski)

Adds a convenient get_feature_importance() method to the public AutoML API so users can retrieve global feature importance without manually accessing internal model directories.

Usage

automl = AutoML()
automl.fit(X_train, y_train)
importance_df = automl.get_feature_importance()
# Returns DataFrame: feature | mean_rank | models_present

Design

  • Delegates to the existing _compute_global_feature_importance() function used by the structured report — no duplicated logic.
  • Returns a clean pandas.DataFrame sorted by importance.
  • Returns None gracefully when importance data is unavailable.
  • Raises AutoMLException with a clear message if fit() has not been called.

Changes

supervised/automl.py — 37 lines added (+1 import, +36 method body)

When PreprocessingMissingValues._fit_na_fill is called on a column
containing exclusively null values, x.value_counts() returns an empty
Series. The subsequent sorted(...)[0] then raises:
  IndexError: list index out of range

This adds an early return of None for the empty case, allowing the
caller to proceed with a safe fallback fill value.

Fixes mljar#770
Adds a unified public method to retrieve global feature importance
computed across all trained models, as requested by the maintainer.

Usage:
    automl = AutoML()
    automl.fit(X_train, y_train)
    importance_df = automl.get_feature_importance()
    # Returns DataFrame with columns: feature, mean_rank, models_present

The method returns None when importance data is not available and
raises AutoMLException if fit() hasn't been called yet.

Closes mljar#809
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: Add get_feature_importance() to AutoML

1 participant