博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Cosine Similarity
阅读量:4683 次
发布时间:2019-06-09

本文共 747 字,大约阅读时间需要 2 分钟。

http://blog.christianperone.com/2013/09/machine-learning-cosine-similarity-for-vector-space-models-part-iii/

 

documents = ("The sky is blue","The sun is bright","The sun in the sky is bright","We can see the shining sun, the bright sun")from sklearn.feature_extraction.text import TfidfVectorizertfidf_vectorizer = TfidfVectorizer()tfidf_matrix = tfidf_vectorizer.fit_transform(documents)# print tfidf_matrixfrom sklearn.metrics.pairwise import cosine_similarityprint cosine_similarity(tfidf_matrix[0], tfidf_matrix)import math# This was already calculated on the previous step, so we just use the valuecos_sim = 0.52305744angle_in_radians = math.acos(cos_sim)print math.degrees(angle_in_radians)

  

转载于:https://www.cnblogs.com/gwnbu/p/7222942.html

你可能感兴趣的文章
你在哪编程?你的程序原料是什么?
查看>>
ehcache 简介
查看>>
java uuid 例子
查看>>
linux zip 压缩密码
查看>>
【SICP练习】26 练习1.32
查看>>
Centos下安装破解Jira7的操作记录
查看>>
Python AES_ECB_PKCS5加密代码
查看>>
SpringBoot--外部配置
查看>>
C#中的线程三 (结合ProgressBar学习Control.BeginInvoke)
查看>>
sqlserver工作日常使用sql--持续完善中
查看>>
文件I/O与标准I/O
查看>>
大数据学习之路(持续更新中...)
查看>>
项目开发总结报告(GB8567——88)
查看>>
enumerate使用
查看>>
BZOJ1930: [Shoi2003]pacman 吃豆豆
查看>>
SSH加固
查看>>
端口扫描base
查看>>
iOS IM开发的一些开源、框架和教程等资料
查看>>
FansUnion:共同写博客计划终究还是“流产”了
查看>>
python 二维字典
查看>>