zoukankan      html  css  js  c++  java
  • 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:

     
ho_{X,Y}={mathrm{cov}(X,Y) over sigma_X sigma_Y} ={E[(X-mu_X)(Y-mu_Y)] over sigma_Xsigma_Y}

    where,  mathrm{cov}  is the covariance sigma_X  is the standard deviation of  X  mu_X  is the mean of  X , and  E  is the expectation.

     适合计算机运行的公式:

    Alternative formulae for the sample Pearson correlation coefficient are also available:

    
r_{xy}=frac{sum x_iy_i-n ar{x} ar{y}}{(n-1) s_x s_y}=frac{nsum x_iy_i-sum x_isum y_i}
{sqrt{nsum x_i^2-(sum x_i)^2}~sqrt{nsum y_i^2-(sum y_i)^2}}.

    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 X_i, Y_i are converted to ranks x_i, y_i, and ρ is computed from:

     
ho = {1- frac {6 sum d_i^2}{n(n^2 - 1)}}.

    where d_i = x_i - y_i, is the difference between ranks


    示例[编辑]

    在此例中,我们要使用下表所给出的原始数据计算一个人的 智商和其每周花在 电视上的小时数的相关性。

    智商X_i每周花在电视上的小时数, Y_i
    1067
    860
    10027
    10150
    9928
    10329
    9720
    11312
    1126
    11017

    首先,我们必须根据以下步骤计算出 d^2_i,如下表所示。

    1. 排列第一列数据 (X_i)。 创建新列 x_i 并赋以等级值 1,2,3,...n
    2. 然后,排列第二列数据 (Y_i). 创建第四列 y_i 并相似地赋以等级值 1,2,3,...n
    3. 创建第五列 d_i 保存两个等级列的差值 (x_i 和 y_i).
    4. 创建最后一列 d^2_i 保存 d_i 的平方.
    智商, X_i每周花在电视上的小时数, Y_i等级 x_i等级 y_id_id^2_i
    8601100
    972026−416
    992838−525
    1002747−39
    10150510−525
    1032969−39
    106773416
    110178539
    112692749
    11312104636

    根据 d^2_i 计算 sum d_i^2 = 194。 样本容量n为 10。 将这些值带入方程

     
ho = 1- {frac {6	imes194}{10(10^2 - 1)}}

    得 ρ = −0.175757575...


     







  • 相关阅读:
    远程仓库拉取项目到本地并修改提交
    Django之URLconf路由
    Django简介以及安装
    Web开发介绍
    Python与MySQL数据库连接
    PyCharm快捷键
    python爬取有道翻译
    Vue相关知识总结
    Ajax相关介绍
    CSS中的定位
  • 原文地址:https://www.cnblogs.com/zwCHAN/p/4265729.html
Copyright © 2011-2022 走看看