因此,我正在使用Naive Bayes MultinomialNB来预测Twitter情绪,我同时拥有训练和测试数据,并且我已经使用训练数据训练了该模型。然后我试图用测试数据进行预测,但它表示尺寸错误。我该如何解决?
getDisplayNameOfId(id:string):Observable<string>{
let gdnid = new Subject<string>();
firebase.database().ref("/users").orderByKey().once("value")
.then((snapshot) => {
let dni:string;
snapshot.forEach((childSnapshot) => {
if (childSnapshot.val().UserId === id){
dni=childSnapshot.val().firstName + " " +childSnapshot.val().lastName;
}
});
gdnid.next(dni);
});
return gdnid.asObservable();
}
因此,当我使用模型进行预测时,会引发尺寸错误。
from sklearn.naive_bayes import MultinomialNB
pf = pd.read_csv('/content/train.csv')
from sklearn.feature_extraction.text import TfidfVectorizer
tfidf_vectorizer = TfidfVectorizer()
tfidf = tfidf_vectorizer.fit_transform(pf.original_text)
model = MultinomialNB()
model.fit(tfidf,pf.sentiment_class)
test_csv = pd.read_csv("/content/test.csv")
test_tfidf = tfidf_vectorizer.transform(test_csv['original_text'])
test_tfidf.toarray()
array([[0. , 0. , 0. , ..., 0.15573603, 0. ,
0. ],
[0.2400925 , 0. , 0. , ..., 0. , 0. ,
0. ],
[0. , 0. , 0. , ..., 0. , 0.46763784,
0. ],
...,
[0. , 0. , 0. , ..., 0. , 0. ,
0. ],
[0. , 0. , 0. , ..., 0. , 0.182512 ,
0. ],
[0. , 0. , 0. , ..., 0. , 0.42798355,
0. ]])