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 ...
随机推荐
- sharepoint rest 脚本发送邮件
function processSendEmails() { var from = 'asad@Example.com', to = 'someone@Example.com', body = 'He ...
- kafka restful api功能介绍与使用
前述 采用confluent kafka-rest proxy实现kafka restful service时候(具体参考上一篇笔记),通过http协议数据传输,需要注意的是采用了base64编码(或 ...
- 直接在apk中添加资源的研究
原文 http://blog.votzone.com/2018/05/12/apk-merge.html 之前接手过一个sdk的开发工作,在开发过程中有一个很重要的点就是尽量使用代码来创建控件,资源文 ...
- CentOS 7紧急救援模式修改root用户密码的方法
最近无聊在网上搜索linux系统root用户密码破解方法,看来很多朋友的博文,同时也试了一下,但是感觉他们写的还是不是很清晰.简洁,因此自己就心血来潮写了这篇博文,提供一个比较清晰的思路给新手,如果有 ...
- css动画Demo---水波动画和边框动画
先上效果图: 水波动画: 边框动画: 1.水波动画 实现代码 <!DOCTYPE html> <html lang="en"> <head> & ...
- 课时87. !important(掌握)
1.什么是important 作用:用于提升某个直接选中标签的选择器中的某个属性的优先级,可以将被指定的属性的优先级提升为最高. 注意点: 1.important只能用于直接选中,不能用于间接选中 p ...
- day 34线程的其他方法,线程池
线程的其他方法: from threading import Thread,current_thread: currrent_thread().getName() 获取线程的名称 current_ ...
- Python实现注册和三次验证登录
# 帐户表account:# sylar:123# alex:456# wusir:789# taibai:789# 需熟练的知识点:文件操作with open()/write()/read().去掉 ...
- 20155232 2016-2017-2 《Java程序设计》第1周学习总结
20155232 2016-2017-2 <Java程序设计>第1周学习总结 认真学习考核方式,理解成绩构成 100分构成: 翻转课堂考核12次(60分) 实验5次(15分) 团队项目(2 ...
- 20155234 2016-2017-2第十周《Java学习笔记》学习总结
20155234第十周<Java学习笔记>学习总结 教材学习内容总结 网络编程 在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事情就是把数据发送到指定的位置,或者接收到指定 ...