【发布时间】:2018-11-15 01:59:59
【问题描述】:
我想构建一个分类文本的算法:火腿或垃圾邮件;我有每个文本类别的训练/测试数据。 (我的火车数据对于每个类别都有8000 sentences,对于测试每个类别都包含2000 sentences)
X_train 看起来像这样['please, call me asap!', 'watch out the new sales!', 'hello jim can we talk?', 'only today you can buy this', 'don't miss our offer!']
y_train 看起来像这样 [1 0 1 0 0] 其中 1 = 火腿,0 = 垃圾邮件
与 X_test 和 y_test 相同。
这是我的代码的 sn-p:
# classifier can be LogisticRegression, MultinomialNB, RandomForest, DecisionTree
text_clf = Pipeline([('vect', CountVectorizer()),
('tfidf', TfidfTransformer()),
('clf', classifier),
])
model = text_clf.fit(X_train, y_train)
y_predict = model.predict(X_test)
这些是我测量的参数:
print(accuracy_score(y_test, y_predict))
print(f1_score(y_test, y_predict, average="weighted"))
print(recall_score(y_test, y_predict, pos_label=1, average="binary"))
print(precision_score(y_test, y_predict, average="weighted"))
如果我不使用任何优化 (remove stop words, remove punctuation, stem words, lemmatize words),我会在每个参数中获得大约 95% 的结果。如果我使用这些优化,准确率、f1 分数和精度会急剧下降到 50-60%。召回函数保持在 95% 不变。
为什么会这样?我错在哪里?我是否正确计算了这些参数?还是这是正常行为?
【问题讨论】:
-
通常“优化”意味着用一件事换另一件事,例如训练速度的准确性。你期待什么?
-
如果我打电话给他们
features,你会试着告诉我为什么会有这种行为吗? -
我会尝试一次添加一个优化,看看它们的效果是什么。如果有特定的原因导致了这种行为,请查看它在做什么。
-
我一个接一个地添加,得到的结果相同。他们每个人都会减少这些参数。
-
请用数据集添加完整的代码(优化和不优化)。
标签: python machine-learning classification text-classification