verticapy.machine_learning.memmodel.linear_model.LinearModelClassifier#
- class verticapy.machine_learning.memmodel.linear_model.LinearModelClassifier(coef: list | ndarray, intercept: float = 0.0)#
InMemoryModel
Implementation of linear algorithms for classification.Parameters#
- coefficients: ArrayLike
ArrayLike of the model’s coefficients.
- intercept: float, optional
The intercept or constant value.
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 LinearModelClassifier
A linear classifier model is defined by its coefficients and an intercept value. In this example, we will use the following:
coefficients = [0.5, 1.2] intercept = 2.0
Let’s create a
LinearModelClassifier
.model_lmc = LinearModelClassifier(coefficients, intercept)
Create a dataset.
data = [[1.0, 0.3], [-0.5, -0.8]]
Making In-Memory Predictions
Use
predict()
method to do predictions.model_lmc.predict(data) Out[6]: array([1, 1])
Use
predict_proba()
method to calculate the predicted probabilities for each class.model_lmc.predict_proba(data) Out[7]: array([[0.0541667 , 0.9458333 ], [0.31216867, 0.68783133]])
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_lmc.predict_sql(cnames) Out[9]: '((1 / (1 + EXP(- (2.0 + 0.5 * col1 + 1.2 * col2)))) > 0.5)::int'
Use
predict_proba_sql()
method to get the SQL code needed to deploy the model that computes predicted probabilities.model_lmc.predict_proba_sql(cnames) Out[10]: ['1 - (1 / (1 + EXP(- (2.0 + 0.5 * col1 + 1.2 * col2))))', '1 / (1 + EXP(- (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: list | ndarray, 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