Python 逻辑回归数据框列名的数量不为';t匹配来自管道的系数数
我想做一个seaborn条形图,在y轴上有特征系数值,在y轴上有特征名称。然而,系数的数量(38)与特征名称的数量(61)不匹配,我不知道如何修复它。我有以下代码:Python 逻辑回归数据框列名的数量不为';t匹配来自管道的系数数,python,Python,我想做一个seaborn条形图,在y轴上有特征系数值,在y轴上有特征名称。然而,系数的数量(38)与特征名称的数量(61)不匹配,我不知道如何修复它。我有以下代码: import seaborn as sbn from sklearn.preprocessing import StandardScaler, OneHotEncoder from sklearn.linear_model import LogisticRegression from sklearn.model_selection
import seaborn as sbn
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.impute import SimpleImputer
numeric_features = X_train.select_dtypes(include = 'float64').columns
numeric_transformer = Pipeline(steps=[('imputer', SimpleImputer(strategy='median')),
('scaler', StandardScaler())])
categorical_features = X_train.select_dtypes(include = object).columns
categorical_transformer = OneHotEncoder(handle_unknown='ignore')
from sklearn.compose import ColumnTransformer
preprocessor = ColumnTransformer(
transformers=[
('num', numeric_transformer, numeric_features),
('cat', categorical_transformer, categorical_features)])
# Append classifier to preprocessing pipeline.
# Now we have a full prediction pipeline.
clf = Pipeline(steps=[('preprocessor', preprocessor),
('classifier', LogisticRegression())])
model = clf.fit(X_train_bal, y_train_bal.values.ravel())
X_train_bal.columns.size
61
model.named_steps['classifier'].coef_
array([[ 0.28870311, -0.13493393, 0.47809258, 0.26252795, 0. ,
0. , 0.26399422, 0.06960872, -0.11635474, 0.70409391,
0.66109449, 1.54120473, 1.13382411, 1.37477535, 0.01964528,
0.41846923, 1.67995602, 0.32164349, -0.02979333, 0.02982878,
-0.35519273, 1.18018633, 0.16830654, 0.08836489, -0.68934245,
-0.639237 , -0.35329415, 0.33123055, 0.57701572, 0.01364959,
-0.32165185, -0.00945931, -0.47790595, 0.15139768, -0.89368239,
0.65439657, 0.52214267, 0.05314618]])
model.named_steps['classifier'].coef_.size
38
# ax = sns.barplot(x="time", y="tip", data=tips,
order=["Dinner", "Lunch"])