machine_learning.gradient_boosting_classifier

Attributes

iris

Classes

GradientBoostingClassifier

Module Contents

class machine_learning.gradient_boosting_classifier.GradientBoostingClassifier(n_estimators: int = 100, learning_rate: float = 0.1)
fit(features: numpy.ndarray, target: numpy.ndarray) None

Fit the GradientBoostingClassifier to the training data.

Parameters: - features (np.ndarray): The training features. - target (np.ndarray): The target values.

Returns: None

>>> import numpy as np
>>> from sklearn.datasets import load_iris
>>> clf = GradientBoostingClassifier(n_estimators=100, learning_rate=0.1)
>>> iris = load_iris()
>>> X, y = iris.data, iris.target
>>> clf.fit(X, y)
>>> # Check if the model is trained
>>> len(clf.models) == 100
True
gradient(target: numpy.ndarray, y_pred: numpy.ndarray) numpy.ndarray

Calculate the negative gradient (pseudo-residuals) for logistic loss.

Parameters: - target (np.ndarray): The target values. - y_pred (np.ndarray): The predicted values.

Returns: - np.ndarray: An array of pseudo-residuals.

>>> import numpy as np
>>> clf = GradientBoostingClassifier(n_estimators=100, learning_rate=0.1)
>>> target = np.array([0, 1, 0, 1])
>>> y_pred = np.array([0.2, 0.8, 0.3, 0.7])
>>> residuals = clf.gradient(target, y_pred)
>>> # Check if residuals have the correct shape
>>> residuals.shape == target.shape
True
predict(features: numpy.ndarray) numpy.ndarray

Make predictions on input data.

Parameters: - features (np.ndarray): The input data for making predictions.

Returns: - np.ndarray: An array of binary predictions (-1 or 1).

>>> import numpy as np
>>> from sklearn.datasets import load_iris
>>> clf = GradientBoostingClassifier(n_estimators=100, learning_rate=0.1)
>>> iris = load_iris()
>>> X, y = iris.data, iris.target
>>> clf.fit(X, y)
>>> y_pred = clf.predict(X)
>>> # Check if the predictions have the correct shape
>>> y_pred.shape == y.shape
True
learning_rate
models: list[tuple[sklearn.tree.DecisionTreeRegressor, float]] = []
n_estimators
machine_learning.gradient_boosting_classifier.iris