Python TfidfVectorizer:使用值获取要素名称的顶部目录

Python TfidfVectorizer:使用值获取要素名称的顶部目录,python,dictionary,scikit-learn,nlp,text-mining,Python,Dictionary,Scikit Learn,Nlp,Text Mining,这是我的数据 xtra是字符串评论的列表 xtra[1] >> 'order monitor want makeshift area powerful old laptop take box impressed size screen wide sturdy fear wobble testing hdmi vga good selection use hdmi turn image gorgeous ip definitely make fhd shine image vivid

这是我的数据

xtra是字符串评论的列表

xtra[1]
>> 'order monitor want makeshift area powerful old laptop take box impressed size screen wide sturdy fear wobble testing hdmi vga good selection use hdmi turn image gorgeous ip definitely make fhd shine image vivid movie amazing plenty room window great   till switch sound laptop monitor drop ball sound monitor laptop hear barely turn sound laptop hear not know money screen decide speaker minute decision plan monitor tower pc external speaker default monitor speaker mediocre look replacement monitor low price ips screen productivityworksome gaming screen suggest look monitor minimum fuss sortof recommend easy setup strongly advise external speaker order enjoy sound hook monitor'
yva是1.0到5.0之间的分数列表(浮动)

在这里,我使用列车测试分割

xtrain, xvalid, ytrain, yvalid = train_test_split(xtra, yva, 
                                              stratify=yva, 
                                              random_state=0, 
                                              test_size=0.33, shuffle=True)
然后是矢量器

tfv = TfidfVectorizer(min_df=3,  max_features=None, 
        strip_accents='unicode', analyzer='word',token_pattern=r'\w{1,}',
        ngram_range=(1, 1), use_idf=1,smooth_idf=1,sublinear_tf=1, 
     )

# Fitting TF-IDF to both training and test sets (semi-supervised learning)
tfv.fit((xtrain) + (xvalid))
xtrain_tfv =  tfv.transform(xtrain) 
xvalid_tfv = tfv.transform(xvalid)
idf = tfv.idf_
features_name= (dict(zip(tfv.get_feature_names(), idf)))
sorted_scores = sorted(features_name.items, key= operator.itemgetter(1), reverse=True)
for item in sorted_scores:
    print ("{} Score: {}".format(item[0], item[1]))
我收到的错误

 ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-112-c215b51ed9ad> in <module>
     10 idf = tfv.idf_
     11 features_name= (dict(zip(tfv.get_feature_names(), idf)))
---> 12 sorted_scores = sorted(features_name.items, key= operator.itemgetter(1), reverse=True)
     13 for item in sorted_scores:
     14     print ("{} Score: {}".format(item[0], item[1]))

TypeError: 'builtin_function_or_method' object is not iterable

我有没有做错什么,或者有没有更好的方法来解决这个问题?

什么是
操作符
?这是一个python模块,我发现一个人习惯于得到我想要的答案。什么是
操作符
?这是一个python模块,我发现一个人习惯于得到我想要的答案。
 ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-112-c215b51ed9ad> in <module>
     10 idf = tfv.idf_
     11 features_name= (dict(zip(tfv.get_feature_names(), idf)))
---> 12 sorted_scores = sorted(features_name.items, key= operator.itemgetter(1), reverse=True)
     13 for item in sorted_scores:
     14     print ("{} Score: {}".format(item[0], item[1]))

TypeError: 'builtin_function_or_method' object is not iterable
machine  Score: 0.513720
learning Score: 0.513720
about    Score: 0.256860
subject  Score: 0.256860
phd      Score: 0.256860
and      Score: 0.256860
my       Score: 0.256860
is       Score: 0.256860
reading  Score: 0.195349