vastorbit.machine_learning.memmodel.ensemble.GradientBoostingClassifier¶
- class vastorbit.machine_learning.memmodel.ensemble.GradientBoostingClassifier(trees: list[BinaryTreeRegressor], logodds: Annotated[list | ndarray, 'Array Like Structure'], classes: Annotated[list | ndarray, 'Array Like Structure'] | None = None, learning_rate: float = 1.0)¶
InMemoryModelimplementation of theGradientBoostingclassifier algorithm.- Parameters:
trees (list[BinaryTreeRegressor]) –
listofBinaryTreefor regression.logodds (ArrayLike[float], optional) – ArrayLike of the logodds of the response classes.
classes (ArrayLike, optional) – The model’s classes.
learning_rate (float, optional) – Learning rate.
- Variables:
input (Attributes are identical to the)
underscore (parameters, followed by an)
('_').
Examples
Initalization
A
GradientBoostingClassifiermodel is an ensemble of multiple binary tree classifier models. In this example, we will create threeBinaryTreeClassifiermodels:from vastorbit.machine_learning.memmodel.tree import BinaryTreeClassifier model1 = BinaryTreeClassifier( children_left = [1, 3, None, None, None], children_right = [2, 4, None, None, None], feature = [0, 1, None, None, None], threshold = ["female", 30, None, None, None], value = [ None, None, [0.8, 0.1, 0.1], [0.1, 0.8, 0.1], [0.2, 0.2, 0.6], ], classes = ["a", "b", "c"] ) model2 = BinaryTreeClassifier( children_left = [1, 3, None, None, None], children_right = [2, 4, None, None, None], feature = [0, 1, None, None, None], threshold = ["female", 30, None, None, None], value = [ None, None, [0.7, 0.2, 0.1], [0.3, 0.5, 0.2], [0.2, 0.2, 0.6], ], classes = ["a", "b", "c"], ) model3 = BinaryTreeClassifier( children_left = [1, 3, None, None, None], children_right = [2, 4, None, None, None], feature = [0, 1, None, None, None], threshold = ["female", 30, None, None, None], value = [ None, None, [0.4, 0.4, 0.2], [0.2, 0.2, 0.6], [0.2, 0.5, 0.3], ], classes = ["a", "b", "c"], )
Now we will use above models to create
GradientBoostingClassifiermodel.from vastorbit.machine_learning.memmodel.ensemble import GradientBoostingClassifier model_gbc = GradientBoostingClassifier( trees = [model1, model2, model3], classes = ["a", "b", "c"], logodds = [0.1, 0.12, 0.15], learning_rate = 0.1, )
Note
We have used
logoddsthat represents logodds of the response column andlearning_ratethat represents learning rate ofGradientBoostingregressor model. Both are optional parameters.Create a dataset.
data = [["male", 100], ["female", 20], ["female", 50]]
Making In-Memory Predictions
Use
predict()method to do predictions.model_gbc.predict(data)
Use
predict_proba()method to compute the predicted probabilities for each class.model_gbc.predict_proba(data)
Deploy SQL Code
Let’s use the following column names:
cnames = ["sex", "fare"]
Use
predict_sql()method to get the SQL code needed to deploy the model using its attributes.model_gbc.predict_sql(cnames)
Use
predict_proba_sql()method to get the SQL code needed to deploy the model probabilities using its attributes.model_gbc.predict_proba_sql(cnames)
Hint
This object can be pickled and used in any in-memory environment, just like scikit-learn models.
Drawing Trees
Use
plot_tree()method to draw the input tree.model_gbc.plot_tree(tree_id = 0)
Important
plot_tree()requires the Graphviz module.Note
The above example is a very basic one. For other more detailed examples and customization options, please see Machine Learning - Tree Plots
- __init__(trees: list[BinaryTreeRegressor], logodds: Annotated[list | ndarray, 'Array Like Structure'], classes: Annotated[list | ndarray, 'Array Like Structure'] | None = None, learning_rate: float = 1.0) None¶
Methods
__init__(trees, logodds[, classes, ...])Returns the model attributes.
plot_tree([pic_path, tree_id])Draws the input tree.
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 using its attributes.
predict_sql(X)Returns the SQL code needed to deploy the model.
set_attributes(**kwargs)Sets the model attributes.
Attributes
Must be overridden in child class