vastorbit.machine_learning.memmodel.decomposition.PCA¶
- class vastorbit.machine_learning.memmodel.decomposition.PCA(principal_components: Annotated[list | ndarray, 'Array Like Structure'], mean: Annotated[list | ndarray, 'Array Like Structure'])¶
InMemoryModelimplementation of thePCAalgorithm.- Parameters:
principal_components (ArrayLike) – Matrix of the principal components.
mean (ArrayLike) – List of the averages of each input feature.
note:: (..) –
PCAare defined entirely by their attributes. For example,principal_componentsandmeandefine a PCA model.
- Variables:
input (Attributes are identical to the)
underscore (parameters, followed by an)
('_').
Examples
Initalization
Import the required module.
from vastorbit.machine_learning.memmodel.decomposition import PCA
A
PCAmodel is defined by itsprincipal_componentsandmeanvalue. In this example, we will use the following:principal_components = [ [0.4, 0.5], [0.3, 0.2], ] mean = [0.1, 0.3]
Let’s create a
PCAmodel.model_pca = PCA(principal_components, mean)
Create a dataset.
data = [[4, 5]]
Making In-Memory Transformation
Use
transform()method to do transformation.model_pca.transform(data)
Deploy SQL Code
Let’s use the following column names:
cnames = ['col1', 'col2']
Use
transform_sql()method to get the SQL code needed to deploy the model using its attributes.model_pca.transform_sql(cnames)
Perform an Oblimin Rotation
Use
rotate()method to perform Oblimin (Varimax, Quartimax) rotation on PCA matrix.model_pca.rotate()
Note
You can determine the type of rotation by adjusting value of gamma in
rotate()method. It must be between0.0and1.0.Use
gamma = 0.0, for Quartimax rotation:gamma = 0.0 model_pca.rotate(gamma)
Use
gamma = 1.0, for Varimax rotation:gamma = 1.0 model_pca.rotate(gamma)
Use
get_attributes()method to check the attributes of the rotated model.model_pca.get_attributes()
Hint
This object can be pickled and used in any in-memory environment, just like scikit-learn models.
- __init__(principal_components: Annotated[list | ndarray, 'Array Like Structure'], mean: Annotated[list | ndarray, 'Array Like Structure']) None¶
Methods
__init__(principal_components, mean)Returns the model attributes.
inverse_transform_sql(X)Returns the SQL needed to reconstruct the original features from the principal components (inverse PCA transform).
matrix_rotation(Phi[, gamma, q, tol])Performs an Oblimin (Varimax, Quartimax) rotation on the input matrix.
rotate([gamma, q, tol])Performs an Oblimin (Varimax, Quartimax) rotation on the
PCAmatrix.set_attributes(**kwargs)Sets the model attributes.
transform(X)Transforms and applies the
PCAmodel to the input matrix.Transforms and returns the SQL needed to deploy the
PCAmodel.Attributes
Must be overridden in child class