Skip to content

Commit

Permalink
exa 16.1
Browse files Browse the repository at this point in the history
  • Loading branch information
SmirkCao committed May 30, 2019
1 parent 3222fee commit 591433c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
11 changes: 10 additions & 1 deletion CH16/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,18 @@ $$

### 例16.1

这个例子,其实从表16.3中拿到的结论通过表16.2也能拿到。$y_1$是原始特征的线性组合,并且,各个原始特征的权重(系数)基本相同,说明大家同样重要。$y_1$和总成绩有关系。
这个例子,其实从表16.3中拿到的结论通过表16.2也能拿到。就是说通过单位特征向量和主成分的方差贡献率可以得到通过主成分的因子负荷量以及贡献率能得到的结论。
$y_1$是原始特征的线性组合,并且,各个原始特征的权重(系数)基本相同,说明大家同样重要。$y_1$和总成绩有关系。
$y_2$的贡献可能更多的体现在文理科的差异上,他们的作用相反。

| 类型 | 主成分 | 特征值 | $x_1$ | $x_2$ | $x_3$ | $x_4$ | 方差贡献率 | 备注|
| --- | --- | --- | --- | --- | --- | --- | --- |---|
| 特征向量 |$y_1$| 2.17 | 0.460 | 0.476 | 0.523 | 0.537 | 0.543 ||
| 特征向量 |$y_2$| 0.87 | 0.574 | 0.486 | -0.476 | -0.456 | 0.218 |累计0.761|
| 因子负荷量|$y_1$|2.17|0.678|0.701|0.770|0.791|$\sqrt{\lambda_1}e_{i1}$|平方和=2.169|
| 因子负荷量|$y_2$|0.87|0.536|0.697|0.790|0.806|$\sqrt{\lambda_2}e_{i2}$|平方和=0.870|

这部分数值参考书上内容,如果用numpy做,会有一定出入,回头再复核下。



Expand Down
25 changes: 16 additions & 9 deletions CH16/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,31 @@

class TestPCAMethods(unittest.TestCase):
def test_e_16_1(self):
R = np.array([[1, 0.44, 0.29, 0.33],
r = np.array([[1, 0.44, 0.29, 0.33],
[0.44, 1, 0.35, 0.32],
[0.29, 0.35, 1, 0.60],
[0.33, 0.32, 0.60, 1]])
ev, sigma = np.linalg.eig(R)
ev, sigma = np.linalg.eig(r)

print("\n")
print(40*"*"+"Engine Values"+40*"*")
print(ev)

print(40*"*"+"eta"+40*"*")
denominator = np.sum(ev)
for numerator in ev:
print(np.round(numerator/denominator, 3))

for idx in range(ev.shape[0]):
print(np.round(ev[idx], 3))
print(np.round(sigma[:, idx], 3))
print(np.round(np.sqrt(ev[idx])*sigma[:, idx], 3))

print(0.678**2+0.701**2+0.770**2+0.791**2)

for idx in range(ev.shape[0]):
print("engine value: ", np.round(ev[idx], 3))
print("engine vector: ", np.round(sigma[:, idx], 3))
print("factor loading, rho(xi,yj): ",
np.round(np.sqrt(ev[idx])*sigma[:, idx], 3))
print("factor loading sum: ",
np.round(np.sum(ev[idx]*sigma[:, idx]**2), 3))
print(40*"*"+"svd"+40*"*")
u, s, vh = np.linalg.svd(r)
print(u)
print(s)
print(vh)
# s 特征值, vh 特征向量

0 comments on commit 591433c

Please sign in to comment.