LDA has an implementation in scikit-learn to avoid this very laborious process. It is easily imported:
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
From there, let's use it to fit and transform our original iris data and plot the resulting projected dataset so that we may compare it to the projection using PCA. The biggest thing to notice in the following code block is that the fit function requires two inputs.
Recall how we mentioned that LDA is actually a classifier disguised as a feature transformation algorithm. Unlike PCA, which finds components in an unsupervised manner (without a response variable), LDA will attempt to find the best coordinate system with respect to a response ...