Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# function that computes the mutual infomation score between a categorical serie and the column Churn
def compute_mutual_information(categorical_serie):
return mutual_info_score(categorical_serie, df_telco.Churn)
# select categorial variables excluding the response variable
categorical_variables = df_telco.select_dtypes(include=object).drop('Churn', axis=1)
# compute the mutual information score between each categorical variable and the target
feature_importance = categorical_variables.apply(compute_mutual_information).sort_values(ascending=False)
# visualize feature importance
print(feature_importance)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment