【问题标题】:Evaluate Machine Learning Text Classifier评估机器学习文本分类器
【发布时间】:2020-02-08 09:43:47
【问题描述】:

我已经构建了一个二进制文本分类器。训练它根据“新”或“返回”为客户识别句子。我的问题是,真实数据可能并不总是在新数据或返回数据之间有明显的区别,即使对于阅读句子的实际人也是如此。 通过使用逻辑回归的监督学习,我的模型被训练到 0.99% 的准确率。

#train model
def train_model(classifier, feature_vector_train, label, feature_vector_valid,valid_y, is_neural_net=False):
    classifier.fit(feature_vector_train, label)
    predictions = classifier.predict(feature_vector_valid)
    if is_neural_net:
        predictions = predictions.argmax(axis=-1)
    return classifier , metrics.accuracy_score(predictions, valid_y)

# Linear Classifier on Count Vectors
    model, accuracy = train_model(linear_model.LogisticRegression(), xtrain_count, train_y, xtest_count,test_y)
    print (':::  Accuracy on Test Set   :::')
    print ('Linear Classifier, BoW Vectors: ', accuracy)

这会给我一个 0.998 的准确度。 我现在可以传递一个完整的句子列表来测试这个模型,如果句子有 newreturn 单词,它会捕捉到,但我需要一个评估指标,因为有些句子会没有机会成为新的回归,因为真实数据一如既往的混乱。

我的问题是:我可以使用哪些评估指标,以便通过模型的每个新句子都显示一个分数? 现在我只使用以下代码

with open('realdata.txt', 'r') as f:
    samples = f.readlines()
vecs = count_vect.transform(sentence)
visit = model.predict(vecs)
num_to_label= {0:'New', 1:'Return'}
for s, p in zip(sentence, visit):
    #printing each sentence with the predicted label
    print(s + num_to_label[p])

例如我希望

Sentence                      Visit          (Metric X)
New visit 2nd floor           New             0.95
Return visit Evening          Return          0.98
Afternoon visit North         New             0.43

因此,我知道相信低于某个百分比的意志指标,因为该工具不可靠。

【问题讨论】:

  • 人工贴标者似乎需要 3 个类别:新的、返回的和未指定的。为什么不做一个三类分类器?
  • @SamH。你将如何训练未指定的数据?只添加与 new 或 return 无关的随机数据?
  • 理想情况下,我会重新标记一些现有数据。在您给出的示例中,“下午访问北部”我将标记为“未指定”

标签: python nlp logistic-regression text-classification


【解决方案1】:

您可以使用 predict_proba() 代替 predict()。这将为您提供对每个可能标签的预测的概率估计。

https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html

【讨论】:

    猜你喜欢
    • 2013-05-08
    • 1970-01-01
    • 2016-10-13
    • 2017-03-01
    • 2015-01-16
    • 1970-01-01
    • 2021-06-17
    • 2017-07-01
    • 2020-05-04
    相关资源
    最近更新 更多