CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
_response.cpython-310.pyc229 linesDownload Raw Back to __pycache__
1o

2�Yi�0�@sbdZddlZddlmZddlmZddlmZm	Z	dd	�Z3d4d�Z		dd
d�Z	ddd�Z
dS)zwUtilities to get the response values of a classifier or a regressor.5 6It allows to make uniform checks and validation.7�N�)�
is_classifier�)�type_of_target)�_check_response_method�check_is_fittedcCs�|dkr|jddkrtd|j�d���|dkr)t�||k�d}|dd�|fS|dkr?t|t�r=t�d	d8�|D��jS|S|S)a�Get the response values when the response method is `predict_proba`.9 10    This function process the `y_pred` array in the binary and multi-label cases.11    In the binary case, it selects the column corresponding to the positive12    class. In the multi-label case, it stacks the predictions if they are not13    in the "compressed" format `(n_samples, n_outputs)`.14 15    Parameters16    ----------17    y_pred : ndarray18        Output of `estimator.predict_proba`. The shape depends on the target type:19 20        - for binary classification, it is a 2d array of shape `(n_samples, 2)`;21        - for multiclass classification, it is a 2d array of shape22          `(n_samples, n_classes)`;23        - for multilabel classification, it is either a list of 2d arrays of shape24          `(n_samples, 2)` (e.g. `RandomForestClassifier` or `KNeighborsClassifier`) or25          an array of shape `(n_samples, n_outputs)` (e.g. `MLPClassifier` or26          `RidgeClassifier`).27 28    target_type : {"binary", "multiclass", "multilabel-indicator"}29        Type of the target.30 31    classes : ndarray of shape (n_classes,) or list of such arrays32        Class labels as reported by `estimator.classes_`.33 34    pos_label : int, float, bool or str35        Only used with binary and multiclass targets.36 37    Returns38    -------39    y_pred : ndarray of shape (n_samples,), (n_samples, n_classes) or             (n_samples, n_output)40        Compressed predictions format as requested by the metrics.41    �binaryrrzGot predict_proba of shape z', but need classifier with two classes.rNzmultilabel-indicatorcSsg|]42}|dd�df�qS)N������)�.0�pr43r44��E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\sklearn/utils/_response.py�45<listcomp>Dsz*_process_predict_proba.<locals>.<listcomp>)�shape�46ValueError�npZflatnonzero�47isinstance�listZvstack�T)�y_pred�target_type�classes�	pos_labelZcol_idxr48r49r
�_process_predict_probas$�50rcCs |dkr||dkrd|S|S)a{Get the response values when the response method is `decision_function`.51 52    This function process the `y_pred` array in the binary and multi-label cases.53    In the binary case, it inverts the sign of the score if the positive label54    is not `classes[1]`. In the multi-label case, it stacks the predictions if55    they are not in the "compressed" format `(n_samples, n_outputs)`.56 57    Parameters58    ----------59    y_pred : ndarray60        Output of `estimator.decision_function`. The shape depends on the target type:61 62        - for binary classification, it is a 1d array of shape `(n_samples,)` where the63          sign is assuming that `classes[1]` is the positive class;64        - for multiclass classification, it is a 2d array of shape65          `(n_samples, n_classes)`;66        - for multilabel classification, it is a 2d array of shape `(n_samples,67          n_outputs)`.68 69    target_type : {"binary", "multiclass", "multilabel-indicator"}70        Type of the target.71 72    classes : ndarray of shape (n_classes,) or list of such arrays73        Class labels as reported by `estimator.classes_`.74 75    pos_label : int, float, bool or str76        Only used with binary and multiclass targets.77 78    Returns79    -------80    y_pred : ndarray of shape (n_samples,), (n_samples, n_classes) or             (n_samples, n_output)81        Compressed predictions format as requested by the metrics.82    rrr	r83�rrrrr84r85r
�_process_decision_functionLs#rFcCs,ddlm}m}||�r\t||�}|j}t|�}	|	dvr<|dur0||��vr0td|�d|����|dur<|	dkr<|d}||�}86|jd	vrNt	|87|	||d88�}89n<|jdkr[t90|91|	||d92�}93n.||�rmt||�}||�d}94}n|dkr�t|jj�d
|�d|�d���|j}||�d}95}|r�|96||jfS|97|fS)aCompute the response values of a classifier, an outlier detector, or a regressor.98 99    The response values are predictions such that it follows the following shape:100 101    - for binary classification, it is a 1d array of shape `(n_samples,)`;102    - for multiclass classification, it is a 2d array of shape `(n_samples, n_classes)`;103    - for multilabel classification, it is a 2d array of shape `(n_samples, n_outputs)`;104    - for outlier detection, it is a 1d array of shape `(n_samples,)`;105    - for regression, it is a 1d array of shape `(n_samples,)`.106 107    If `estimator` is a binary classifier, also return the label for the108    effective positive class.109 110    This utility is used primarily in the displays and the scikit-learn scorers.111 112    .. versionadded:: 1.3113 114    Parameters115    ----------116    estimator : estimator instance117        Fitted classifier, outlier detector, or regressor or a118        fitted :class:`~sklearn.pipeline.Pipeline` in which the last estimator is a119        classifier, an outlier detector, or a regressor.120 121    X : {array-like, sparse matrix} of shape (n_samples, n_features)122        Input values.123 124    response_method : {"predict_proba", "predict_log_proba", "decision_function",             "predict"} or list of such str125        Specifies the response method to use get prediction from an estimator126        (i.e. :term:`predict_proba`, :term:`predict_log_proba`,127        :term:`decision_function` or :term:`predict`). Possible choices are:128 129        - if `str`, it corresponds to the name to the method to return;130        - if a list of `str`, it provides the method names in order of131          preference. The method returned corresponds to the first method in132          the list and which is implemented by `estimator`.133 134    pos_label : int, float, bool or str, default=None135        The class considered as the positive class when computing136        the metrics. If `None` and target is 'binary', `estimators.classes_[1]` is137        considered as the positive class.138 139    return_response_method_used : bool, default=False140        Whether to return the response method used to compute the response141        values.142 143        .. versionadded:: 1.4144 145    Returns146    -------147    y_pred : ndarray of shape (n_samples,), (n_samples, n_classes) or             (n_samples, n_outputs)148        Target scores calculated from the provided `response_method`149        and `pos_label`.150 151    pos_label : int, float, bool, str or None152        The class considered as the positive class when computing153        the metrics. Returns `None` if `estimator` is a regressor or an outlier154        detector.155 156    response_method_used : str157        The response method used to compute the response values. Only returned158        if `return_response_method_used` is `True`.159 160        .. versionadded:: 1.4161 162    Raises163    ------164    ValueError165        If `pos_label` is not a valid label.166        If the shape of `y_pred` is not consistent for binary classifier.167        If the response method can be applied to a classifier only and168        `estimator` is a regressor.169    r)r�is_outlier_detector)r�170multiclassNz171pos_label=z+ is not a valid label: It should be one of rr	)�
predict_probaZpredict_log_probar�decision_function�predictz? should either be a classifier to be used with response_method=zR or the response_method should be 'predict'. Got a regressor with response_method=�	 instead.)
Zsklearn.baserrr�classes_r�tolistr�__name__rr�	__class__r )�	estimator�X�response_methodr�return_response_method_usedrrZprediction_methodrrrr172r173r
�_get_response_valuests\R174��175�176��177178���r*cCsvd}t|�t|�st|d|jj�d���t|j�dkr*t|dt|j��d���|dkr2ddg}t|||||d	�S)179aCompute the response values of a binary classifier.180 181    Parameters182    ----------183    estimator : estimator instance184        Fitted classifier or a fitted :class:`~sklearn.pipeline.Pipeline`185        in which the last estimator is a binary classifier.186 187    X : {array-like, sparse matrix} of shape (n_samples, n_features)188        Input values.189 190    response_method : {'auto', 'predict_proba', 'decision_function'}191        Specifies whether to use :term:`predict_proba` or192        :term:`decision_function` as the target response. If set to 'auto',193        :term:`predict_proba` is tried first and if it does not exist194        :term:`decision_function` is tried next.195 196    pos_label : int, float, bool or str, default=None197        The class considered as the positive class when computing198        the metrics. By default, `estimators.classes_[1]` is199        considered as the positive class.200 201    return_response_method_used : bool, default=False202        Whether to return the response method used to compute the response203        values.204 205        .. versionadded:: 1.5206 207    Returns208    -------209    y_pred : ndarray of shape (n_samples,)210        Target scores calculated from the provided response_method211        and pos_label.212 213    pos_label : int, float, bool or str214        The class considered as the positive class when computing215        the metrics.216 217    response_method_used : str218        The response method used to compute the response values. Only returned219        if `return_response_method_used` is `True`.220 221        .. versionadded:: 1.5222    z/Expected 'estimator' to be a binary classifier.z Got r!rz classes instead.�autorr)rr))rrrr%r$�lenr"r*)r&r'r(rr)Zclassification_errorr223r224r
�_get_response_values_binary�s&/���r-)NF)�__doc__�numpyr�baserrrZ225validationrrrrr*r-r226r227r228r
�<module>s<,229��
Aluode/PerceptionLabPortable · CoolFace