`L i/)dZddlmZmZddlZddlmZddlm Z m Z m Z m Z m Z ddlmZmZddlmZdd lmZdd lmZdd lmZ dd Zdd ZGdde e eZdZGdde eeZy)z)Base class for ensemble-based estimators.)ABCMetaabstractmethodN)effective_n_jobs) BaseEstimatorMetaEstimatorMixinclone is_classifier is_regressor)Bunchcheck_random_state)get_tags)_print_elapsed_time)_routing_enabled)_BaseCompositioncts3d|vr/ t||5|j|||dddd|St||5|j||fi|ddd|S#1swY6xYw#t$rB}dt |vr/tdj |j j|d}~wwxYw#1swY|SxYw)z7Private function used to fit an estimator within a job. sample_weight)rNz+unexpected keyword argument 'sample_weight'z8Underlying estimator {} does not support sample weights.)rrfit TypeErrorstrformat __class____name__) estimatorXy fit_paramsmessage_clsnamemessageexcs \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sklearn/ensemble/_base.py_fit_single_estimatorr"s  /Z"? $_g> O a*_2M N O !' : . IMM!Q -* - .  O O <CHNUU!++44    . s9 A5A)A5 C)A2.A55 C>=B;;CC c4t|}i}t|jdD]X}|dk(s|jds|j t j t jj||<Z|r|jdi|yy)aSet fixed random_state parameters for an estimator. Finds all parameters ending ``random_state`` and sets them to integers derived from ``random_state``. Parameters ---------- estimator : estimator supporting get/set_params Estimator with potential randomness managed by random_state parameters. random_state : int, RandomState instance or None, default=None Pseudo-random number generator to control the generation of the random integers. Pass an int for reproducible output across multiple function calls. See :term:`Glossary `. Notes ----- This does not necessarily set *all* ``random_state`` attributes that control an estimator's randomness, only those accessible through ``estimator.get_params()``. ``random_state``s not controlled include those belonging to: * cross-validation splitters * ``scipy.stats`` rvs Tdeep random_state__random_stateN) r sorted get_paramsendswithrandintnpiinfoint32max set_params)rr&to_setkeys r!_set_random_statesr4+s8&l3L Fi***56G . CLL1A$B&..rxx/A/E/EFF3KG &v&cXeZdZdZe d deddZd dZd dZdZ d Z d Z y) BaseEnsembleaBase class for all ensemble classes. Warning: This class should not be used directly. Use derived classes instead. Parameters ---------- estimator : object The base estimator from which the ensemble is built. n_estimators : int, default=10 The number of estimators in the ensemble. estimator_params : list of str, default=tuple() The list of attributes to use as parameters when instantiating a new base estimator. If none are given, default parameters are used. Attributes ---------- estimator_ : estimator The base estimator from which the ensemble is grown. estimators_ : list of estimators The collection of fitted base estimators. N ) n_estimatorsestimator_paramsc.||_||_||_yN)rr9r:)selfrr9r:s r!__init__zBaseEnsemble.__init__ls#( 0r5cN|j|j|_y||_y)zMCheck the base estimator. Sets the `estimator_` attributes. N)r estimator_)r=defaults r!_validate_estimatorz BaseEnsemble._validate_estimator}s >> %"nnDO%DOr5c t|j}|jdi|jDcic]}|t ||c}| t |||r|j j||Scc}w)zMake and configure a copy of the `estimator_` attribute. Warning: This method should be used to properly instantiate new sub-estimators. r()r r@r1r:getattrr4 estimators_append)r=rFr&rps r!_make_estimatorzBaseEnsemble._make_estimatorsu $//*  TT=R=RS74#3 3ST  # y, 7     # #I . TsA8 c,t|jS)z0Return the number of estimators in the ensemble.)lenrEr=s r!__len__zBaseEnsemble.__len__s4##$$r5c |j|S)z.Return the index'th estimator in the ensemble.)rE)r=indexs r! __getitem__zBaseEnsemble.__getitem__s&&r5c,t|jS)z0Return iterator over estimators in the ensemble.)iterrErKs r!__iter__zBaseEnsemble.__iter__sD$$%%r5r<)TN) r __module__ __qualname____doc__rtupler>rBrHrLrOrRr(r5r!r7r7QsH4 1 1 1 &"%'&r5r7) metaclassctt||}tj|||zt}|d||zxxxdz ccctj |}||j dg|j zfS)z;Private function used to partition estimators between jobs.)dtypeNr)minrr-fullintcumsumtolist)r9n_jobsn_estimators_per_jobstartss r!_partition_estimatorsrcs{!&)< 8F776<6+AM0<&01Q61 YY+ ,F '..01# 2G GGr5c^eZdZdZedZedZdZfdZ dfd Z fdZ xZ S) _BaseHeterogeneousEnsembleaBase class for heterogeneous ensemble of learners. Parameters ---------- estimators : list of (str, estimator) tuples The ensemble of estimators to use in the ensemble. Each element of the list is defined as a tuple of string (i.e. name of the estimator) and an estimator instance. An estimator can be set to `'drop'` using `set_params`. Attributes ---------- estimators_ : list of estimators The elements of the estimators parameter, having been fitted on the training data. If an estimator has been set to `'drop'`, it will not appear in `estimators_`. c>tdit|jS)zDictionary to access any fitted sub-estimators by name. Returns ------- :class:`~sklearn.utils.Bunch` r()r dict estimatorsrKs r!named_estimatorsz+_BaseHeterogeneousEnsemble.named_estimatorss-tDOO,--r5c||_yr<rh)r=rhs r!r>z#_BaseHeterogeneousEnsemble.__init__s $r5c t|jdk(std|jDs tdt |j\}}|j |t d|D}|s tdt|rtnt}|D]L}|dk7s ||rtdj|jj|jdd||fS) Nrc3rK|]/}t|ttfxrt|dt1yw)rN) isinstancerVlistr).0items r! zB_BaseHeterogeneousEnsemble._validate_estimators..s60  teT] + H 47C0H H0 s57zfInvalid 'estimators' attribute, 'estimators' should be a non-empty list of (string, estimator) tuples.c3&K|] }|dk7 yw)dropNr(rpests r!rrzB_BaseHeterogeneousEnsemble._validate_estimators..s@cC6M@szHAll estimators are dropped. At least one is required to be an estimator.rtz The estimator {} should be a {}.) rJrhall ValueErrorzip_validate_namesanyr r rrr)r=namesrh has_estimatoris_estimator_typervs r!_validate_estimatorsz/_BaseHeterogeneousEnsemble._validate_estimatorss t 1 $C0 0 - @  1z U#@Z@@ &  .;4-@Ml Cf}%6s%; 6== ..0A0J0J120N j  r5c &t|di||S)a Set the parameters of an estimator from the ensemble. Valid parameter keys can be listed with `get_params()`. Note that you can directly set the parameters of the estimators contained in `estimators`. Parameters ---------- **params : keyword arguments Specific parameters using e.g. `set_params(parameter_name=new_value)`. In addition, to setting the parameters of the estimator, the individual estimator of the estimators can also be set, or can be removed by setting them to 'drop'. Returns ------- self : object Estimator instance. rk)super _set_params)r=paramsrs r!r1z%_BaseHeterogeneousEnsemble.set_paramss, 3F3 r5c&t|d|S)a< Get the parameters of an estimator from the ensemble. Returns the parameters given in the constructor as well as the estimators contained within the `estimators` parameter. Parameters ---------- deep : bool, default=True Setting it to True gets the various estimators and the parameters of the estimators as well. Returns ------- params : dict Parameter and estimator names mapped to their values or parameter names mapped to their values. rhr$)r _get_params)r=r%rs r!r*z%_BaseHeterogeneousEnsemble.get_paramss&w"_BaseHeterogeneousEnsemble.__sklearn_tags__..&s=,:=Q69IQ ++55tS,68c3tK|]0}|ddk7r"t|djjnd2ywr)rrsparserus r!rrz>_BaseHeterogeneousEnsemble.__sklearn_tags__..*s=)7:!f6FQ ++22DP)r)r__sklearn_tags__rxrhrrr Exception)r=tagsrs r!rz+_BaseHeterogeneousEnsemble.__sklearn_tags__#s}w') (+,??,)DOO %&))??)&DOO "     sAA)) A65A6)T) rrSrTrUpropertyrirr>rr1r*r __classcell__)rs@r!reresJ$..%%!@2<*r5re)NNr<)rUabcrrnumpyr-joblibrbaserrr r r utilsr r utils._tagsrutils._user_interfacerutils.metadata_routingrutils.metaestimatorsrr"r4r7rcrer(r5r!rsh/ (#XX-"753@D0#'LQ&%}Q&h HA(GAr5