gpt4 book ai didi

python - 我应该如何使用 scikit learn 对以下列表列表进行矢量化?

转载 作者:太空狗 更新时间:2023-10-29 20:42:11 27 4
gpt4 key购买 nike

我想用 scikit 学习一个有列表的列表。我去了我阅读培训文本的路径,然后我得到了这样的东西:

corpus = [["this is spam, 'SPAM'"],["this is ham, 'HAM'"],["this is nothing, 'NOTHING'"]]

from sklearn.feature_extraction.text import CountVectorizer
vect = CountVectorizer(analyzer='word')
vect_representation= vect.fit_transform(corpus)
print vect_representation.toarray()

我得到以下信息:

return lambda x: strip_accents(x.lower())
AttributeError: 'list' object has no attribute 'lower'

还有一个问题是每个文档末尾的标签,我应该如何处理它们才能进行正确的分类?

最佳答案

对于 future 的每个人来说,这解决了我的问题:

corpus = [["this is spam, 'SPAM'"],["this is ham, 'HAM'"],["this is nothing, 'NOTHING'"]]

from sklearn.feature_extraction.text import CountVectorizer
bag_of_words = CountVectorizer(tokenizer=lambda doc: doc, lowercase=False).fit_transform(splited_labels_from_corpus)

这是我使用 .toarray() 函数时的输出:

[[0 0 1]
[1 0 0]
[0 1 0]]

谢谢大家

关于python - 我应该如何使用 scikit learn 对以下列表列表进行矢量化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27673527/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com