Using LDA for classification
Linear discriminant analysis (LDA) attempts to fit a linear combination of features to predict an outcome variable. LDA is often used as a pre-processing step. We'll walk through both methods in this recipe.
Getting ready
In this recipe, we will do the following:
- Grab stock data from Google.
- Rearrange it in a shape we're comfortable with.
- Create an LDA object to fit and predict the class labels.
- Give an example of how to use LDA for dimensionality reduction.
Before starting on step 1 and grabbing stock data from Google, install a version of pandas that supports the latest stock reader. Do so at an Anaconda command line by typing this:
conda install -c anaconda pandas-datareader
Note that your pandas version will be updated. If this is a problem, create a new environment for this pandas version. Now open a notebook and check whether the pandas-datareader
imports correctly:
from pandas-datareader
import data
If it is imported correctly, no errors will show up.