【发布时间】:2018-12-15 11:23:00
【问题描述】:
我正在尝试使用 Python 和 Sklearn 创建分类器。我目前已成功导入所有数据。我一直在尝试遵循here 的教程,并在进行过程中对其进行了一些更改。后来进入该项目,我意识到他们的训练和测试数据与我的大不相同。如果我理解正确,他们有这样的事情:
X_train = ['Article or News article here', 'Anther News Article or Article here', ...]
y_train = ['Article Type', 'Article Type', ...]
#Same for the X_test and y_test
虽然我有这样的事情:
X_train = [['Dylan went in the house. Robert left the house', 'Where is Dylan?'], ['Mary ate the apple. Tom ate the cake', 'Who ate the cake?'], ...]
y_train = ['In the house.', 'Tom ate the cake']
#Same for the X_test and y_test
当我尝试使用管道训练分类器时:
text_clf = Pipeline([('vect', CountVectorizer(stop_words='english')),
('tfidf', TfidfTransformer(use_idf=True)),
('clf', SGDClassifier(loss='hinge', penalty='l2', alpha=1e-3, random_state=42,
verbose=1)),])
我得到错误:
AttributeError: 'list' object has no attribute 'lower'
在这一行:
text_clf.fit(X_train, y_train)
经过研究,我现在知道这是因为我正在为我的 X_train 数据输入一个数组,而不是一个字符串。
所以我的问题是,我如何构建一个管道来接受我的X_train 数据的数组和我的y_train 数据的字符串?这可能与管道有关吗?
【问题讨论】:
标签: python scikit-learn pipeline