
正文
spark MLlib 概念 1:相关系数( PPMCC or PCC or Pearson's r皮尔森相关系数) and Spearman's correlation(史匹曼等级相关系数)
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
皮尔森相关系数定义: 协方差与标准差乘积的商。
Pearson's correlation coefficient when applied to a population is commonly represented by the Greek letter ρ (rho) and may be referred to as the population correlation coefficient or the population Pearson correlation coefficient. The formula for ρ is:
where,
is the covariance,
is the standard deviation of
,
is the mean of
, and
is the expectation.
适合计算机运行的公式:
Alternative formulae for the sample Pearson correlation coefficient are also available:
The above formula suggests a convenient single-pass algorithm for calculating sample correlations, but, depending on the numbers involved, it can sometimes benumerically unstable.
数学意义:
描述两个变量X, Y的线性相关性,且不随变量的平移而改变。范围 [-1,1],当X,Y协变时大于0,逆变时小于0. 线性无关时等于0.
Spearman's rank correlation coefficient分析两个变量的一致性程度。定义:For a sample of size n, the n raw scores
are converted to ranks
, and ρ is computed from:

where
, is the difference between ranks
示例[编辑]
在此例中,我们要使用下表所给出的原始数据计算一个人的 智商和其每周花在 电视上的小时数的相关性。
智商, 
每周花在电视上的小时数, 
106 7 86 0 100 27 101 50 99 28 103 29 97 20 113 12 112 6 110 17
首先,我们必须根据以下步骤计算出
,如下表所示。
- 排列第一列数据 (
)。 创建新列
并赋以等级值 1,2,3,...n。 - 然后,排列第二列数据 (
). 创建第四列
并相似地赋以等级值 1,2,3,...n。 - 创建第五列
保存两个等级列的差值 (
和
). - 创建最后一列
保存
的平方.
智商, 
每周花在电视上的小时数, 
等级 
等级 


86 0 1 1 0 0 97 20 2 6 −4 16 99 28 3 8 −5 25 100 27 4 7 −3 9 101 50 5 10 −5 25 103 29 6 9 −3 9 106 7 7 3 4 16 110 17 8 5 3 9 112 6 9 2 7 49 113 12 10 4 6 36
根据
计算
。 样本容量n为 10。 将这些值带入方程

得 ρ = −0.175757575...
来源: <http://zh.wikipedia.org/wiki/%E6%96%AF%E7%9A%AE%E5%B0%94%E6%9B%BC%E7%AD%89%E7%BA%A7%E7%9B%B8%E5%85%B3%E7%B3%BB%E6%95%B0>
For a sample of size n, the n raw scores
are converted to ranks
, and ρ is computed from:
where
, is the difference between ranks
示例[编辑]
在此例中,我们要使用下表所给出的原始数据计算一个人的 智商和其每周花在 电视上的小时数的相关性。
智商, ![]() | 每周花在电视上的小时数, ![]() |
| 106 | 7 |
| 86 | 0 |
| 100 | 27 |
| 101 | 50 |
| 99 | 28 |
| 103 | 29 |
| 97 | 20 |
| 113 | 12 |
| 112 | 6 |
| 110 | 17 |
首先,我们必须根据以下步骤计算出
,如下表所示。
- 排列第一列数据 (
)。 创建新列
并赋以等级值 1,2,3,...n。 - 然后,排列第二列数据 (
). 创建第四列
并相似地赋以等级值 1,2,3,...n。 - 创建第五列
保存两个等级列的差值 (
和
). - 创建最后一列
保存
的平方.
智商, ![]() | 每周花在电视上的小时数, ![]() | 等级 ![]() | 等级 ![]() | ![]() | ![]() |
| 86 | 0 | 1 | 1 | 0 | 0 |
| 97 | 20 | 2 | 6 | −4 | 16 |
| 99 | 28 | 3 | 8 | −5 | 25 |
| 100 | 27 | 4 | 7 | −3 | 9 |
| 101 | 50 | 5 | 10 | −5 | 25 |
| 103 | 29 | 6 | 9 | −3 | 9 |
| 106 | 7 | 7 | 3 | 4 | 16 |
| 110 | 17 | 8 | 5 | 3 | 9 |
| 112 | 6 | 9 | 2 | 7 | 49 |
| 113 | 12 | 10 | 4 | 6 | 36 |
根据
计算
。 样本容量n为 10。 将这些值带入方程
得 ρ = −0.175757575...
来源: <http://zh.wikipedia.org/wiki/%E6%96%AF%E7%9A%AE%E5%B0%94%E6%9B%BC%E7%AD%89%E7%BA%A7%E7%9B%B8%E5%85%B3%E7%B3%BB%E6%95%B0>

来自为知笔记(Wiz)









