Skip to content

Instantly share code, notes, and snippets.

@amandaiglesiasmoreno
Created November 22, 2021 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amandaiglesiasmoreno/4a4b136993927b53df7c9768c432797d to your computer and use it in GitHub Desktop.
Save amandaiglesiasmoreno/4a4b136993927b53df7c9768c432797d to your computer and use it in GitHub Desktop.
# 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