Back to questions
JuniorTheoryCommon
The iris data has 150 flowers, 4 features and 3 classes; what does this program print?
from sklearn.datasets import load_iris
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
X, y = load_iris(return_X_y=True)
lda = LinearDiscriminantAnalysis()
X_new = lda.fit_transform(X, y)
print(X_new.shape)(150, 2)
- Expecting
(150, 4), as withPCA: LDA gives at most C − 1 components for C classes, so with 3 classes it keeps 2. - Expecting one component per class,
(150, 3): the centers of 3 classes lie in a plane, so LDA finds only 2 separating directions.
- What would
LinearDiscriminantAnalysis(n_components=3)do on the same data? - How many components can LDA give for a binary classification task?