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

modified doc string of memmodel/linear_model.py #747

Merged
merged 5 commits into from
Oct 17, 2023
Merged
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
145 changes: 143 additions & 2 deletions verticapy/machine_learning/memmodel/linear_model.py
abhsharma2 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,80 @@

class LinearModel(InMemoryModel):
"""
InMemoryModel implementation of linear
:py:mod:`verticapy.machine_learning.memmodel.base.InMemoryModel` implementation of linear
algorithms.


Parameters
----------
coef: ArrayLike
ArrayLike of the model's coefficients.
abhsharma2 marked this conversation as resolved.
Show resolved Hide resolved
intercept: float, optional
The intercept or constant value.

.. note:: :py:mod:`verticapy.machine_learning.memmodel` are defined entirely by their attributes. For example, 'coefficients' and 'intercept' define a linear regression model.

Examples
--------

**Initalization**

Import the required module.

.. ipython:: python
:suppress:

from verticapy.machine_learning.memmodel.linear_model import LinearModel

A linear model is defined by its coefficients and an intercept value. In this example, we will use the following:

.. ipython:: python
:suppress:

coefficients = [0.5, 1.2]
intercept = 2.0

Let's create a :py:mod:`verticapy.machine_learning.memmodel.linear_model`.

.. ipython:: python
:suppress:

model_lm = LinearModel(coefficients, intercept)

Create a dataset.

.. ipython:: python
:suppress:
oualib marked this conversation as resolved.
Show resolved Hide resolved

data = [[1.0, 0.3], [2.0, -0.6]]

**Making In-Memory Predictions**

Use :py:mod:`verticapy.machine_learning.memmodel.linear_model.LinearModel.predict` method to do predictions

.. ipython:: python
:suppress:

model_lm.predict(data)

**Deploy SQL Code**

Let's use the following column names:

.. ipython:: python
:suppress:

cnames = ['col1', 'col2']

Use :py:mod:`verticapy.machine_learning.memmodel.linear_model.LinearModel.predict_sql` method to get the SQL code needed to deploy the model using its attributes

.. ipython:: python
:suppress:

model_lm.predict_sql(cnames)

.. 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 @@ -160,7 +225,7 @@ def predict_proba_sql(self, X: ArrayLike) -> list[str]:

class LinearModelClassifier(LinearModel):
"""
InMemoryModel Implementation of linear algorithms for
:py:mod:`verticapy.machine_learning.memmodel.base.InMemoryModel` Implementation of linear algorithms for
classification.

Parameters
Expand All @@ -169,6 +234,82 @@ class LinearModelClassifier(LinearModel):
ArrayLike of the model's coefficients.
intercept: float, optional
The intercept or constant value.

Examples
--------
oualib marked this conversation as resolved.
Show resolved Hide resolved

**Initalization**

Import the required module.
oualib marked this conversation as resolved.
Show resolved Hide resolved

.. ipython:: python
:suppress:

from verticapy.machine_learning.memmodel.linear_model import LinearModelClassifier

A linear classifier model is defined by its coefficients and an intercept value. In this example, we will use the following:

.. ipython:: python
:suppress:

coefficients = [0.5, 1.2]
intercept = 2.0

Let's create a :py:mod:`verticapy.machine_learning.memmodel.linear_model`.

.. ipython:: python
:suppress:

model_lmc = LinearModelClassifier(coefficients, intercept)

Create a dataset.

.. ipython:: python
:suppress:

data = [[1.0, 0.3], [-0.5, -0.8]]

**Making In-Memory Predictions**

Use :py:meth:`verticapy.machine_learning.memmodel.linear_model.LinearModelClassifier.predict` method to do predictions

.. ipython:: python
:suppress:

model_lmc.predict(data)

Use :py:meth:`verticapy.machine_learning.memmodel.linear_model.LinearModel.predict_proba` method to calculate the predicted probabilities for each class

.. ipython:: python
:suppress:

model_lmc.predict_proba(data)

**Deploy SQL Code**

Let's use the following column names:

.. ipython:: python
:suppress:

cnames = ['col1', 'col2']

Use :py:meth:`verticapy.machine_learning.memmodel.linear_model.LinearModelClassifier.predict_sql` method to get the SQL code needed to deploy the model using its attributes

.. ipython:: python
:suppress:

model_lmc.predict_sql(cnames)

Use :py:meth:`verticapy.machine_learning.memmodel.linear_model.LinearModel.predict_proba_sql` method to get the SQL code needed to deploy the model that computes predicted probabilities

.. ipython:: python
:suppress:

model_lmc.predict_proba_sql(cnames)

.. hint:: This object can be pickled and used in any in-memory environment, just like `SKLEARN <https://scikit-learn.org/>`_ models.

"""

# Properties.
Expand Down