其他分享
首页 > 其他分享> > TfidfVectorizer统计词频

TfidfVectorizer统计词频

作者:互联网

from sklearn.feature_extraction.text import TfidfVectorizer
import jieba

# text = ['This is the first document.', 'This is the second second document.', 'And the third one.',
#         'Is this the first document?', ]
# 
# tf = TfidfVectorizer(min_df=1)
#
# X = tf.fit_transform(text)
# names = tf.get_feature_names()
# print(names)
# print(X.toarray())


text = '今天天气真好,我要去北京天安门玩,要去景山攻牙之后,玩完大明劫'
# 进行结巴分词,精确模式
text_list = jieba.cut(text, cut_all=False)
text_list = ",".join(text_list)
context = []
context.append(text_list)
print(context)

tf = TfidfVectorizer(min_df=1)

X = tf.fit_transform(context)
names = tf.get_feature_names()

print(names)
print(X.toarray())

标签:text,list,print,TfidfVectorizer,词频,names,tf,统计
来源: https://blog.csdn.net/YPL_ZML/article/details/93906460