verticapy.machine_learning.memmodel.linear_model.LinearModel¶
- class verticapy.machine_learning.memmodel.linear_model.LinearModel(coef: Annotated[list | ndarray, 'Array Like Structure'], intercept: float = 0.0)¶
InMemoryModelimplementation of linear algorithms.Parameters¶
- coef: ArrayLike
ArrayLike of the model’s coefficients.
- intercept: float, optional
The intercept or constant value.
Note
memmodel()are defined entirely by their attributes. For example,coefficientsandinterceptdefine a linear regression model.Attributes¶
Attributes are identical to the input parameters, followed by an underscore (‘_’).
Examples¶
Initalization
Import the required module.
from verticapy.machine_learning.memmodel.linear_model import LinearModel
A linear model is defined by its
coefficientsand aninterceptvalue. In this example, we will use the following:coefficients = [0.5, 1.2] intercept = 2.0
Let’s create a
LinearModel.model_lm = LinearModel(coefficients, intercept)
Create a dataset.
data = [[1.0, 0.3], [2.0, -0.6]]
Making In-Memory Predictions
Use
predict()method to do predictions.model_lm.predict(data) Out[6]: array([2.86, 2.28])
Deploy SQL Code
Let’s use the following column names:
cnames = ['col1', 'col2']
Use
predict_sql()method to get the SQL code needed to deploy the model using its attributes.model_lm.predict_sql(cnames) Out[8]: '2.0 + 0.5 * col1 + 1.2 * col2'
Hint
This object can be pickled and used in any in-memory environment, just like SKLEARN models.
- __init__(coef: Annotated[list | ndarray, 'Array Like Structure'], intercept: float = 0.0) None¶
Methods
__init__(coef[, intercept])Returns the model attributes.
predict(X)Predicts using the input Matrix.
Computes the model's probabilites using the input matrix.
Returns the SQL code needed to deploy the model probabilities using its attributes.
predict_sql(X)Returns the SQL code needed to deploy the model using its attributes.
set_attributes(**kwargs)Sets the model attributes.
Attributes
Must be overridden in child class