U
    eB                     @   s2   d dl ZddlmZ ddlmZ G dd dZdS )    N   )learning_curve   )check_matplotlib_supportc                   @   s   e Zd ZdZddddZdddddddddd	d
dZededddddddddddej	dddddddddddddZ
dS )LearningCurveDisplaya
  Learning Curve visualization.

    It is recommended to use
    :meth:`~sklearn.model_selection.LearningCurveDisplay.from_estimator` to
    create a :class:`~sklearn.model_selection.LearningCurveDisplay` instance.
    All parameters are stored as attributes.

    Read more in the :ref:`User Guide <visualizations>`.

    .. versionadded:: 1.2

    Parameters
    ----------
    train_sizes : ndarray of shape (n_unique_ticks,)
        Numbers of training examples that has been used to generate the
        learning curve.

    train_scores : ndarray of shape (n_ticks, n_cv_folds)
        Scores on training sets.

    test_scores : ndarray of shape (n_ticks, n_cv_folds)
        Scores on test set.

    score_name : str, default=None
        The name of the score used in `learning_curve`. It will be used to
        decorate the y-axis. If `None`, the generic name `"Score"` will be
        used.

    Attributes
    ----------
    ax_ : matplotlib Axes
        Axes with the learning curve.

    figure_ : matplotlib Figure
        Figure containing the learning curve.

    errorbar_ : list of matplotlib Artist or None
        When the `std_display_style` is `"errorbar"`, this is a list of
        `matplotlib.container.ErrorbarContainer` objects. If another style is
        used, `errorbar_` is `None`.

    lines_ : list of matplotlib Artist or None
        When the `std_display_style` is `"fill_between"`, this is a list of
        `matplotlib.lines.Line2D` objects corresponding to the mean train and
        test scores. If another style is used, `line_` is `None`.

    fill_between_ : list of matplotlib Artist or None
        When the `std_display_style` is `"fill_between"`, this is a list of
        `matplotlib.collections.PolyCollection` objects. If another style is
        used, `fill_between_` is `None`.

    See Also
    --------
    sklearn.model_selection.learning_curve : Compute the learning curve.

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> from sklearn.datasets import load_iris
    >>> from sklearn.model_selection import LearningCurveDisplay, learning_curve
    >>> from sklearn.tree import DecisionTreeClassifier
    >>> X, y = load_iris(return_X_y=True)
    >>> tree = DecisionTreeClassifier(random_state=0)
    >>> train_sizes, train_scores, test_scores = learning_curve(
    ...     tree, X, y)
    >>> display = LearningCurveDisplay(train_sizes=train_sizes,
    ...     train_scores=train_scores, test_scores=test_scores, score_name="Score")
    >>> display.plot()
    <...>
    >>> plt.show()
    N)
score_namec                C   s   || _ || _|| _|| _d S )Ntrain_sizestrain_scorestest_scoresr   )selfr	   r
   r   r    r   ^/var/www/html/assets/scripts/venv/lib/python3.8/site-packages/sklearn/model_selection/_plot.py__init__P   s    zLearningCurveDisplay.__init__Ftestfill_between)negate_scorer   
score_type	log_scalestd_display_styleline_kwfill_between_kwerrorbar_kwc             
   C   sh  t | jj d ddlm}
 |dkr2|
 \}}|rJ| j | j  }}n| j| j }}|dkrptd| d|dkrtd| d	|d
krd|i}n|dkrd|i}n
||d}|dkr|dkri }g | _	|
 D ]2\}}| j	j|j| j|jddfd|i|  qd| _d| _|dkr|	dkr2i }	g | _|
 D ]>\}}| j|j| j|jdd|jddfd|i|	 q@d\| _	| _n|dkr|dkri }ddi}||}g | _|
 D ]N\}}| j|j| j|jdd|jdd |jdd|jdd f| q|dkr$| jn|}|  |r@|d |d ||  || _|j| _| S )a;  Plot visualization.

        Parameters
        ----------
        ax : matplotlib Axes, default=None
            Axes object to plot on. If `None`, a new figure and axes is
            created.

        negate_score : bool, default=False
            Whether or not to negate the scores obtained through
            :func:`~sklearn.model_selection.learning_curve`. This is
            particularly useful when using the error denoted by `neg_*` in
            `scikit-learn`.

        score_name : str, default=None
            The name of the score used to decorate the y-axis of the plot. If
            `None`, the generic name "Score" will be used.

        score_type : {"test", "train", "both"}, default="test"
            The type of score to plot. Can be one of `"test"`, `"train"`, or
            `"both"`.

        log_scale : bool, default=False
            Whether or not to use a logarithmic scale for the x-axis.

        std_display_style : {"errorbar", "fill_between"} or None, default="fill_between"
            The style used to display the score standard deviation around the
            mean score. If None, no standard deviation representation is
            displayed.

        line_kw : dict, default=None
            Additional keyword arguments passed to the `plt.plot` used to draw
            the mean score.

        fill_between_kw : dict, default=None
            Additional keyword arguments passed to the `plt.fill_between` used
            to draw the score standard deviation.

        errorbar_kw : dict, default=None
            Additional keyword arguments passed to the `plt.errorbar` used to
            draw mean score and standard deviation score.

        Returns
        -------
        display : :class:`~sklearn.model_selection.LearningCurveDisplay`
            Object that stores computed values.
        z.plotr   N)errorbarr   NzUnknown std_display_style: z7. Should be one of 'errorbar', 'fill_between', or None.)r   trainZbothzUnknown score_type: z.. Should be one of 'test', 'train', or 'both'.r   Training metricr   Testing metric)r   r   )r   Nr   )Zaxislabelr   )NNr   alphag      ?logz%Number of samples in the training set)r   	__class____name__Zmatplotlib.pyplotZpyplotZsubplotsr
   r   
ValueErrorZlines_itemsappendplotr	   ZmeanZ	errorbar_Zfill_between_r   Zstdr   r   ZlegendZ
set_xscaleZ
set_xlabelZ
set_ylabelZax_ZfigureZfigure_)r   axr   r   r   r   r   r   r   r   Zplt_r
   r   ZscoresZ
line_labelZscoreZdefault_fill_between_kwr   r   r   r%   V   s    <










	

	

zLearningCurveDisplay.plotg?g      ?   allr   )groupsr	   cvscoringexploit_incremental_learningn_jobspre_dispatchverboseshufflerandom_stateerror_score
fit_paramsr&   r   r   r   r   r   r   r   r   c                C   sx   t | j d |dkrdn|}t|||||||||	|
||||d|d\}}}| ||||d}|j||||||||dS )a;  Create a learning curve display from an estimator.

        Parameters
        ----------
        estimator : object type that implements the "fit" and "predict" methods
            An object of that type which is cloned for each validation.

        X : array-like of shape (n_samples, n_features)
            Training data, where `n_samples` is the number of samples and
            `n_features` is the number of features.

        y : array-like of shape (n_samples,) or (n_samples, n_outputs) or None
            Target relative to X for classification or regression;
            None for unsupervised learning.

        groups : array-like of shape (n_samples,), default=None
            Group labels for the samples used while splitting the dataset into
            train/test set. Only used in conjunction with a "Group" :term:`cv`
            instance (e.g., :class:`GroupKFold`).

        train_sizes : array-like of shape (n_ticks,),                 default=np.linspace(0.1, 1.0, 5)
            Relative or absolute numbers of training examples that will be used
            to generate the learning curve. If the dtype is float, it is
            regarded as a fraction of the maximum size of the training set
            (that is determined by the selected validation method), i.e. it has
            to be within (0, 1]. Otherwise it is interpreted as absolute sizes
            of the training sets. Note that for classification the number of
            samples usually have to be big enough to contain at least one
            sample from each class.

        cv : int, cross-validation generator or an iterable, default=None
            Determines the cross-validation splitting strategy.
            Possible inputs for cv are:

            - None, to use the default 5-fold cross validation,
            - int, to specify the number of folds in a `(Stratified)KFold`,
            - :term:`CV splitter`,
            - An iterable yielding (train, test) splits as arrays of indices.

            For int/None inputs, if the estimator is a classifier and `y` is
            either binary or multiclass,
            :class:`~sklearn.model_selection.StratifiedKFold` is used. In all
            other cases, :class:`~sklearn.model_selectionKFold` is used. These
            splitters are instantiated with `shuffle=False` so the splits will
            be the same across calls.

            Refer :ref:`User Guide <cross_validation>` for the various
            cross-validation strategies that can be used here.

        scoring : str or callable, default=None
            A string (see :ref:`scoring_parameter`) or
            a scorer callable object / function with signature
            `scorer(estimator, X, y)` (see :ref:`scoring`).

        exploit_incremental_learning : bool, default=False
            If the estimator supports incremental learning, this will be
            used to speed up fitting for different training set sizes.

        n_jobs : int, default=None
            Number of jobs to run in parallel. Training the estimator and
            computing the score are parallelized over the different training
            and test sets. `None` means 1 unless in a
            :obj:`joblib.parallel_backend` context. `-1` means using all
            processors. See :term:`Glossary <n_jobs>` for more details.

        pre_dispatch : int or str, default='all'
            Number of predispatched jobs for parallel execution (default is
            all). The option can reduce the allocated memory. The str can
            be an expression like '2*n_jobs'.

        verbose : int, default=0
            Controls the verbosity: the higher, the more messages.

        shuffle : bool, default=False
            Whether to shuffle training data before taking prefixes of it
            based on`train_sizes`.

        random_state : int, RandomState instance or None, default=None
            Used when `shuffle` is True. Pass an int for reproducible
            output across multiple function calls.
            See :term:`Glossary <random_state>`.

        error_score : 'raise' or numeric, default=np.nan
            Value to assign to the score if an error occurs in estimator
            fitting. If set to 'raise', the error is raised. If a numeric value
            is given, FitFailedWarning is raised.

        fit_params : dict, default=None
            Parameters to pass to the fit method of the estimator.

        ax : matplotlib Axes, default=None
            Axes object to plot on. If `None`, a new figure and axes is
            created.

        negate_score : bool, default=False
            Whether or not to negate the scores obtained through
            :func:`~sklearn.model_selection.learning_curve`. This is
            particularly useful when using the error denoted by `neg_*` in
            `scikit-learn`.

        score_name : str, default=None
            The name of the score used to decorate the y-axis of the plot.
            If `None`, the generic `"Score"` name will be used.

        score_type : {"test", "train", "both"}, default="test"
            The type of score to plot. Can be one of `"test"`, `"train"`, or
            `"both"`.

        log_scale : bool, default=False
            Whether or not to use a logarithmic scale for the x-axis.

        std_display_style : {"errorbar", "fill_between"} or None, default="fill_between"
            The style used to display the score standard deviation around the
            mean score. If `None`, no representation of the standard deviation
            is displayed.

        line_kw : dict, default=None
            Additional keyword arguments passed to the `plt.plot` used to draw
            the mean score.

        fill_between_kw : dict, default=None
            Additional keyword arguments passed to the `plt.fill_between` used
            to draw the score standard deviation.

        errorbar_kw : dict, default=None
            Additional keyword arguments passed to the `plt.errorbar` used to
            draw mean score and standard deviation score.

        Returns
        -------
        display : :class:`~sklearn.model_selection.LearningCurveDisplay`
            Object that stores computed values.

        Examples
        --------
        >>> import matplotlib.pyplot as plt
        >>> from sklearn.datasets import load_iris
        >>> from sklearn.model_selection import LearningCurveDisplay
        >>> from sklearn.tree import DecisionTreeClassifier
        >>> X, y = load_iris(return_X_y=True)
        >>> tree = DecisionTreeClassifier(random_state=0)
        >>> LearningCurveDisplay.from_estimator(tree, X, y)
        <...>
        >>> plt.show()
        z.from_estimatorNZScoreF)r*   r	   r+   r,   r-   r.   r/   r0   r1   r2   r3   Zreturn_timesr4   r   )r&   r   r   r   r   r   r   r   )r   r!   r   r%   )clsZ	estimatorXyr*   r	   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r&   r   r   r   r   r   r   r   r   r
   r   Zvizr   r   r   from_estimator   sJ     0z#LearningCurveDisplay.from_estimator)N)r!   
__module____qualname____doc__r   r%   classmethodnpZlinspacenanr8   r   r   r   r   r      sJ   H  r   )numpyr=    r   utilsr   r   r   r   r   r   <module>   s   