GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pythonForMachineLearning/PearsonCorrelationCoefficient.py at master · daacheng/pythonForMachineLearning

Expand file tree

/

PearsonCorrelationCoefficient.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
41 lines (36 loc) · 1.06 KB
/

PearsonCorrelationCoefficient.py

Copy path

File metadata and controls

41 lines (36 loc) · 1.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import numpy as np
import math
#皮尔逊相关系数
def getPearson(x,y):
xBar=np.mean(x)
yBar=np.mean(y)
fenzi=0
fenmu=0
x_2=0
y_2=0
for i in range(len(x)):
x_=x[i]-xBar
y_=y[i]-yBar
fenzi+=x_*y_
x_2+=x_**2
y_2+=y_**2
fenmu=math.sqrt(x_2*y_2)
return fenzi/fenmu
#多元线性回归的R平方值(相关系数) degree参数只X的次方
def polyfit(x,y,degree):
result={}
coeffs=np.polyfit(x,y,degree)#np的方法直接求得线性相关的系数[b0,b1……bn]
result['polynomial']=coeffs.tolist()
p=np.poly1d(coeffs)#p=2.657 x + 5.322 预估的直线
yhat=p(x)#y的预估值
y_=np.mean(y)
ssr=np.sum((yhat-y_)**2)
sst=np.sum((y-y_)**2)
result['determination']=ssr/sst
return result
x=[1,3,8,7,9]
y=[10,12,24,21,34]
#p=getPearson(x,y)
#print(p)#皮尔逊相关系数:衡量两个值线性相关强度的量
#print(p**2)#简单线性回归的R平方值 决定系数 反应因变量的全部变异能通过回归关系被自变量解释的比例
polyfit(x,y,1)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.