@dataclass class FeatureImportance(ModelTest)
Test if the subgroups of the protected attributes are the top ranking important variables based on user-inputted feature importance values.
To pass, subgroups should not fall in the top n most important variables.
The test also stores a dataframe showing the results of each groups.
attrs- List of protected attributes.
threshold- Threshold for the test. To pass, subgroups should not fall in the top n (threshold) most important variables.
test_name- Name of the test, default is 'Feature Importance Test'.
test_desc- Description of the test. If none is provided, an automatic description will be generated based on the rest of the arguments passed in.
def plot(df: pd.DataFrame, show_n: int = 10, save_plots: bool = True)
Plot the top n most important features based on their importance values.
df- A dataframe with 2 columns - first column of feature names and second column of importance values.
show_n- Show the top n important features on the plot.
def get_result(df_importance) -> pd.DataFrame
Output a dataframe containing the test results of the protected attributes.
df_importance- A dataframe with 2 columns - first column with feature names and second column with importance values.
def run(df_importance) -> bool
Runs test by calculating result and evaluating if it passes a defined condition.
df_importance- A dataframe with 2 columns - first column of feature names and second column of importance values.