scipy库的pearsonr(x, y)的使用
生活随笔
收集整理的這篇文章主要介紹了
scipy库的pearsonr(x, y)的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
學習了皮爾遜相關系數的計算:
1 功能:計算特征與目標變量之間的相關度?
2? 輸入:x為特征,y為目標變量.
? ?輸出:r: 相關系數 [-1,1]之間,p-value: p值。 (r, p-value )
( p值越小,表示相關系數越顯著,一般p值在500個樣本以上時有較高的可靠性。)
3 代碼
import numpy as np
from scipy.stats import pearsonr
import random
np.random.seed(0)
size=300
x=np.random.normal(0,1,size)
print "Lower noise",pearsonr(x,x+np.random.normal(0,1,size))
print "Higher noise",pearsonr(x,x+np.random.normal(0,10,size))
Lower noise (0.71824836862138408, 7.3240173129983507e-49)
Higher noise (0.057964292079338155, 0.31700993885324752)
?
總結
以上是生活随笔為你收集整理的scipy库的pearsonr(x, y)的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Python】numpy库和scipy
- 下一篇: php漫画连载系统,小涴熊漫画连载系统带