tfidf处理代码_Python 对文档内容TFIDF处理

该博客展示了如何使用Python实现TF-IDF算法,通过一个具体的例子解释了如何对文档内容进行TF-IDF处理。查询术语'Mr. Green'在不同文档中的TF-IDF得分被计算,并显示了总体TF-IDF分数。
摘要由CSDN通过智能技术生成

CODE:

#!/usr/bin/python

# -*- coding: utf-8 -*-

'''

Created on 2014-9-8

@author: guaguastd

@name: tf_idf_sample.py

'''

from tfIdf import tf, tf_idf, idf

# Enter in a query term from the corpus variable

QUERY_TERMS = ['mr.', 'green']

corpus = \

{'a': 'Mr. Green killed Colonel Mustard in the study with the candlestick. \

Mr. Green is not a very nice fellow.',

'b': 'Professor Plum has a green plant in his study.',

'c': "Miss Scarlett watered Professor Plum's green plant while he was away \

from his office last week."}

for (k, v) in sorted(corpus.items()):

print k, ':', v

print

# Score queries by calculating cumulative tf_idf score for each term in query

q

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值