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 ...
随机推荐
- PE下安装官方WIN7
进入PE后,用虚拟光驱 加载 win*.iso 文件后,运行安装程序setup.exe. 开始安装:
- iOS TabBarItem设置红点(未读消息)
实现原理: 其实是自定义一个view,将view添加到UITabBar上面,也可以是一个按钮,设置背景图片,和label.废话少说直接上代码搞一个UITabBar的分类 #import <UIK ...
- oracle10g学习笔记
1.简介 1.1.sql:Structured Query Language 结构化查询语言 1.2.windows在目录路径中使用反斜线\,unix和linux使用正斜线/ 1.3.Number(a ...
- 实施erp的建议
纺织行业实施ERP建议 (一)企业各层面应提高对ERP的认识 ERP项目的实施范围横跨企业的每一个部门,在实施过程中需要调动各个部门的资源,这首先需要企业领导者高度重视,从实施的各个环节给予支持:其次 ...
- Linux基础-2.目录文件的浏览、管理及维护
1.Linux文件系统的层次结构 1)了解Linux文件系统的树状结构: 在Linux或UNIX操作系统中,所有的文件和目录都被组织成一个以根节点开始的倒置树状结构 2)掌握目录的定义:目录相当于Wi ...
- js 实现内容的展开和收缩
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Vue使用moment.js处理前端时间格式问题
使用moment.js处理格式显示问题: 1.首先引入moment.js插件 npm install moment --save 2.入口文件main.js中导入并使用 3.在项目中使用即可:data ...
- less.js插件监听
<script>less.watch();</script> 在不手动刷新/重新加载页面会自动监听less的变化,页面做出相应的变化 . 写在这两行后面就好 了 <lin ...
- hadoop生态搭建(3节点)
软件:CentOS-7 VMware12 SSHSecureShellClient shell工具:Xshell 规划 vm网络配置 01.基础配置 02.ssh配置 03.zookeep ...
- Zeta--S3 Linux抓取一帧YUV图像后使用硬件编码器编码成H.264
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <getopt.h&g ...