`L i@dZddlZddlmZmZddlmZmZddlZ ddl m Z m Z m Z mZmZddlmZmZddlmZmZdd lmZmZdd lmZmZmZmZdd lmZm Z dd l!m"Z"m#Z#dd l$m%Z%m&Z&m'Z'm(Z(m)Z)ddl*m+Z+ddgZ,Gdde+eZ-dZ.Gdde#e e-Z/Gdde#e e-Z0y)a\Weight Boosting. This module contains weight boosting estimators for both classification and regression. The module structure is the following: - The `BaseWeightBoosting` base class implements a common ``fit`` method for all the estimators in the module. Regression and classification only differ from each other in the loss function that is optimized. - :class:`~sklearn.ensemble.AdaBoostClassifier` implements adaptive boosting (AdaBoost-SAMME) for classification problems. - :class:`~sklearn.ensemble.AdaBoostRegressor` implements adaptive boosting (AdaBoost.R2) for regression problems. N)ABCMetaabstractmethod)IntegralReal)ClassifierMixinRegressorMixin _fit_context is_classifier is_regressor)accuracy_scorer2_score)DecisionTreeClassifierDecisionTreeRegressor)_safe_indexingcheck_random_state) HasMethodsHiddenInterval StrOptions)softmax stable_cumsum)_raise_for_unsupported_routing_RoutingNotSupportedMixin)_check_sample_weight _num_samplescheck_is_fittedhas_fit_parameter validate_data) BaseEnsembleAdaBoostClassifierAdaBoostRegressorceZdZUdZeddgdgeedddgeeddd gd gd Ze e d <e dd e dddfd Z dZedddZe dZddZedZfdZxZS)BaseWeightBoostingzBase class for AdaBoost estimators. Warning: This class should not be used directly. Use derived classes instead. fitpredictNr left)closedrneither random_state estimator n_estimators learning_rater+_parameter_constraints2?)r.estimator_paramsr/r+cFt||||||_||_y)N)r-r.r3)super__init__r/r+)selfr-r.r3r/r+ __class__s g/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sklearn/ensemble/_weight_boosting.pyr6zBaseWeightBoosting.__init__Is2 %-  +(c *t||ddgddddS)NcsrcscTF) accept_sparse ensure_2dallow_nddtypereset)rr7Xs r9_check_XzBaseWeightBoosting._check_X\s(   %.  r:F)prefer_skip_nested_validationc t|d|t|||ddgdddt|\}}t||tj dd}||j z}|jg|_t j|jtj |_ t j|jtj |_ t|j}t j |j"j$}|d k(}t'|jD]}t j(||d }d ||<|j+|||||\}}} ||S||j|<| |j|<| d k(r|St j |} t j,| st/j0d |dd|S| d kr|S||jdz ks|| z}|S)aBuild a boosted classifier/regressor from the training set (X, y). Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. Sparse matrix can be CSC, CSR, COO, DOK, or LIL. COO, DOK, and LIL are converted to CSR. y : array-like of shape (n_samples,) The target values. sample_weight : array-like of shape (n_samples,), default=None Sample weights. If None, the sample weights are initialized to 1 / n_samples. Returns ------- self : object Fitted estimator. r& sample_weightr<r=TN)r>r?r@rA y_numeric)rAcopyensure_non_negative)rA)a_mina_maxrz:Sample weights have reached infinite values, at iteration zG, causing overflow. Iterations stopped. Try lowering the learning rate.r) stacklevelr )rrr rnpfloat64sum_validate_estimator estimators_zerosr.estimator_weights_onesestimator_errors_rr+finforAepsrangeclip_boostisfinitewarningswarn) r7rDyrIr+epsilonzero_weight_maskiboostestimator_weightestimator_errorsample_weight_sums r9r&zBaseWeightBoosting.fiths+2 'tU-P   %."4(  1- 1BJJTt  **,,    ""$((4+<+z:BaseWeightBoosting.feature_importances_..-s'#S555szdUnable to compute feature importances since estimator does not have a feature_importances_ attribute)rUlen ValueErrorrWrSzipAttributeError)r7normes r9rrz'BaseWeightBoosting.feature_importances_s$    #s4+;+;'<'AQ  **..0D'*4+B+BDDTDT'U    1   sA A>> B BBcFt|}d|j_|S)NT)r5__sklearn_tags__ input_tagssparse)r7tagsr8s r9r~z#BaseWeightBoosting.__sklearn_tags__;s!w')!% r:rq)__name__ __module__ __qualname____doc__rrrrr0dict__annotations__rtupler6rEr r&r^rnpropertyrrr~ __classcell__r8s@r9r%r%;s!%!34d;!(AtFCD"4DCD'( $D)))$  &+^ ^@% % NG>%%Nr:r%) metaclassc:|j|}tj|tj|jj d|tj |}|dz |d|z |jdddtjfzz zS)zCalculate algorithm 4, step 2, equation c) of Zhu et al [1]. References ---------- .. [1] J. Zhu, H. Zou, S. Rosset, T. Hastie, "Multi-class AdaBoost", 2009. N)outr r2axis) predict_probarQr]rZrAr[logrSnewaxis)r- n_classesrDproba log_probas r9 _samme_probarAs  # #A &E GGE288EKK(,,d>u I MS9_ 1 (=am(LLL r:ceZdZUdZiej dedheedhgiZee d< dddddd fd Z fd Z d Z d Z dZdZdZedZdZdZdZxZS)r"aAn AdaBoost classifier. An AdaBoost [1]_ classifier is a meta-estimator that begins by fitting a classifier on the original dataset and then fits additional copies of the classifier on the same dataset but where the weights of incorrectly classified instances are adjusted such that subsequent classifiers focus more on difficult cases. This class implements the algorithm based on [2]_. Read more in the :ref:`User Guide `. .. versionadded:: 0.14 Parameters ---------- estimator : object, default=None The base estimator from which the boosted ensemble is built. Support for sample weighting is required, as well as proper ``classes_`` and ``n_classes_`` attributes. If ``None``, then the base estimator is :class:`~sklearn.tree.DecisionTreeClassifier` initialized with `max_depth=1`. .. versionadded:: 1.2 `base_estimator` was renamed to `estimator`. n_estimators : int, default=50 The maximum number of estimators at which boosting is terminated. In case of perfect fit, the learning procedure is stopped early. Values must be in the range `[1, inf)`. learning_rate : float, default=1.0 Weight applied to each classifier at each boosting iteration. A higher learning rate increases the contribution of each classifier. There is a trade-off between the `learning_rate` and `n_estimators` parameters. Values must be in the range `(0.0, inf)`. algorithm : {'SAMME'}, default='SAMME' Use the SAMME discrete boosting algorithm. .. deprecated:: 1.6 `algorithm` is deprecated and will be removed in version 1.8. This estimator only implements the 'SAMME' algorithm. random_state : int, RandomState instance or None, default=None Controls the random seed given at each `estimator` at each boosting iteration. Thus, it is only used when `estimator` exposes a `random_state`. Pass an int for reproducible output across multiple function calls. See :term:`Glossary `. Attributes ---------- estimator_ : estimator The base estimator from which the ensemble is grown. .. versionadded:: 1.2 `base_estimator_` was renamed to `estimator_`. estimators_ : list of classifiers The collection of fitted sub-estimators. classes_ : ndarray of shape (n_classes,) The classes labels. n_classes_ : int The number of classes. estimator_weights_ : ndarray of floats Weights for each estimator in the boosted ensemble. estimator_errors_ : ndarray of floats Classification error for each estimator in the boosted ensemble. feature_importances_ : ndarray of shape (n_features,) The impurity-based feature importances if supported by the ``estimator`` (when based on decision trees). Warning: impurity-based feature importances can be misleading for high cardinality features (many unique values). See :func:`sklearn.inspection.permutation_importance` as an alternative. n_features_in_ : int Number of features seen during :term:`fit`. .. versionadded:: 0.24 feature_names_in_ : ndarray of shape (`n_features_in_`,) Names of features seen during :term:`fit`. Defined only when `X` has feature names that are all strings. .. versionadded:: 1.0 See Also -------- AdaBoostRegressor : An AdaBoost regressor that begins by fitting a regressor on the original dataset and then fits additional copies of the regressor on the same dataset but where the weights of instances are adjusted according to the error of the current prediction. GradientBoostingClassifier : GB builds an additive model in a forward stage-wise fashion. Regression trees are fit on the negative gradient of the binomial or multinomial deviance loss function. Binary classification is a special case where only a single regression tree is induced. sklearn.tree.DecisionTreeClassifier : A non-parametric supervised learning method used for classification. Creates a model that predicts the value of a target variable by learning simple decision rules inferred from the data features. References ---------- .. [1] Y. Freund, R. Schapire, "A Decision-Theoretic Generalization of on-Line Learning and an Application to Boosting", 1995. .. [2] :doi:`J. Zhu, H. Zou, S. Rosset, T. Hastie, "Multi-class adaboost." Statistics and its Interface 2.3 (2009): 349-360. <10.4310/SII.2009.v2.n3.a8>` Examples -------- >>> from sklearn.ensemble import AdaBoostClassifier >>> from sklearn.datasets import make_classification >>> X, y = make_classification(n_samples=1000, n_features=4, ... n_informative=2, n_redundant=0, ... random_state=0, shuffle=False) >>> clf = AdaBoostClassifier(n_estimators=100, random_state=0) >>> clf.fit(X, y) AdaBoostClassifier(n_estimators=100, random_state=0) >>> clf.predict([[0, 0, 0, 0]]) array([1]) >>> clf.score(X, y) 0.96 For a detailed example of using AdaBoost to fit a sequence of DecisionTrees as weaklearners, please refer to :ref:`sphx_glr_auto_examples_ensemble_plot_adaboost_multiclass.py`. For a detailed example of using AdaBoost to fit a non-linearly separable classification dataset composed of two Gaussian quantiles clusters, please refer to :ref:`sphx_glr_auto_examples_ensemble_plot_adaboost_twoclass.py`. algorithmSAMME deprecatedr0Nr1r2)r.r/rr+c:t|||||||_yNr,)r5r6r)r7r-r.r/rr+r8s r9r6zAdaBoostClassifier.__init__s, %'%  #r:ct|td|jdk7rt j dt t|jds,t|jjjdy) 5Check the estimator and set the estimator_ attribute.r  max_depthdefaultrzdThe parameter 'algorithm' is deprecated in 1.6 and has no effect. It will be removed in version 1.8.rIz doesn't support sample_weight.N) r5rTrrr`ra FutureWarningr estimator_rxr-r8rr7r8s r9rTz&AdaBoostClassifier._validate_estimatorsx #,BQ,O#P >>\ ) MM5  !/B>>++4455TU Cr:c |j|}|j||||j|}|dk(r,t|dd|_t |j|_||k7}tjtj||d} | dkr|ddfS|j } | dd| z z k\r?|jjd t |jdk(r td y |jtjd| z | z tj| dz zz} ||jd z k(s4tj tj|| |z|dkDzz}|| | fS) aImplement a single boost. Perform a single boost according to the discrete SAMME algorithm and return the updated sample weights. Parameters ---------- iboost : int The index of the current boost iteration. X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. y : array-like of shape (n_samples,) The target values (class labels). sample_weight : array-like of shape (n_samples,) The current sample weights. random_state : RandomState instance The RandomState instance used if the base estimator accepts a `random_state` attribute. Returns ------- sample_weight : array-like of shape (n_samples,) or None The reweighted sample weights. If None then boosting has terminated early. estimator_weight : float The weight for the current boost. If None then boosting has terminated early. estimator_error : float The classification error for the current boost. If None then boosting has terminated early. r+rHrclasses_N)weightsrr2rMz\BaseClassifier in AdaBoostClassifier ensemble is worse than random, ensemble can not be fit.NNNr )_make_estimatorr&r'getattrrrw n_classes_rQmeanaveragerUpoprxr/rr.exp) r7rerDrbrIr+r- y_predict incorrectrgrrfs r9r^zAdaBoostClassifier._boostsL((l(C  a- 8%%a( Q;#Iz4@DM!$--0DON ''"**Y TU"VW a  #s* *OO  cS9_5 5     $4##$) & $ -- FFC/)_< =ySV@W W  **Q..FF}%"Y.-!2CDEM .??r:c|j|}|jdk(r |jj|dkDdS|jjt j |ddS)aPredict classes for X. The predicted class of an input sample is computed as the weighted mean prediction of the classifiers in the ensemble. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. Sparse matrix can be CSC, CSR, COO, DOK, or LIL. COO, DOK, and LIL are converted to CSR. Returns ------- y : ndarray of shape (n_samples,) The predicted classes. rrrr )decision_functionrrtakerQargmax)r7rDpreds r9r'zAdaBoostClassifier.predicthsc"%%a( ??a ==%%dQhQ%7 7}}!!"))Dq"9!BBr:c #K|j|}|j}|j}|dk(rB|j|D]-}t j |j |dkDd/y|j|D]?}t j |j t j|ddAyw)aReturn staged predictions for X. The predicted class of an input sample is computed as the weighted mean prediction of the classifiers in the ensemble. This generator method yields the ensemble prediction after each iteration of boosting and therefore allows monitoring, such as to determine the prediction on a test set after each boost. Parameters ---------- X : array-like of shape (n_samples, n_features) The input samples. Sparse matrix can be CSC, CSR, COO, DOK, or LIL. COO, DOK, and LIL are converted to CSR. Yields ------ y : generator of ndarray of shape (n_samples,) The predicted classes. rrrr N)rErrstaged_decision_functionrQarrayrr)r7rDrclassesrs r9rlz!AdaBoostClassifier.staged_predicts* MM! OO -- >55a8 ?hhw||D1H1|=>> ?55a8 Nhhw||BIId,C!|LMM NsCCct||j|j|jddtj fdk(r&t j jddfStfdt|j|jD}||jjz}dk(r#|dddfxxdzcc<|jdS|S) aCompute the decision function of ``X``. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. Sparse matrix can be CSC, CSR, COO, DOK, or LIL. COO, DOK, and LIL are converted to CSR. Returns ------- score : ndarray of shape of (n_samples, k) The decision function of the input samples. The order of outputs is the same as that of the :term:`classes_` attribute. Binary classification is a special cases with ``k == 1``, otherwise ``k==n_classes``. For binary classification, values closer to -1 or 1 mean more like the first or second class in ``classes_``, respectively. Nr r)shapec3K|]C\}}tj|jk(j|ddz z |zEyw)rr N)rQwherer'T)rsr-wrDrrs r9rvz7AdaBoostClassifier.decision_function..sU  1 HH""1%033i!m$q(  sA A rrr) rrErrrQr zeros_likerrSryrUrW)r7rDrrrs ` @@r9rz$AdaBoostClassifier.decision_functions&  MM! OO --2:: . >==1771:q/: : !$D$4$4d6M6M N    ''++-- > AJ" J888# # r:c# Kt||j|}|j}|jddtj f}d}d}t |j|jD]\}}||z }t j|j||k(j|d|dz z |z}||}n||z }|dk(r>t j|} | dddfxxdzcc<| |z jd||z yw)aCompute decision function of ``X`` for each boosting iteration. This method allows monitoring (i.e. determine error on testing set) after each boosting iteration. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. Sparse matrix can be CSC, CSR, COO, DOK, or LIL. COO, DOK, and LIL are converted to CSR. Yields ------ score : generator of ndarray of shape (n_samples, k) The decision function of the input samples. The order of outputs is the same of that of the :term:`classes_` attribute. Binary classification is a special cases with ``k == 1``, otherwise ``k==n_classes``. For binary classification, values closer to -1 or 1 mean more like the first or second class in ``classes_``, respectively. NrMrr rrr)rrErrrQrryrWrUrr'rrKrS) r7rDrrrr{rtr- current_predtmp_preds r9rz+AdaBoostClassifier.staged_decision_functions,  MM! OO --2:: .!$T%<%N>N!O " FI FND88""1%033i!m$v-L |# $A~774=A"$$+++33Tk!' "sD Dc|dk(r&tj| |gjdz }n||dz z}t|dS)anCompute probabilities from the decision function. This is based eq. (15) of [1] where: p(y=c|X) = exp((1 / K-1) f_c(X)) / sum_k(exp((1 / K-1) f_k(X))) = softmax((1 / K-1) * f(X)) References ---------- .. [1] J. Zhu, H. Zou, S. Rosset, T. Hastie, "Multi-class AdaBoost", 2009. rr F)rK)rQvstackrr)decisionrs r9_compute_proba_from_decisionz/AdaBoostClassifier._compute_proba_from_decisionsF >yy8)X!6799A=H  A %Hxe,,r:ct||j}|dk(r tjt |dfS|j |}|j ||S)aPredict class probabilities for X. The predicted class probabilities of an input sample is computed as the weighted mean predicted class probabilities of the classifiers in the ensemble. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. Sparse matrix can be CSC, CSR, COO, DOK, or LIL. COO, DOK, and LIL are converted to CSR. Returns ------- p : ndarray of shape (n_samples, n_classes) The class probabilities of the input samples. The order of outputs is the same of that of the :term:`classes_` attribute. r )rrrQrXrrrr7rDrrs r9rz AdaBoostClassifier.predict_probasW& OO >77LOQ/0 0))!,009EEr:c#xK|j}|j|D]}|j||yw)aPredict class probabilities for X. The predicted class probabilities of an input sample is computed as the weighted mean predicted class probabilities of the classifiers in the ensemble. This generator method yields the ensemble predicted class probabilities after each iteration of boosting and therefore allows monitoring, such as to determine the predicted class probabilities on a test set after each boost. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. Sparse matrix can be CSC, CSR, COO, DOK, or LIL. COO, DOK, and LIL are converted to CSR. Yields ------ p : generator of ndarray of shape (n_samples,) The class probabilities of the input samples. The order of outputs is the same of that of the :term:`classes_` attribute. N)rrrrs r9staged_predict_probaz'AdaBoostClassifier.staged_predict_proba/s@2OO 55a8 IH33HiH H Is8:cJtj|j|S)aPredict class log-probabilities for X. The predicted class log-probabilities of an input sample is computed as the weighted mean predicted class log-probabilities of the classifiers in the ensemble. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. Sparse matrix can be CSC, CSR, COO, DOK, or LIL. COO, DOK, and LIL are converted to CSR. Returns ------- p : ndarray of shape (n_samples, n_classes) The class probabilities of the input samples. The order of outputs is the same of that of the :term:`classes_` attribute. )rQrrrCs r9predict_log_probaz$AdaBoostClassifier.predict_log_probaMs&vvd((+,,r:rq)rrrrr%r0rrrrr6rTr^r'rlrr staticmethodrrrrrrs@r9r"r"VsOd$  3 3$j'+VJ ~4N-OP$D##$ T@lC0 ND)V1"f--$F8I<-r:ceZdZUdZiej dehdgiZeed< dddddd fd Z fd Z d Z d Z dZ dZxZS)r#aAn AdaBoost regressor. An AdaBoost [1] regressor is a meta-estimator that begins by fitting a regressor on the original dataset and then fits additional copies of the regressor on the same dataset but where the weights of instances are adjusted according to the error of the current prediction. As such, subsequent regressors focus more on difficult cases. This class implements the algorithm known as AdaBoost.R2 [2]. Read more in the :ref:`User Guide `. .. versionadded:: 0.14 Parameters ---------- estimator : object, default=None The base estimator from which the boosted ensemble is built. If ``None``, then the base estimator is :class:`~sklearn.tree.DecisionTreeRegressor` initialized with `max_depth=3`. .. versionadded:: 1.2 `base_estimator` was renamed to `estimator`. n_estimators : int, default=50 The maximum number of estimators at which boosting is terminated. In case of perfect fit, the learning procedure is stopped early. Values must be in the range `[1, inf)`. learning_rate : float, default=1.0 Weight applied to each regressor at each boosting iteration. A higher learning rate increases the contribution of each regressor. There is a trade-off between the `learning_rate` and `n_estimators` parameters. Values must be in the range `(0.0, inf)`. loss : {'linear', 'square', 'exponential'}, default='linear' The loss function to use when updating the weights after each boosting iteration. random_state : int, RandomState instance or None, default=None Controls the random seed given at each `estimator` at each boosting iteration. Thus, it is only used when `estimator` exposes a `random_state`. In addition, it controls the bootstrap of the weights used to train the `estimator` at each boosting iteration. Pass an int for reproducible output across multiple function calls. See :term:`Glossary `. Attributes ---------- estimator_ : estimator The base estimator from which the ensemble is grown. .. versionadded:: 1.2 `base_estimator_` was renamed to `estimator_`. estimators_ : list of regressors The collection of fitted sub-estimators. estimator_weights_ : ndarray of floats Weights for each estimator in the boosted ensemble. estimator_errors_ : ndarray of floats Regression error for each estimator in the boosted ensemble. feature_importances_ : ndarray of shape (n_features,) The impurity-based feature importances if supported by the ``estimator`` (when based on decision trees). Warning: impurity-based feature importances can be misleading for high cardinality features (many unique values). See :func:`sklearn.inspection.permutation_importance` as an alternative. n_features_in_ : int Number of features seen during :term:`fit`. .. versionadded:: 0.24 feature_names_in_ : ndarray of shape (`n_features_in_`,) Names of features seen during :term:`fit`. Defined only when `X` has feature names that are all strings. .. versionadded:: 1.0 See Also -------- AdaBoostClassifier : An AdaBoost classifier. GradientBoostingRegressor : Gradient Boosting Classification Tree. sklearn.tree.DecisionTreeRegressor : A decision tree regressor. References ---------- .. [1] Y. Freund, R. Schapire, "A Decision-Theoretic Generalization of on-Line Learning and an Application to Boosting", 1995. .. [2] H. Drucker, "Improving Regressors using Boosting Techniques", 1997. Examples -------- >>> from sklearn.ensemble import AdaBoostRegressor >>> from sklearn.datasets import make_regression >>> X, y = make_regression(n_features=4, n_informative=2, ... random_state=0, shuffle=False) >>> regr = AdaBoostRegressor(random_state=0, n_estimators=100) >>> regr.fit(X, y) AdaBoostRegressor(n_estimators=100, random_state=0) >>> regr.predict([[0, 0, 0, 0]]) array([4.7972]) >>> regr.score(X, y) 0.9771 For a detailed example of utilizing :class:`~sklearn.ensemble.AdaBoostRegressor` to fit a sequence of decision trees as weak learners, please refer to :ref:`sphx_glr_auto_examples_ensemble_plot_adaboost_regression.py`. loss>linearsquare exponentialr0Nr1r2r)r.r/rr+cHt|||||||_||_yr)r5r6rr+)r7r-r.r/rr+r8s r9r6zAdaBoostRegressor.__init__s4 %'%   (r:c:t|tdy)rrrN)r5rTrrs r9rTz%AdaBoostRegressor._validate_estimators #,AA,N#Or:c|j|}|jtjt |t |d|}t ||}t ||} |j || |j|} tj| |z } |dkD} || } | | }|j}|dk7r||z}|jdk(r|dz}n(|jdk(rdtj| z }| |zj}|dkr|dd fS|d k\r4t|jd kDr|jjd y |d|z z }|j tj"d|z z}||j$d z k(s1|| xxtj&|d|z |j zzcc<|||fS)aWImplement a single boost for regression Perform a single boost according to the AdaBoost.R2 algorithm and return the updated sample weights. Parameters ---------- iboost : int The index of the current boost iteration. X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. y : array-like of shape (n_samples,) The target values (class labels in classification, real numbers in regression). sample_weight : array-like of shape (n_samples,) The current sample weights. random_state : RandomState The RandomState instance used if the base estimator accepts a `random_state` attribute. Controls also the bootstrap of the weights used to train the weak learner. Returns ------- sample_weight : array-like of shape (n_samples,) or None The reweighted sample weights. If None then boosting has terminated early. estimator_weight : float The weight for the current boost. If None then boosting has terminated early. estimator_error : float The regression error for the current boost. If None then boosting has terminated early. rT)sizereplaceprrrrr2rM?r rr)rchoicerQarangerrr&r'absmaxrrrSrwrUrr/rr.power)r7rerDrbrIr+r- bootstrap_idxX_y_r error_vect sample_maskmasked_sample_weightmasked_error_vector error_maxrgbetarfs r9r^zAdaBoostRegressor._boostsR((l(C %++ IIl1o &a , A} - A} - b"%%a( VVIM* #a' ,[9(5'++- > 9 ,  99 A %  YY- '"%0C/C(D"D 02EEJJL a  #s* *  #4##$q(  $$R(##"78 --sTz0BB**Q.. + &"((s00D4F4FF+  &.??r:ctj|jd|Dcgc]}|j|c}j}tj |d}t |j|d}|d|dddfddtjfzk\}|jd}|tjt||f} |tjt|| fScc}w)Nr rrr) rQrrUr'rargsortrrWrrrr) r7rDlimitest predictions sorted_idx weight_cdfmedian_or_above median_idxmedian_estimatorss r9_get_median_predictz%AdaBoostRegressor._get_median_predictVshh$:J:J6E:RS3 ASTVV ZZ !4 #4#:#::#FQO $jB.?2:: .N(NN$+++3 &ryya'A:'MN299\!_57HHII TsC7ct||j|}|j|t|jS)a1Predict regression value for X. The predicted regression value of an input sample is computed as the weighted median prediction of the regressors in the ensemble. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. Sparse matrix can be CSC, CSR, COO, DOK, or LIL. COO, DOK, and LIL are converted to CSR. Returns ------- y : ndarray of shape (n_samples,) The predicted regression values. )rrErrwrUrCs r9r'zAdaBoostRegressor.predictgs8"  MM! ''3t/?/?+@AAr:c#Kt||j|}t|jdD]\}}|j ||yw)aReturn staged predictions for X. The predicted regression value of an input sample is computed as the weighted median prediction of the regressors in the ensemble. This generator method yields the ensemble prediction after each iteration of boosting and therefore allows monitoring, such as to determine the prediction on a test set after each boost. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. Yields ------ y : generator of ndarray of shape (n_samples,) The predicted regression values. r )rN)rrE enumeraterUr)r7rDi_s r9rlz AdaBoostRegressor.staged_predict}sT(  MM! d..2 7DAq**1A*6 6 7sAArq)rrrrr%r0rrrr6rTr^rr'rlrrs@r9r#r#csvsj$  3 3$?@A$D) )&P_@BJ"B,7r:)1rr`abcrrnumbersrrnumpyrQbaserr r r r metricsr rtreerrutilsrrutils._param_validationrrrr utils.extmathrrutils.metadata_routingrrutils.validationrrrrr_baser!__all__r%rr"r#rjr:r9r s*'"/@6NN2   CCL*J-0BJ-Zr71>CUr7r: