【发布时间】:2018-04-26 21:41:23
【问题描述】:
我用 TfIdfVectorizer 转换器和 OnevsRestClassifier 估计器创建了一个管道,并在训练数据上对其进行了如下训练
# Split data using train_test_split
print "Split data into train and test sets"
x_train, x_test, y_train, y_test = train_test_split(
data_x, data_y, test_size=0.33)
# transform matrix of plots into lists to pass to a TfidfVectorizer
train_x = [x[0].strip() for x in x_train.tolist()]
test_x = [x[0].strip() for x in x_test.tolist()]
# Pipeline fit and transform
print "Learn the model using train data"
model = text_clf.fit(train_x, y_train)
# Predict the test data
print "Predict the recipients on test data"
predictions = model.predict(test_x)
现在,我想使用经过训练的模型来预测新的未标记数据的类别。 我试过了,报错了
# Read text from input
text = raw_input()
print "Input : ", text
new_data = text_clf.transform([text])
predict = model.predict(new_data)
这是错误。我做错了什么?
AttributeError: 'OneVsRestClassifier' object has no attribute 'transform'
【问题讨论】:
标签: python-2.7 scikit-learn tf-idf multilabel-classification