machine_learning.gradient_boosting_classifier ============================================= .. py:module:: machine_learning.gradient_boosting_classifier Attributes ---------- .. autoapisummary:: machine_learning.gradient_boosting_classifier.iris Classes ------- .. autoapisummary:: machine_learning.gradient_boosting_classifier.GradientBoostingClassifier Module Contents --------------- .. py:class:: GradientBoostingClassifier(n_estimators: int = 100, learning_rate: float = 0.1) .. py:method:: 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 .. py:method:: 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 .. py:method:: 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 .. py:attribute:: learning_rate :value: 0.1 .. py:attribute:: models :type: list[tuple[sklearn.tree.DecisionTreeRegressor, float]] :value: [] .. py:attribute:: n_estimators :value: 100 .. py:data:: iris