詹惠儿

2018-12-14   阅读量: 811

数据分析师 Python编程 Python爬虫

如何比较两个单词的相似性指数

扫码加入数据分析学习群

python中的nltk库比较任何两个单词的相似性指数

import nltk

from nltk.corpus import wordnet

# Let's compare the noun of "ship" and "boat:"

w1 = wordnet.synset('run.v.01') # v here denotes the tag verb

w2 = wordnet.synset('sprint.v.01')

print(w1.wup_similarity(w2))

w1 = wordnet.synset('ship.n.01')

w2 = wordnet.synset('boat.n.01') # n denotes noun

print(w1.wup_similarity(w2))

添加CDA认证专家【维克多阿涛】,微信号:【cdashijiazhuang】,提供数据分析指导及CDA考试秘籍。已助千人通过CDA数字化人才认证。欢迎交流,共同成长!
0.0000 0 0 关注作者 收藏

评论(0)


暂无数据

推荐课程

推荐帖子