Unfortunately, I could not plot coef_ magnitude as the size of features did not correspond to the size of coef_… I can’t find my mistake. Here is my code :
numerical_selector = selector(dtype_exclude=object)
categorical_selector = selector(dtype_exclude=object)
preprocessor=ColumnTransformer([
('onehotencoder',OneHotEncoder(handle_unknown="ignore"),categorical_selector(data)),
('standarscaler',StandardScaler(),numerical_selector(data))
])
model=make_pipeline(preprocessor,LogisticRegression(max_iter=1000))
cv_result=cross_validate(model,data,target,cv=10,return_estimator=True)
categorical_columns=categorical_selector(data)
numerical_columns=numerical_selector(data)
preprocessor.fit(data)
feature_names = (preprocessor.named_transformers_["onehotencoder"]
.get_feature_names_out(categorical_columns)).tolist()
feature_names += numerical_columns
coefs = [est[-1].coef_ for est in cv_result["estimator"]]
weights = pd.DataFrame(coefs[0], columns=feature_names)
Here I got an error :
ValueError: Shape of passed values is (1, 394), indices imply (1, 396)
and I checked :
coefs[0].shape => (1, 394)
len(feature_names) => 396
What’s wrong ???
Thanks for any help !
Marc