verticapy.machine_learning.memmodel.decomposition.SVD¶
- class verticapy.machine_learning.memmodel.decomposition.SVD(vectors: Annotated[list | ndarray, 'Array Like Structure'], values: Annotated[list | ndarray, 'Array Like Structure'])¶
InMemoryModelimplementation of theSVDAlgorithm.Parameters¶
- vectors: ArrayLike
Matrix of the right singular vectors.
- values: ArrayLike
List of the singular values for each input feature.
Note
SVDare defined entirely by their attributes. For example,vectorsandvaluesdefine a SVD model.Attributes¶
Attributes are identical to the input parameters, followed by an underscore (‘_’).
Examples¶
Initalization
Import the required module.
from verticapy.machine_learning.memmodel.decomposition import SVD
A
SVDmodel is defined by its vectors and values. In this example, we will use the following:vectors = [ [0.4, 0.5], [0.3, 0.2], ] values = [0.1, 0.3]
Let’s create a
SVDmodel.model_svd = SVD(vectors, values)
Create a dataset.
data = [[0.3, 0.5]]
Making In-Memory Transformation
Use
transform()method to do transformation.model_svd.transform(data) Out[6]: array([[2.7 , 0.83333333]])
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_svd.transform_sql(cnames) Out[8]: ['col1 * 0.4 / 0.1 + col2 * 0.3 / 0.1', 'col1 * 0.5 / 0.3 + col2 * 0.2 / 0.3']
Use
get_attributes()method to check the attributes of the rotated model.model_svd.get_attributes() Out[9]: {'vectors': array([[0.4, 0.5], [0.3, 0.2]]), 'values': array([0.1, 0.3])}
Hint
This object can be pickled and used in any in-memory environment, just like SKLEARN models.
- __init__(vectors: Annotated[list | ndarray, 'Array Like Structure'], values: Annotated[list | ndarray, 'Array Like Structure']) None¶
Methods
__init__(vectors, values)Returns the model attributes.
set_attributes(**kwargs)Sets the model attributes.
transform(X)Transforms and applies the
SVDmodel to the input matrix.Transforms and returns the SQL needed to deploy the
SVDmodel.Attributes
Must be overridden in child class