Back to questions
JuniorTheoryCommon
What does this program print?
from sklearn.datasets import load_iris
from sklearn.decomposition import PCA
X, y = load_iris(return_X_y=True)
pca = PCA(n_components=2)
X_new = pca.fit_transform(X)
print(X_new.shape, pca.components_.shape)(150, 2) (2, 4)
- Expecting
components_of shape(4, 2): it holds one row per component and one column per original feature, so its shape is(n_components, n_features). - Expecting
X_newto keep 4 columns:fit_transformreturns the projections, one column per kept component, so it has 2 columns.
- How is one row of
X_newcomputed from a row ofXandcomponents_? - What shape would
components_have withoutn_components?