Using factor analysis for decomposition
Factor analysis is another technique that we can use to reduce dimensionality. However, factor analysis makes assumptions and PCA does not. The basic assumption is that there are implicit features responsible for the features of the dataset.
This recipe will boil down to the explicit features from our samples in an attempt to understand the independent variables as much as the dependent variables.
Getting ready
To compare PCA and factor analysis, let's use the iris dataset again, but we'll first need to load the FactorAnalysis
class:
from sklearn import datasets iris = datasets.load_iris() iris_X = iris.data from sklearn.decomposition import FactorAnalysis
How to do it...
From a programming perspective, factor analysis isn't much different from PCA:
fa = FactorAnalysis(n_components=2) iris_two_dim = fa.fit_transform(iris.data) iris_two_dim[:5] array([[-1.33125848, -0.55846779], [-1.33914102, 0.00509715], [-1.40258715, 0.307983 ], ...