Here are the steps for performing PCA in Python to explain variability in a target feature:
read_csv() function.sklearn.decomposition module.fit() method.explained_variance_ratio_ attribute.matplotlib.pyplot module.transform() method.Here is an example code for the above steps:
main.py1133 chars38 lines
This will give you a new dataset with the principal components and the target variable. You can now use this dataset for further analysis or modeling.
gistlibby LogSnag