TF IDF算法示例代码
# TF-IDF算法示例 # 0.引入依赖 import numpy as np import pandas as pd import math # 1.定义数据和预处理 docA = The cat sat on my bed docB = The dog sat on my knees bowA = docA.split( ) bowB = docB.split( ) # print(bowA, bowB) # 构建词库 wordSet = set(bowA).union(bowB) # print(wordSet) # 2.进行词数统计 # 用统计字典来保存词出现的次数
用户评论