【发布时间】:2019-06-29 16:33:27
【问题描述】:
我正在尝试使用 SKLearn 0.20.2 来制作管道,同时使用新的 ColumnTransformer 功能。我的问题是,当我运行我的分类器时:clf.fit(x_train, y_train) 我不断收到错误消息:
ValueError: all the input array dimensions except for the concatenation axis must match exactly
我有一列名为text 的文本块。我所有的其他专栏本质上都是数字的。我正在尝试在我的管道中使用 Countvectorizer,我认为这就是问题所在。非常感谢您的帮助。
在我运行管道并检查我的 x_train/y_train 后,如果有帮助,它看起来像这样(省略通常显示在左列中的行号,并且文本列比图像中显示的要高)。
from sklearn.impute import SimpleImputer
from sklearn.compose import ColumnTransformer
# plus other necessary modules
# mapped to column names from dataframe
numeric_features = ['hasDate', 'iterationCount', 'hasItemNumber', 'isEpic']
numeric_transformer = Pipeline(steps=[
('imputer', SimpleImputer(strategy='median'))
])
# mapped to column names from dataframe
text_features = ['text']
text_transformer = Pipeline(steps=[
('vect', CountVectorizer())
])
preprocessor = ColumnTransformer(
transformers=[('num', numeric_transformer, numeric_features),('text', text_transformer, text_features)]
)
clf = Pipeline(steps=[('preprocessor', preprocessor),
('classifier', MultinomialNB())
])
x_train, x_test, y_train, y_test = train_test_split(features, labels, test_size=0.33)
clf.fit(x_train,y_train)
【问题讨论】:
-
train_test_split中的features和labels是什么?features.shape和labels.shape的结果?
标签: python machine-learning scikit-learn