from sklearn.feature_extraction.text import TfIDfVectorizermyvocabulary = ['life','learning']corpus = {1: "The game of life is a game of everlasting learning",2: "The unexamined life is not worth living",3: "Never stop learning"}tfIDf = TfIDfVectorizer(vocabulary = myvocabulary,ngram_range = (1,3))tfs = tfIDf.fit_transform(corpus.values())
现在我想在矩阵中查看我计算的tf-IDf分数,如下所示.
我尝试按如下方式进行.
IDf = tfIDf.IDf_dic = dict(zip(tfIDf.get_feature_names(),IDf))print(dic)
但是,我得到如下输出.
{'life': 1.2876820724517808,'learning': 1.2876820724517808}
请帮我.
解决方法 感谢σηγ,我可以从 this question找到答案feature_names = tfIDf.get_feature_names()corpus_index = [n for n in corpus]import pandas as pddf = pd.DataFrame(tfs.T.todense(),index=feature_names,columns=corpus_index)print(df)总结
以上是内存溢出为你收集整理的如何在python中的sklearn中打印tf-idf得分矩阵全部内容,希望文章能够帮你解决如何在python中的sklearn中打印tf-idf得分矩阵所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)