Pearson Distance
Pearson Distance:
where:
1. is the covariance
2. is the standard deviation of
3. is the standard deviation of
pearson distance:
When we consider and
, then pearson distance is the vectorial angle cosine between
and
When the length of and
is 2, then
is either 1 or -1.
The corresponding python code is as follow:
from math import sqrt def pearson(v1,v2):
sum1 = sum(v1)
sum2 = sum(v2)
sum1Sq = sum([pow(v,2) for v in v1])
sum2Sq = sum([pow(v,2) for v in v2])
pSum = sum([v1[i]*v2[i] for i in range(len(v1))])
num = pSum - sum1*sum2/len(v1)
den = sqrt(sum1Sq - pow(sum1,2)/len(v1))*sqrt(sum2Sq - pow(sum2,2)/len(v2))
if den == 0: return 1.0
return num/den
Pearson Distance的更多相关文章
- 转:Python K-means代码
#coding: UTF-8 import pearson_distance from pearson_distance import pearson_distance from math impor ...
- 推荐算法——距离算法
本文内容 用户评分表 曼哈顿(Manhattan)距离 欧式(Euclidean)距离 余弦相似度(cos simliarity) 推荐算法以及数据挖掘算法,计算"距离"是必须的~ ...
- 相似性 similarity | Pearson | Spearman | p-value | 相关性 correlation | 距离 distance | distance measure
这几个概念不能混淆,估计大部分人都没有完全搞懂这几个概念. 看下这个,非常有用:Interpret the key results for Correlation euclidean | maximu ...
- 相似性度量(Similarity Measurement)与“距离”(Distance)
在做分类时常常需要估算不同样本之间的相似性度量(Similarity Measurement),这时通常采用的方法就是计算样本间的“距离”(Distance).采用什么样的方法计算距离是很讲究,甚至关 ...
- Chi Square Distance
The chi squared distance d(x,y) is, as you already know, a distance between two histograms x=[x_1,.. ...
- Scipy教程 - 距离计算库scipy.spatial.distance
http://blog.csdn.net/pipisorry/article/details/48814183 在scipy.spatial中最重要的模块应该就是距离计算模块distance了. fr ...
- 相似度度量:欧氏距离与余弦相似度(Similarity Measurement Euclidean Distance Cosine Similarity)
在<机器学习---文本特征提取之词袋模型(Machine Learning Text Feature Extraction Bag of Words)>一文中,我们通过计算文本特征向量之间 ...
- [LeetCode] Total Hamming Distance 全部汉明距离
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- [LeetCode] Hamming Distance 汉明距离
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
随机推荐
- Linux环境下部署SpringBoot项目
1.在pom文件中添加maven插件 <build> <plugins> <plugin> <groupid>org.springframework.b ...
- Linux下ELK环境搭建
一.准备工作 准备3台机器,这样才能完成分布式集群的实验,当然能有更多机器更好: 192.168.3.64(e1) 192.168.3.62 (e2) 192.168.3.63(e3) 角色划分: ...
- android学习:关于RelativeLayout叠放布局的问题
RelativeLayout布局关于元素叠加的问题 1.RelativeLayout布局中的元素如果要实现元素叠加必须设置 RelativeLayout.ALIGN_PARENT_TOP 这样元素 ...
- Vue聊天框默认滚动到底部
功能场景 在开发中,我们总能遇到某些场景需要运用到聊天框,比如客服对话.如果你不是一名开发人员,可能你在使用QQ或者聊天工具的时候并没有注意到,当你发出一条消息的时候,窗体会默认滚动到最底部,让用户可 ...
- IDEA导入eclipse项目并部署到tomcat
1.首先引入本地项目 我这里是maven项目就直接选择的以maven项目引入,如果选eclipse的话,pom文件不会被初始化,部署tomcat会出问题 这项选完后,就一路next,jdk可以在引入的 ...
- JS变量、作用域、内存
写到这个题目<JS变量.作用域,内存>,我就不由自主想起了黄金三嫖客.可能是名字有点像,嗯,一定是这样子的! JS接触下来,应该是要比Java简单不少的,所以,要学好啊.立个flag半年后 ...
- Call to a member function allowField() on null 错误总结
Call to a member function allowField() on null 在空对象上调用 allowField() 没有该模型对象无法调用,需要创建相应的模型 错误版本: if ...
- Flume(1)-概述与组成架构
一. 定义 Flume是Cloudera提供的一个高可用的,高可靠的,分布式的海量日志采集.聚合和传输的系统.Flume基于流式架构,灵活简单. 二. 优点 1. 可以和任意集中式存储进程集成. 2. ...
- usb驱动之打印usb设备信息(二)
以下是打印鼠标左右键及其他输入的源代码,详细说明见https://www.cnblogs.com/zhu-g5may/p/9309381.html /*参考/drivers/hid/usbhid/us ...
- 20155207 2016-2017-2《Java程序设计》课程总结
20155207 2016-2017-2<Java程序设计>课程总结 每周作业链接汇总: 预备作业一:一路风景---我期待的是师生关系 预备作业二:学习情况的相关调查 预备作业三:安装虚拟 ...