簡體   English   中英

LinearSVC無法正確分類情緒

[英]LinearSVC not classifying the sentiment correctly

我正在嘗試使用scikit-learning LinearSVC分類器制作情感分析器。 問題在於分類器將每個句子分類為肯定的。 另一個問題是-為什么函數predict()向我返回每個文本的分類標簽列表? 我認為它應該只返回一個文本/數字,這是分類標簽。 這是從代碼中摘錄的示例。

vectorizer = TfidfVectorizer(input='content', decode_error='ignore')
vect_train_x = vectorizer.fit_transform(training_data) # this is actually a list of sentences

scaler = StandardScaler(with_mean=False) # I don't know why it should be False
X_train = scaler.fit_transform(vect_train_x)  # compute mean, std and transform training data as well

vect_test_x = vectorizer.transform(test) # the sentence that needs to be classified

X_test = scaler.transform(vect_test_x) 

clf = LinearSVC()
clf.fit(X_train, labels)
print vect_test_x
print clf.predict(X_test) # returning me a list of Positive => ['Positive' 'Positive' 'Positive' 'Positive' 'Positive' 'Positive']

如果您能向我解釋我到底不了解什么,我將不勝感激。 我試圖閱讀文檔,但是沒有任何示例,我無法理解。 我的訓練數據包括10萬肯定的句子和10萬否定的句子。

遇到這個問題,我遇到了同樣的問題,解決我問題的方法是先將X_test轉換為列表,然后轉換為np.array,然后將其傳遞給'predict'函數

new_array = []
new_array.append(Input) #Input is string if reading from a file or from input()
X_test = np.array(new_array)
print clf.predict(X_test)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM