所以我用 sklearn 朴素贝叶斯分类器构建了一个模型。我需要知道如何通过输入预测句子
当我只是对句子进行硬编码时,它工作正常,看起来像这样
new_sentence = ['its so broken']
new_testdata_tfidf= tfidf.transform(new_sentence)
#transform it to matrix to see the score TFIDF on the training data
fit_feature_selection = selection.transform(new_testdata_tfidf)
#transform the new data to see if the feature remove or not, because after tfidf i use chi2 selection feature.
predicted = classifier.predict(feature_selection )
#then predict it. the classificaiton out, the class is -1 which is the correct answer
Run Code Online (Sandbox Code Playgroud)
我需要用手输入文本数据作为输入,所以我这样使用
new_sentence = input[('')]
#i input the same sentence its so broken …Run Code Online (Sandbox Code Playgroud)