diff --git a/verticapy/machine_learning/memmodel/linear_model.py b/verticapy/machine_learning/memmodel/linear_model.py index 7047a10ba..afd70a2d2 100755 --- a/verticapy/machine_learning/memmodel/linear_model.py +++ b/verticapy/machine_learning/memmodel/linear_model.py @@ -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. 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: + + 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 `_ models. + """ # Properties. @@ -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 @@ -169,6 +234,82 @@ class LinearModelClassifier(LinearModel): ArrayLike of the model's coefficients. intercept: float, optional The intercept or constant value. + + Examples + -------- + + **Initalization** + + Import the required module. + + .. 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 `_ models. + """ # Properties.