verticapy.machine_learning.memmodel.decomposition.SVD#
- class verticapy.machine_learning.memmodel.decomposition.SVD(vectors: list | ndarray, values: list | ndarray)#
InMemoryModel
implementation of theSVD
Algorithm.Parameters#
- vectors: ArrayLike
Matrix of the right singular vectors.
- values: ArrayLike
List of the singular values for each input feature.
Note
SVD
are defined entirely by their attributes. For example,vectors
andvalues
define 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
SVD
model 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
SVD
model.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: list | ndarray, values: list | ndarray) None #
Methods
__init__
(vectors, values)Returns the model attributes.
set_attributes
(**kwargs)Sets the model attributes.
transform
(X)Transforms and applies the
SVD
model to the input matrix.Transforms and returns the SQL needed to deploy the
SVD
model.Attributes
Must be overridden in child class