Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

get top feature gridsearchcv

#when using with pipeline and gridsearch
feature_names = model.best_estimator_.named_steps['vect'].get_feature_names()
coefs = model.best_estimator_.named_steps['model'].coef_.flatten()

# Zip coefficients and names together and make a DataFrame
zipped = zip(feature_names, coefs)
df_f = pd.DataFrame(zipped, columns=["feature", "value"])

#if plotting add color
# Sort the features by the absolute value of their coefficient
df_f["abs_value"] = df_f["value"].apply(lambda x: abs(x))
df_f["colors"] = df_f["value"].apply(lambda x: "green" if x > 0 else "red")
df_f = df_f.sort_values("abs_value", ascending=False)
 
PREVIOUS NEXT
Tagged: #top #feature #gridsearchcv
ADD COMMENT
Topic
Name
1+9 =