栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/661791.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号