【发布时间】:2020-12-11 07:20:00
【问题描述】:
我已经使用 csv 中的一些数据训练了一个聊天机器人。所有的 tçdatabase 和模型都工作正常,它可以预测句子的标签,但我希望聊天机器人预测输入的标签。 这是代码(是一个sklearn管道):
while True:
usr_inp = input("Tú: ")
X_predict = train_test_split(usr_inp , test_size=0.1 , random_state=12)
prediction = pipeline.predict(X_predict)
print("Prediction: " , prediction)
它给出了这个错误:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-41-db8a012d9786> in <module>()
47 usr_inp = input("Tú: ")
48 X_predict = train_test_split(usr_inp , test_size=0.1 , random_state=12)
---> 49 prediction = pipeline.predict(X_predict)
50 print("Prediction: " , prediction)
6 frames
/usr/local/lib/python3.6/dist-packages/sklearn/feature_extraction/text.py in _preprocess(doc, accent_function, lower)
66 """
67 if lower:
---> 68 doc = doc.lower()
69 if accent_function is not None:
70 doc = accent_function(doc)
AttributeError: 'list' object has no attribute 'lower'
型号:
#Model & Pipeline
model = LogisticRegression(C=25 , solver="saga" , max_iter=2000)
pipeline = Pipeline([("tfidf" , vectorizer) , ("clf" , model)])
pipeline.fit(X_train , X_test)
有人可以帮我吗? 谢谢
【问题讨论】:
标签: python pandas scikit-learn