:[f"{x * 100:.1f}%" for x in pca.explained_variance_ratio_]
:['29.1%', '18.8%', '7.5%', '5.1%', '3.2%', '3.0%', '2.4%', '2.1%', '2.0%', '1.7%', '1.6%', '1.5%', '1.3%', '1.3%', '1.2%', '1.2%', '1.0%', '1.0%', '1.0%', '0.9%', '0.9%', '0.8%', '0.8%', '0.8%', '0.8%', '0.8%', '0.7%', '0.7%', '0.7%', '0.6%', '0.6%', '0.6%', '0.6%', '0.6%', '0.5%', '0.5%', '0.5%', '0.4%', '0.4%', '0.4%', '0.4%', '0.0%']
>>> pca.n_features_in_
>>>pca.n_samples_
>embedding.shape # (592, 2)
py# PCA成分の取得
matrix_centered = matrix - matrix.mean(axis=0) # 平均中心化
# pca.fit(matrix_centered.T) # 回答者に基づいてPCAを実行
# 第1主成分(X軸)
pc1 = pca.components_[0] # 第1主成分ベクトル(回答者ごとの重み)
for col in matrix.columns:
question_vector = matrix_centered[col]
# contributions[col] = np.dot(question_vector, pc1)
c = np.dot(question_vector, pc1)
print(f"{col}: {c:.2f}: {readable.get(col, col)}")