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的更多相关文章

  1. 转:Python K-means代码

    #coding: UTF-8 import pearson_distance from pearson_distance import pearson_distance from math impor ...

  2. 推荐算法——距离算法

    本文内容 用户评分表 曼哈顿(Manhattan)距离 欧式(Euclidean)距离 余弦相似度(cos simliarity) 推荐算法以及数据挖掘算法,计算"距离"是必须的~ ...

  3. 相似性 similarity | Pearson | Spearman | p-value | 相关性 correlation | 距离 distance | distance measure

    这几个概念不能混淆,估计大部分人都没有完全搞懂这几个概念. 看下这个,非常有用:Interpret the key results for Correlation euclidean | maximu ...

  4. 相似性度量(Similarity Measurement)与“距离”(Distance)

    在做分类时常常需要估算不同样本之间的相似性度量(Similarity Measurement),这时通常采用的方法就是计算样本间的“距离”(Distance).采用什么样的方法计算距离是很讲究,甚至关 ...

  5. Chi Square Distance

    The chi squared distance d(x,y) is, as you already know, a distance between two histograms x=[x_1,.. ...

  6. Scipy教程 - 距离计算库scipy.spatial.distance

    http://blog.csdn.net/pipisorry/article/details/48814183 在scipy.spatial中最重要的模块应该就是距离计算模块distance了. fr ...

  7. 相似度度量:欧氏距离与余弦相似度(Similarity Measurement Euclidean Distance Cosine Similarity)

    在<机器学习---文本特征提取之词袋模型(Machine Learning Text Feature Extraction Bag of Words)>一文中,我们通过计算文本特征向量之间 ...

  8. [LeetCode] Total Hamming Distance 全部汉明距离

    The Hamming distance between two integers is the number of positions at which the corresponding bits ...

  9. [LeetCode] Hamming Distance 汉明距离

    The Hamming distance between two integers is the number of positions at which the corresponding bits ...

随机推荐

  1. 【算法学习】AVL平衡二叉搜索树原理及各项操作编程实现(C语言)

    #include<stdio.h> #include "fatal.h" struct AvlNode; typedef struct AvlNode *Positio ...

  2. 接入Gobelieve IM开发平台的DEMO代码

    接入Gobelieve IM开发平台的DEMO代码, 请求头部: Authorization: Basic $base64(appid:$hex_md5(appsecret))意思是 appsecre ...

  3. ubuntu下面显示隐藏文件快捷键

    ubuntu下面显示隐藏文件快捷键 ctrl + H这个快捷键可以在ubuntu系统下显示隐藏的文件夹和文件

  4. Ansible常用功能

    Ansible 是近几年十分流行的DevOps工具架构什么的我就不在这里赘述了,网上一找一堆 这里写点我在ansible常用功能 1.命令串 #copy文件 #ansible host文件中的主机组 ...

  5. MySQL的库表详细操作

    MySQL数据库 本节目录 一 库操作 二 表操作 三 行操作 一 库操作 1.创建数据库 1.1 语法 CREATE DATABASE 数据库名 charset utf8; 1.2 数据库命名规则 ...

  6. vue中点击添加class,双击去掉class

    VUE中 html 中 <ul id="shoppingList" v-on:click="addClass($event)" class="i ...

  7. hive表查询中文显示乱码

    hive在查询表信息时,中文显示乱码,数字或者url显现null问题解决思路. 1.确定create hive表时指定的row format delimited fields terminated b ...

  8. python获取网页编码问题(encoding和apparent_encoding)

    在requests获取网页的编码格式时,有两种方式,而结果也不同,通常用apparent_encoding更合适 注:推荐一个大佬写的关于获取网页编码格式以及requests中text()和conte ...

  9. XAMPP之Mysql启动失败

    启动XAMPP中的Mysql出现如下: 可能的原因是本地有多个MySQL,所以要在注册表编辑器中将imagePath改成XAMPP中的mysql的地址.(打开注册表编辑器:win+R,输入regedi ...

  10. (数据科学学习手札47)基于Python的网络数据采集实战(2)

    一.简介 马上大四了,最近在暑期实习,在数据挖掘的主业之外,也帮助同事做了很多网络数据采集的内容,接下来的数篇文章就将一一罗列出来,来续写几个月前开的这个网络数据采集实战的坑. 二.马蜂窝评论数据采集 ...