[英]what is better to train your own model for sentiment analysis or to use pre trained model like vader and textblob?
我有 python 腳本,該腳本訓練了用於情感分析的數據集,並使用帶有tfidf 、交叉驗證、 bigram和GridSearchCV的logisticRegression model 創建了 model。 對文本執行預處理階段。
我嘗試使用像VaderSentiment這樣的預訓練 model 來比較這兩個模型。
真實數據的結果是:
那么我訓練有素的 model 的錯誤在哪里? 還是最好使用 vaderSentiment 進行 twitter 情緒分析?
請注意,在我訓練有素的結果中,我得到了:
Accuracy: 91.482%
Best parameters set found on development set:
{'bow__ngram_range': (1, 2), 'tfidf__use_idf': True}
Optimized model achieved an ROC of: 0.9998
from sklearn.model_selection import GridSearchCV
from sklearn import metrics
import matplotlib.pyplot as plt
from sklearn.pipeline import Pipeline
from sklearn.model_selection import KFold
from sklearn.feature_extraction.text import CountVectorizer,TfidfVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn import model_selection
from sklearn.metrics import classification_report,confusion_matrix,accuracy_score
cross_val = KFold(n_splits=3, random_state=42)
# create pipeline
pipeline = Pipeline([
('bow', CountVectorizer(strip_accents='ascii',
stop_words=['english'],# add or delete arabic based on the content of the tested df
lowercase=True)), # strings to token integer counts
('tfidf', TfidfTransformer()), # integer counts to weighted TF-IDF scores
('classifier', LogisticRegression(C=15.075475376884423,penalty="l2")), # train on TF-IDF vectors w/ Naive Bayes classifier
])
# this is where we define the values for GridSearchCV to iterate over
parameters = {'bow__ngram_range': [(1, 1), (1, 2)],
'tfidf__use_idf': (True, False),
}
clf = GridSearchCV(pipeline, param_grid=parameters, cv=cross_val, verbose=1, n_jobs=-1, scoring= 'roc_auc')
clf.fit(x_train, y_train)
test_twtr_preds = LR_Model.predict(test_twtr['processed_TEXT'])
from nltk.sentiment.vader import SentimentIntensityAnalyzer
analyser = SentimentIntensityAnalyzer()
def print_sentiment_scores(text):
snt = analyser.polarity_scores(text) #Calling the polarity analyzer
if snt["compound"] >= 0.05:
snt = "positive"
elif snt["compound"] > -0.05 and snt["compound"] < 0.05:
snt="neutral"
elif snt["compound"] <=0.05:
snt="Negative"
return snt
def_test_twtr_preds["Vader_Process"]=def_test_twtr_preds["processed_TEXT"].apply(print_sentiment_scores)
在評估任何系統的精度時,一個非常有用的元素是知道集合的大小。 超過 2000 或 3000 條推文的 70% 的准確度與超過 50 條不同。所以永遠不要忘記說出數據的大小。
另一方面,您不能期望兩種算法都給出相似的結果。 您的算法是概率分類器的一部分,而 Vader 是基於規則和基於詞典的。 這是根本的區別,所以他們永遠不會給出相似的,更不一樣的結果。
如果你想提高你的算法的精度,你必須有很好分類的詞袋。 通常,這些包是由開發人員准備的,他們對語言或影響單詞使用的文化因素沒有深入的了解。 我使用了一個基於統計方法(沒有機器學習)的簡單分類器,我在一組 3000 條推文中獲得了高達 87% 的准確率。 考慮到我的算法在不到一分鍾的時間內運行並且不需要訓練,差異是巨大的。
所以你的算法不一定是錯的,但你不能比較基於不同程序和不同數據集的系統。
建議:優先考慮為您提供最佳精度的方法。 但是如果你想改進你的方法,首先要提高你的詞袋的精度。 有鑰匙。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.