Skip to content

Commit

Permalink
only get feature_importance if select feature by top n. (#3235)
Browse files Browse the repository at this point in the history
* only get feature_importance if select feature by top n.

* remove extra import

---------

Co-authored-by: Richard Li <[email protected]>
  • Loading branch information
RichardLi1437 and Richard Li authored Aug 19, 2024
1 parent 7d13863 commit a0567e3
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from shared_utilities.io_utils import (
try_read_mltable_in_spark, try_read_mltable_in_spark_with_error, save_spark_df_as_mltable
)
from shared_utilities.momo_exceptions import DataNotFoundError, InvalidInputError
from shared_utilities.momo_exceptions import InvalidInputError


def run():
Expand Down Expand Up @@ -42,16 +42,12 @@ def run():
input_df1 = input_df2

feature_importance = None
try:
feature_importance = try_read_mltable_in_spark_with_error(args.feature_importance, "feature_importance")
except DataNotFoundError as e:
if args.filter_type == FeatureSelectorType.TOP_N_BY_ATTRIBUTION.name:
raise e
except Exception:
if args.filter_type == FeatureSelectorType.TOP_N_BY_ATTRIBUTION.name:
raise Exception(
"Error encountered when retrieving top N features. Please ensure target_column is defined."
)
if args.filter_type == FeatureSelectorType.TOP_N_BY_ATTRIBUTION.name:
try:
feature_importance = try_read_mltable_in_spark_with_error(args.feature_importance, "feature_importance")
except Exception as e:
raise Exception(f"Error encountered when retrieving top N features. {e}. "
"The feature importance step may not have completed successfully.")

feature_selector = FeatureSelectorFactory().produce(
feature_selector_type=args.filter_type,
Expand Down

0 comments on commit a0567e3

Please sign in to comment.