Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docstring changes for memmodel/decomposition #777

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion verticapy/machine_learning/memmodel/naive_bayes.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class NaiveBayes(MulticlassClassifier):
'male': 0.583333333333333},
'S': {'female': 0.311212814645309,
'male': 0.688787185354691}}

prior: ArrayLike
The model's classes probabilities.
classes: ArrayLike
Expand Down