# 데이터 구성 X = RandomState(0).randint(0, 9, 5 * 4).reshape((5, 4)) print(X) # [[5 0 3 3] # [7 3 5 2] # [4 7 6 8] # [8 1 6 7] # [7 8 1 5]] # # 주성분 분석 적합 # # 데이터 표준화 ss = StandardScaler() ss.fit(X.astype(float)) X_scaled = ss.transform(X.astype(float)) print(np.around(X_scaled, 2)) # [[-0.82 -1.19 -0.62 -0.88] # [ 0.54 -0.25 0.41 -1.32] # [-1.5 1. 0.93 1.32] # [ 1.22 -0.88 0.93 0.88] # [ 0.54 1.32 -1.65 0. ]] # 주성분 적합 pca = PCA() pca.fit(X_scaled) # 주성분(V 행렬의 열벡터): 여기서는 V의 전치 행렬이 출력되므로 행 벡터가 된다. print(np.around(pca.components_, 2)) # [[-0.44 0.47 0.33 0.69]