程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Pearson correlation coefficient python implementation

編輯:Python

皮爾遜pearsonCorrelation coefficient and Spearmanspearman等級相關系數.
They can be used to measure the magnitude of the correlation between two variables

Population data and sample data

1. 總體:All the individuals of the object to be examined are called the totality
(我國10The data obtained from the annual census is the overall data)
2. 樣本:從總體中所抽取的一部分個體叫做總體的一個樣本
(在QQThe data obtained by sending out the questionnaires and asking students to help them fill in are the sample data)

  • ps:We always want to get some characteristics of the overall data,For example mean and variance etc,But most of the data we are exposed to is sample data,So we need to use the statistic of the sample to estimate the statistic of the population
  • For example using the sample mean、The sample standard deviation is used to estimate the mean of the population(平均水平)and the overall standard deviation(偏離程度).

總體Pearson相關系數

樣本Pearson相關系數

PearsonSeveral errors in coefficients

基於python的PearsonCorrelation coefficients are implemented

import pandas as pd
data = pd.read_excel('八年級女生體測數據.xlsx')
data.corr() # 計算相關性系數

運行結果:

## Correlation coefficient heatmap
import seaborn as sns
import matplotlib.pyplot as plt
corr = data.corr()
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] =False #減號unicode編碼
ax = plt.subplots(figsize=(20, 16))#調整畫布大小
ax = sns.heatmap(corr, vmax=.8, square=True, annot=True)#畫熱力圖 annot=True Indicates display coefficient
# 設置刻度字體大小
plt.xticks(fontsize=13)
plt.yticks(fontsize=13)

運行結果:

pearsonHypothesis testing for correlation coefficients

檢驗步驟

pearsonThe conditions for the correlation coefficient hypothesis test


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved