factor_analyzer.factor_analyzer_rotator

factor_analyzer.factor_analyzer_rotator

Class to perform various rotations of factor loading matrices.

Classes

Name Description
Rotator Perform rotations on an unrotated factor loading matrix.

Rotator

factor_analyzer.factor_analyzer_rotator.Rotator(
    method='varimax',
    normalize=True,
    power=4,
    kappa=0,
    gamma=0,
    delta=0.01,
    max_iter=500,
    tol=1e-05,
)

Perform rotations on an unrotated factor loading matrix.

The Rotator class takes an (unrotated) factor loading matrix and performs one of several rotations.

Parameters

Name Type Description Default
method str The factor rotation method. Options include: (a) varimax (orthogonal rotation) (b) promax (oblique rotation) (c) oblimin (oblique rotation) (d) oblimax (orthogonal rotation) (e) quartimin (oblique rotation) (f) quartimax (orthogonal rotation) (g) equamax (orthogonal rotation) (h) geomin_obl (oblique rotation) (i) geomin_ort (orthogonal rotation) Defaults to ‘varimax’. 'varimax'
normalize bool Whether to perform Kaiser normalization and de-normalization prior to and following rotation. Used for ‘varimax’ and ‘promax’ rotations. If None, default for ‘promax’ is False, and default for ‘varimax’ is True. Defaults to None. True
power int The exponent to which to raise the promax loadings (minus 1). Numbers should generally range from 2 to 4. Defaults to 4. 4
kappa float The kappa value for the ‘equamax’ objective. Ignored if the method is not ‘equamax’. Defaults to 0. 0
gamma int The gamma level for the ‘oblimin’ objective. Ignored if the method is not ‘oblimin’. Defaults to 0. 0
delta float The delta level for ‘geomin’ objectives. Ignored if the method is not ’geomin_*’. Defaults to 0.01. 0.01
max_iter int The maximum number of iterations. Used for ‘varimax’ and ‘oblique’ rotations. Defaults to 1000. 500
tol float The convergence threshold. Used for ‘varimax’ and ‘oblique’ rotations. Defaults to 1e-5. 1e-05

Attributes

Name Type Description
loadings_ numpy.ndarray The loadings matrix. Shape (n_features, n_factors).
rotation_ numpy.ndarray The rotation matrix. Shape (n_factors, n_factors).
phi_ numpy.ndarray or None The factor correlations matrix. This only exists if method is ‘oblique’.

Notes

Most of the rotations in this class are ported from R’s GPARotation package.

References

[1] https://cran.r-project.org/web/packages/GPArotation/index.html

Examples

>>> import pandas as pd
>>> from spotoptim.factor_analyzer import FactorAnalyzer, Rotator
>>> df_features = pd.read_csv('test02.csv')
>>> fa = FactorAnalyzer(rotation=None)
>>> fa.fit(df_features)
>>> rotator = Rotator()
>>> rotator.fit_transform(fa.loadings_)
array([[-0.07693215,  0.04499572,  0.76211208],
       [ 0.01842035,  0.05757874,  0.01297908],
       [ 0.06067925,  0.70692662, -0.03311798],
       [ 0.11314343,  0.84525117, -0.03407129],
       [ 0.15307233,  0.5553474 , -0.00121802],
       [ 0.77450832,  0.1474666 ,  0.20118338],
       [ 0.7063001 ,  0.17229555, -0.30093981],
       [ 0.83990851,  0.15058874, -0.06182469],
       [ 0.76620579,  0.1045194 , -0.22649615],
       [ 0.81372945,  0.20915845,  0.07479506]])

Methods

Name Description
fit Compute the factor rotation.
fit_transform Compute the factor rotation, and return the new loading matrix.
fit
factor_analyzer.factor_analyzer_rotator.Rotator.fit(X, y=None)

Compute the factor rotation.

Parameters
Name Type Description Default
X array - like The factor loading matrix. Shape (n_features, n_factors). required
y ignored Ignored. None
Returns
Name Type Description
self Rotator The rotator object.
Examples
>>> import pandas as pd
>>> from spotoptim.factor_analyzer import FactorAnalyzer, Rotator
>>> df_features = pd.read_csv('test02.csv')
>>> fa = FactorAnalyzer(rotation=None)
>>> fa.fit(df_features)
>>> rotator = Rotator()
>>> rotator.fit(fa.loadings_)
fit_transform
factor_analyzer.factor_analyzer_rotator.Rotator.fit_transform(X, y=None)

Compute the factor rotation, and return the new loading matrix.

Parameters
Name Type Description Default
X array - like The factor loading matrix. Shape (n_features, n_factors). required
y ignored Ignored. None
Returns
Name Type Description
loadings_ numpy.ndarray The loadings matrix. Shape (n_features, n_factors).
Raises
Name Type Description
ValueError If method is not in the list of acceptable methods.
Examples
>>> import pandas as pd
>>> from spotoptim.factor_analyzer import FactorAnalyzer, Rotator
>>> df_features = pd.read_csv('test02.csv')
>>> fa = FactorAnalyzer(rotation=None)
>>> fa.fit(df_features)
>>> rotator = Rotator()
>>> rotator.fit_transform(fa.loadings_)
array([[-0.07693215,  0.04499572,  0.76211208],
       [ 0.01842035,  0.05757874,  0.01297908],
       [ 0.06067925,  0.70692662, -0.03311798],
       [ 0.11314343,  0.84525117, -0.03407129],
       [ 0.15307233,  0.5553474 , -0.00121802],
       [ 0.77450832,  0.1474666 ,  0.20118338],
       [ 0.7063001 ,  0.17229555, -0.30093981],
       [ 0.83990851,  0.15058874, -0.06182469],
       [ 0.76620579,  0.1045194 , -0.22649615],
       [ 0.81372945,  0.20915845,  0.07479506]])