当前位置:   article > 正文

【机器学习】读取txt文本内容计算TF-IDF值,算法,python_对txt或者csv格式的数据进行tf-idf分析

对txt或者csv格式的数据进行tf-idf分析

Sklearn库的学习之TF-IDF算法:

  1. # coding:utf-8
  2. import jieba
  3. import jieba.posseg as pseg
  4. import os
  5. import sys
  6. from sklearn import feature_extraction
  7. from sklearn.feature_extraction.text import TfidfTransformer
  8. from sklearn.feature_extraction.text import CountVectorizer
  9. one = open(r'one.txt',encoding = "utf-8")
  10. onee = list(one)
  11. two = open(r'two.txt',encoding = "utf-8")
  12. twoo = list(two)
  13. three = open(r'three.txt',encoding = "utf-8")
  14. threee = list(three)
  15. four = open(r'four.txt',encoding = "utf-8")
  16. fourr = list(four)
  17. five = open(r'five.txt',encoding = "utf-8")
  18. fivee = list(five)
  19. six = open(r'six.txt',encoding = "utf-8")
  20. sixx = list(six)
  21. one.close()
  22. two.close()
  23. three.close()
  24. if __name__ == "__main__":
  25. corpus= onee + twoo + threee + fourr + fivee 
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/743983
推荐阅读
相关标签
  

闽ICP备14008679号