固有値・固有ベクトルの解釈・意味#
線形代数的な解釈#
いまいちど定義を振り返る
定義
が成り立つとき、スカラー
定義より、線形変換
Tip
線形変換
と解釈できる。
統計学的な解釈#
データを行列で表したときの話
学習データの分散が最大になる方向への線形変換を求める手法である 主成分分析 を例に考える。
主成分分析
各変数の平均のベクトル
で定義される。
係数ベクトル
このデータの分散は
となる。
このまま
制約条件付き分散最大化問題
この分散が最大となる射影ベクトルは、ラグランジュ関数
を最大にする
微分して0とおけば
より
となる。
これは固有値・固有ベクトルの定義で見かけた
主成分分析は、データ
を解析的に解くために
という式を立てて固有ベクトル
Tip
分散を最大化する軸の方向が固有ベクトル
その軸方向のデータのばらつきの大きさが固有値
と捉えることができる。
数値例#
このようなデータがあったとする
Show code cell source
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
w = 0.3
n = 300
x1 = norm.rvs(loc=0, scale=1, size=n, random_state=0)
x2 = w * x1 + (1 - w) * norm.rvs(loc=0, scale=1, size=n, random_state=1)
X = np.append(x1.reshape(-1, 1), x2.reshape(-1, 1), axis=1)
fig, ax = plt.subplots()
ax.scatter(x1, x2)
ax.set(xlabel="x1", ylabel="x2")
fig.show()

固有値問題を解いて
x_bar = X.mean(axis=0)
X_bar = X - x_bar
Sigma = (1 / n) * X_bar.T @ X_bar
lambdas, vectors = np.linalg.eig(Sigma)
print(f"""
λ={lambdas}
a1={vectors[:, 0].round(3)}
a2={vectors[:, 1].round(3)}
""")
λ=[1.17427995 0.37150396]
a1=[0.886 0.464]
a2=[-0.464 0.886]
主成分を表す固有ベクトルの傾きに直線をプロットすると以下の通り。
係数ベクトル
PC1方向の変換
Show code cell source
o = [0, 0]
a1 = vectors[:, 0]
a2 = vectors[:, 1]
fig, ax = plt.subplots()
ax.scatter(x1, x2)
ax.arrow(*o, *a1, width=0.02, color="coral", length_includes_head=True, alpha=0.7, label="PC1")
ax.arrow(*o, *a2, width=0.02, color="orange", length_includes_head=True, alpha=0.7, label="PC2")
ax.set(xlabel="x1", ylabel="x2")
ax.legend()
fig.show()

推定できた
Show code cell source
S = X_bar @ vectors
fig, ax = plt.subplots()
ax.scatter(S[:, 0], S[:, 1])
ax.set(xlabel="s1", ylabel="s2")
fig.show()
