TfidfVectorizer的词汇和get_features()之间的区别?

TfidfVectorizer的词汇和get_features()之间的区别?,第1张

TfidfVectorizer的词汇和get_features()之间的区别?

属性 vocabulary__ 输出一个字典,其中所有ngram是字典关键字,而各个值是tfidf矩阵中每个ngram(特征)的列位置。方法
_get_feature_names()

输出一个列表,其中的ngrams根据每个要素的列位置出现。因此,您可以使用任一方法来确定哪个tfidf列对应于哪个功能。在下面的示例中,使用get_feature_names()的输出来命名列,可以轻松地将tfidf矩阵转换为熊猫数据帧。还要注意,所有值的权重均相等,并且所有权重的平方和等于1。

singleTFIDF.vocabulary_Out[41]: {'this': 5, 'is': 1, 'simple': 3, 'example': 0, 'this is': 6, 'is simple': 2, 'simple example': 4}singleTFIDF.get_feature_names()Out[42]: ['example', 'is', 'is simple', 'simple', 'simple example', 'this', 'this is']import pandas as pddf = pd.Dataframe(single.toarray(), columns=singleTFIDF.get_feature_names())dfOut[48]:     example        is  is simple    simple  simple example      this   this is0  0.377964  0.377964   0.377964  0.377964        0.377964  0.377964  0.377964


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5663747.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存