【发布时间】:2017-08-30 05:09:57
【问题描述】:
我正在尝试训练一个朴素贝叶斯分类器,但我遇到了数据问题。我打算用它来提取文本摘要。
Example_Input: It was a sunny day. The weather was nice and the birds were singing.
Example_Output: The weather was nice and the birds were singing.
我有一个我打算使用的数据集,并且在每个文档中至少有 1 个句子用于摘要。
我决定使用 sklearn,但我不知道如何表示我拥有的数据。即X和y。
from sklearn.naive_bayes import MultinomialNB
clf = MultinomialNB().fit(X, y)
最接近我的想法是把它做成这样:
X = [
'It was a sunny day. The weather was nice and the birds were singing.',
'I like trains. Hi, again.'
]
y = [
[0,1],
[1,0]
]
其中目标值表示 1 - 包含在摘要中,0 - 不包含。不幸的是,这会产生不良形状异常,因为 y 预计是一维数组。我想不出一种表示它的方式,所以请帮忙。
顺便说一句,我不直接使用X 中的字符串值,而是使用来自sklearn 的CountVectorizer 和TfidfTransformer 将它们表示为向量。
【问题讨论】:
标签: python machine-learning scikit-learn naivebayes