Skip to content

Commit

Permalink
docstring changes for memmodel/decomposition (#777)
Browse files Browse the repository at this point in the history
* docstring changes for memmodel/decomposition

* updating black formatting changes

* minor black formatting change needed in memmodel/naive_bayes

* removed unnecessary suppress

---------

Co-authored-by: Umar Farooq Ghumman <[email protected]>
  • Loading branch information
abhsharma2 and mail4umar authored Oct 27, 2023
1 parent 78743cc commit b592d53
Showing 1 changed file with 170 additions and 2 deletions.
172 changes: 170 additions & 2 deletions verticapy/machine_learning/memmodel/decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,98 @@ class PCA(InMemoryModel):
Matrix of the principal components.
mean: ArrayLike
List of the averages of each input feature.
.. note:: :py:mod:`verticapy.machine_learning.memmodel` are defined entirely by their attributes.
For example, 'principal components' and 'mean' define a PCA model.
Examples
--------
**Initalization**
Import the required module.
.. ipython:: python
from verticapy.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:
.. ipython:: python
principal_components = [[0.4, 0.5], [0.3, 0.2]]
mean = [0.1, 0.3]
Let's create a :py:mod:`verticapy.machine_learning.memmodel.decomposition.PCA` model.
.. ipython:: python
model_pca = PCA(principal_components, mean)
Create a dataset.
.. ipython:: python
data = [[4, 5]]
**Making In-Memory Transformation**
Use :py:meth:`verticapy.machine_learning.memmodel.decomposition.PCA.transform` method to do transformation
.. ipython:: python
model_pca.transform(data)
**Deploy SQL Code**
Let's use the following column names:
.. ipython:: python
cnames = ['col1', 'col2']
Use :py:meth:`verticapy.machine_learning.memmodel.decomposition.PCA.transform_sql` method
to get the SQL code needed to deploy the model using its attributes
.. ipython:: python
model_pca.transform_sql(cnames)
**Perform an Oblimin Rotation**
Use :py:meth:`verticapy.machine_learning.memmodel.decomposition.PCA.rotate` method
to perform Oblimin (Varimax, Quartimax) rotation on PCA matrix
.. ipython:: python
model_pca.rotate()
.. note:: You can determine the type of rotation by adjusting value of gamma in
:py:meth:`verticapy.machine_learning.memmodel.decomposition.PCA.rotate` method.
It must be between 0.0 and 1.0.
Use gamma = 0.0, for Quartimax rotation:
.. ipython:: python
gamma = 0.0
model_pca.rotate(gamma)
Use gamma = 1.0, for Varimax rotation:
.. ipython:: python
gamma = 1.0
model_pca.rotate(gamma)
Use :py:meth:`verticapy.machine_learning.memmodel.decomposition.PCA.get_attributes` method
to check the attributes of the rotated model
.. ipython:: python
model_pca.get_attributes()
.. hint:: This object can be pickled and used in any in-memory environment, just like `SKLEARN <https://scikit-learn.org/>`_ models.
"""

# Properties.
Expand Down Expand Up @@ -153,8 +245,11 @@ def rotate(self, gamma: float = 1.0, q: int = 20, tol: float = 1e-6) -> None:
gamma: float, optional
Oblimin rotation factor, determines the type of rotation.
It must be between 0.0 and 1.0.
gamma = 0.0 results in a Quartimax rotation.
gamma = 1.0 results in a Varimax rotation.
- gamma = 0.0 results in a Quartimax rotation.
- gamma = 1.0 results in a Varimax rotation.
q: int, optional
Maximum number of iterations.
tol: float, optional
Expand All @@ -176,6 +271,79 @@ class SVD(InMemoryModel):
values: ArrayLike
List of the singular values for each input
feature.
.. note:: :py:mod:`verticapy.machine_learning.memmodel` are defined entirely by their attributes.
For example, 'vectors' and 'values' define a SVD model.
Examples
--------
**Initalization**
Import the required module.
.. ipython:: python
:suppress:
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:
.. ipython:: python
:suppress:
vectors = [[0.4, 0.5], [0.3, 0.2]]
values = [0.1, 0.3]
Let's create a :py:mod:`verticapy.machine_learning.memmodel.decomposition.SVD` model.
.. ipython:: python
:suppress:
model_svd = SVD(vectors, values)
Create a dataset.
.. ipython:: python
:suppress:
data = [[0.3, 0.5]]
**Making In-Memory Transformation**
Use :py:meth:`verticapy.machine_learning.memmodel.decomposition.SVD.transform` method to do transformation
.. ipython:: python
:suppress:
model_svd.transform(data)
**Deploy SQL Code**
Let's use the following column names:
.. ipython:: python
:suppress:
cnames = ['col1', 'col2']
Use :py:meth:`verticapy.machine_learning.memmodel.decomposition.SVD.transform_sql` method
to get the SQL code needed to deploy the model using its attributes
.. ipython:: python
:suppress:
model_svd.transform_sql(cnames)
Use :py:meth:`verticapy.machine_learning.memmodel.decomposition.SVD.get_attributes` method
to check the attributes of the rotated model
.. ipython:: python
:suppress:
model_svd.get_attributes()
.. hint:: This object can be pickled and used in any in-memory environment, just like `SKLEARN <https://scikit-learn.org/>`_ models.
"""

# Properties.
Expand Down

0 comments on commit b592d53

Please sign in to comment.