あなたの主成分(PC)を持って、あなたは以下のように、PCやデータを内積を計算することによって、あなたの次元を減らすことができます 私は、この手順に従いました。
def projectData(X, U, K):
# Compute the projection of the data using only the top K eigenvectors in U (first K columns). X: data, U: Eigenvectors, K: your choice of dimension
new_U = U[:,:K]
return X.dot(new_U)
元のデータを元に戻すにはどうすればよいですか? Uの上位K個の固有ベクトルを使用して元の空間に投影して戻すことによって実現します。
def recoverData(Z, U, K):
# Compute the approximation of the data by projecting back onto the original space using the top K eigenvectors in U. Z: projected data
new_U = U[:, :K]
return Z.dot(new_U.T) # We can use transpose instead of inverse because U is orthogonal.