量化線性關係

Python 線性建模入門

Jason Vestuto

Data Scientist

視覺化前

3 格圖:3 個散佈圖,從左到右相關性由強到零

Python 線性建模入門

單變數統計複習

# Mean
mean = sum(x)/len(x)
# Deviation, sometimes called "centering"
dx = x - np.mean(x)
# Variance
variance = np.mean(dx*dx)
# Standard Deviation
stdev = np.sqrt(variance)
Python 線性建模入門

共變異數

# Deviations of two variables
dx = x - np.mean(x)
dy = y - np.mean(y)
# Co-vary means to vary together
deviation_products = dx*dy
# Covariance as the mean
covariance = np.mean(dx*dy)
Python 線性建模入門

相關係數

# Divide deviations by standard deviation 
zx = dx/np.std(x)
zy = dy/np.std(y)
# Mean of the normalize deviations
correlation = np.mean(zx*zy)
Python 線性建模入門

正規化:前

高斯分佈圖:鐘形,不同中心、高度與寬度

Python 線性建模入門

正規化:後

高斯分佈圖:鐘形,皆以 0 為中心,高度與寬度相同

Python 線性建模入門

大小與方向

  • 相關值:-1 到 +1

6 格圖:2 列 × 3 欄,散佈圖,從左到右相關性由強轉弱

  • 兩部分:大小(1 到 0)與正負號(+ 或 -)
Python 線性建模入門

一起來練習吧!

Python 線性建模入門

Preparing Video For Download...