Loading...

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'])

InMemoryModel implementation of the PCA algorithm.

Parameters:
  • principal_components (ArrayLike) – Matrix of the principal components.

  • mean (ArrayLike) – List of the averages of each input feature.

  • note:: (..) – PCA are defined entirely by their attributes. For example, principal_components and mean define 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 PCA model is defined by its principal_components and mean value. 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 PCA model.

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 between 0.0 and 1.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)

get_attributes()

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 PCA matrix.

set_attributes(**kwargs)

Sets the model attributes.

transform(X)

Transforms and applies the PCA model to the input matrix.

transform_sql(X)

Transforms and returns the SQL needed to deploy the PCA model.

Attributes

object_type

Must be overridden in child class