`L i]5ddlZddlmZmZddlmZddlmZddl m Z m Z m Z m Z mZGdd ZGd d ZGd d eeZedgde_GddeZdZGddeZy)N) BaseEstimatorClassifierMixin) RequestMethod) available_if)_check_sample_weight _num_samples check_arraycheck_is_fittedcheck_random_stateceZdZdZdZdZy)ArraySlicingWrapper- Parameters ---------- array c||_yNarrayselfrs \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sklearn/utils/_mocking.py__init__zArraySlicingWrapper.__init__s  c2t|j|Sr MockDataFramer)raslices r __getitem__zArraySlicingWrapper.__getitem__sTZZ/00rN)__name__ __module__ __qualname____doc__rrrrrrs 1rrc8eZdZdZdZdZd dZdZdZd dZ y) rrc||_||_|j|_|j|_t ||_yr)rvaluesshapendimrilocrs rrzMockDataFrame.__init__)s2  [[ JJ '. rc,t|jSr)lenr)rs r__len__zMockDataFrame.__len__1s4::rNc|jSrr)rdtypes r __array__zMockDataFrame.__array__4szzrcFt|j|jk(Srrrothers r__eq__zMockDataFrame.__eq__:sTZZ5;;677rc||k( Srr#r1s r__ne__zMockDataFrame.__ne__=s5=  rcNt|jj||S)Naxis)rrtake)rindicesr8s rr9zMockDataFrame.take@sTZZ__W4_@AArr)r) rr r!r"rr,r/r3r5r9r#rrrr s&/ 8!Brrc heZdZdZdddddddddd dZddZddZd Zd Zd Z dd Z fd Z xZ S)CheckingClassifiera$ Dummy classifier to test pipelining and meta-estimators. Checks some property of `X` and `y`in fit / predict. This allows testing whether pipelines / cross-validation or metaestimators changed the input. Can also be used to check if `fit_params` are passed correctly, and to force a certain score to be returned. Parameters ---------- check_y, check_X : callable, default=None The callable used to validate `X` and `y`. These callable should return a bool where `False` will trigger an `AssertionError`. If `None`, the data is not validated. Default is `None`. check_y_params, check_X_params : dict, default=None The optional parameters to pass to `check_X` and `check_y`. If `None`, then no parameters are passed in. methods_to_check : "all" or list of str, default="all" The methods in which the checks should be applied. By default, all checks will be done on all methods (`fit`, `predict`, `predict_proba`, `decision_function` and `score`). foo_param : int, default=0 A `foo` param. When `foo > 1`, the output of :meth:`score` will be 1 otherwise it is 0. expected_sample_weight : bool, default=False Whether to check if a valid `sample_weight` was passed to `fit`. expected_fit_params : list of str, default=None A list of the expected parameters given when calling `fit`. Attributes ---------- classes_ : int The classes seen during `fit`. n_features_in_ : int The number of features seen during `fit`. Examples -------- >>> from sklearn.utils._mocking import CheckingClassifier This helper allow to assert to specificities regarding `X` or `y`. In this case we expect `check_X` or `check_y` to return a boolean. >>> from sklearn.datasets import load_iris >>> X, y = load_iris(return_X_y=True) >>> clf = CheckingClassifier(check_X=lambda x: x.shape == (150, 4)) >>> clf.fit(X, y) CheckingClassifier(...) We can also provide a check which might raise an error. In this case, we expect `check_X` to return `X` and `check_y` to return `y`. >>> from sklearn.utils import check_array >>> clf = CheckingClassifier(check_X=check_array) >>> clf.fit(X, y) CheckingClassifier(...) Nallr check_ycheck_y_paramscheck_Xcheck_X_paramsmethods_to_check foo_paramexpected_sample_weightexpected_fit_params random_statec ||_||_||_||_||_||_||_||_| |_yrr>) rr?r@rArBrCrDrErFrGs rrzCheckingClassifier.__init__sI , , 0"&<##6 (rc|r t||jS|jin |j}|j|fi|}t|tt j fr|sJ|}|c|jW|jin |j}|j|fi|}t|tt j fr|sJ||fS|}||fS)atValidate X and y and make extra check. Parameters ---------- X : array-like of shape (n_samples, n_features) The data set. `X` is checked only if `check_X` is not `None` (default is None). y : array-like of shape (n_samples), default=None The corresponding target, by default `None`. `y` is checked only if `check_y` is not `None` (default is None). should_be_fitted : bool, default=True Whether or not the classifier should be already fitted. By default True. Returns ------- X, y ) r rArB isinstanceboolnpbool_r?r@)rXyshould_be_fittedparams checked_X checked_ys r _check_X_yzCheckingClassifier._check_X_ys&  D ! << #..6RD object Parameters passed to the ``fit`` method of the estimator Returns ------- self r=fitF)rPrT) ensure_2dallow_ndzExpected fit parameter(s) z not seen.zFit parameter z has length z ; expected .z#Expected sample_weight to be passed)r rCrTrLr'n_features_in_uniquer classes_rFsetAssertionErrorlistitemsrEr )rrNrO sample_weight fit_paramsmissingkeyvalues rrVzCheckingClassifier.fitsJ0A,q/111  E )Ud6K6K-K??1a%?@DAq hhqk!n +a54"PQ  # #$223c*oEG$0gzJ)..0  U&,q/9((\,u:M9N%l1o%6a9   & &$$%JKK  2 rc|jdk(sd|jvr|j|\}}t|j}|j |j t |S)a=Predict the first class seen in `classes_`. Parameters ---------- X : array-like of shape (n_samples, n_features) The input data. Returns ------- preds : ndarray of shape (n_samples,) Predictions of the first class seen in `classes_`. r=predict)size)rCrTr rGchoicer\r rrNrOrngs rrgzCheckingClassifier.predicts\  E )Y$:O:O-O??1%DAq !2!23zz$--l1oz>>rcz|jdk(sd|jvr|j|\}}t|j}|j t |t |j}tj||}|tj|dddtjfz}|S)aPredict probabilities for each class. Here, the dummy classifier will provide a probability of 1 for the first class of `classes_` and 0 otherwise. Parameters ---------- X : array-like of shape (n_samples, n_features) The input data. Returns ------- proba : ndarray of shape (n_samples, n_classes) The probabilities for each sample and class. r= predict_proba)outrr7N) rCrTr rGrandnr r+r\rLabssumnewaxis)rrNrOrkprobas rrmz CheckingClassifier.predict_probas  E )_@U@U-U??1%DAq !2!23 ,q/3t}}+=>u%( A&q"**}55 rcN|jdk(sd|jvr|j|\}}t|j}t |j dk(r|j t|S|j t|t |j S)aBConfidence score. Parameters ---------- X : array-like of shape (n_samples, n_features) The input data. Returns ------- decision : ndarray of shape (n_samples,) if n_classes == 2 else (n_samples, n_classes) Confidence score. r=decision_functionr)rCrTr rGr+r\ror rjs rruz$CheckingClassifier.decision_functions  ! !U *"d&;&;;??1%DAq !2!23 t}}  "99\!_- -99\!_c$--.@A Arc|jdk(sd|jvr|j|||jdkDrd}|Sd}|S)aQFake score. Parameters ---------- X : array-like of shape (n_samples, n_features) Input data, where `n_samples` is the number of samples and `n_features` is the number of features. Y : array-like of shape (n_samples, n_output) or (n_samples,) Target relative to X for classification or regression; None for unsupervised learning. Returns ------- score : float Either 0 or 1 depending of `foo_param` (i.e. `foo_param > 1 => score=1` otherwise `score=0`). r=scorerg?g)rCrTrD)rrNYrws rrwzCheckingClassifier.score7sQ&  E )W8M8M-M OOAq ! >>A E E rcvt|}d|_d|j_d|j _|S)NTF)super__sklearn_tags__ _skip_test input_tags two_d_array target_tags one_d_labelsrtags __class__s rr{z#CheckingClassifier.__sklearn_tags__Rs6w')&+#(,% rNTr)NN) rr r!r"rrTrVrgrmrurwr{ __classcell__rs@rr<r<DsV?H# ).#J.`?$0B66rr<rVF)namekeys validate_keysc<eZdZdZddZdZdZdZfdZxZ S)NoSampleWeightWrapperzWrap estimator which will not expose `sample_weight`. Parameters ---------- est : estimator, default=None The estimator to wrap. c||_yr)est)rrs rrzNoSampleWeightWrapper.__init__ks rc:|jj||Sr)rrVrrNrOs rrVzNoSampleWeightWrapper.fitnsxx||Aq!!rc8|jj|Sr)rrgrrNs rrgzNoSampleWeightWrapper.predictqsxx""rc8|jj|Sr)rrmrs rrmz#NoSampleWeightWrapper.predict_probatsxx%%a((rc2t|}d|_|Sr)rzr{r|rs rr{z&NoSampleWeightWrapper.__sklearn_tags__wsw') rr) rr r!r"rrVrgrmr{rrs@rrrbs&"#)rrcfd}|S)Nc@|jduxr|jvSrresponse_methods)rmethods rcheckz_check_response..check~s$$$D0TVt?T?T5TTrr#)rrs` r_check_responser}sU LrceZdZdZd dZdZeeddZeeddZ eed d Z y) _MockEstimatorOnOffPredictionaEstimator for which we can turn on/off the prediction methods. Parameters ---------- response_methods: list of {"predict", "predict_proba", "decision_function"}, default=None List containing the response implemented by the estimator. When, the response is in the list, it will return the name of the response method when called. Otherwise, an `AttributeError` is raised. It allows to use `getattr` as any conventional estimator. By default, no response methods are mocked. Nc||_yrr)rrs rrz&_MockEstimatorOnOffPrediction.__init__s 0rc:tj||_|Sr)rLr[r\rs rrVz!_MockEstimatorOnOffPrediction.fits !   rrgcy)Nrgr#rs rrgz%_MockEstimatorOnOffPrediction.predictsrrmcy)Nrmr#rs rrmz+_MockEstimatorOnOffPrediction.predict_probasrrucy)Nrur#rs rruz/_MockEstimatorOnOffPrediction.decision_functions"rr) rr r!r"rrVrrrgrmrur#rrrrsl 1/),-.//234/"567#8#rr)numpyrLbaserrutils._metadata_requestsrmetaestimatorsr validationr r r r r rrr<set_fit_requestrrrr#rrrsy14( 1 1!B!BHS-Sr&3 Ru&" M6#M#r