To calculate the factor loadings in Python using PCA, we can use the `components_` attribute of the `sklearn.decomposition.PCA` object [1][2]. The factor loadings are the coefficients of the linear combination of the original variables from which the principal components (PCs) are constructed.
Here's an example of how to calculate the factor loadings using PCA in Python:
```python
from sklearn.decomposition import PCA
import pandas as pd
import numpy as np
# Load data
data = pd.read_csv('data.csv')
# Perform PCA
pca = PCA(n_components=3)
pca.fit(data)
# Get factor loadings
loadings = pd.DataFrame(pca.components_.T, columns=['PC1', 'PC2', 'PC3'], index=data.columns)
```
In this example, we first load the data into a pandas DataFrame. We then create a `PCA` object with `n_components=3` to perform PCA on the data. Finally, we create a DataFrame `loadings` with the factor loadings for each variable in the original data. The `pca.components_` attribute returns a matrix of shape `(n_components, n_features)` where `n_components` is the number of principal components and `n_features` is the number of original variables in the data. The transpose of this matrix gives us the factor loadings for each variable in the original data [1].
Note that the factor loadings are the correlation coefficients between the original variables and the principal components. To obtain the factor loadings, we can also multiply each component by the square root of its corresponding eigenvalue [2][6]:
```python
loadings = pca.components_.T * np.sqrt(pca.explained_variance_)
```
This gives us the same factor loadings as before, but scaled by the square root of the corresponding eigenvalue.