
    0Ph#                       d Z ddlZddlZddlmZ ddlmZmZ ddlZddl	m
Z ddlmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZmZmZ ddlmZ d Z e eeddd          g eeddd          g eeddd          g eeddd          g eeddd          g eeddd          g eeddd          gddg eeddd          g eeddd          gdg eeddd          ddg eeddd          ddgdgdgdd          	 	 d]ddddddddddddddd            Z e eeddd          g eeddd          g eeddd          g eeddd          g eeddd          gdgdg edd h          dgdgdgd!
d          	 	 d]d"dd#dd$dd$dd%d&            Z e eeddd          gdgd'd          d^dd)d*            Z e eeddd          g eeddd          g eeddd          g eeddd          g eeddd          g eeddd          dg eeddd          g eeddd          gdgdgdgd+d          	 	 d_d,dddd-ddd$dd.	d/            Z e eeddd          e gdg eeddd          dgdg eeddd          gd0d          	 d`dddd1d2d3            Z! e eeddd          e gdg eeddd          dgdgd4d          d`dddd5d6            Z" e eeddd          dg eeddd          g eeddd          ddg eeddd          dge gdgdgdgd7d          	 	 daddd8ddd$d9d:            Z# e eeddd          g eed"dd          g eeddd          gdgd;d          dbddd<d=            Z$ e eeddd          g eeddd          gdgd>d          d`ddd<d?            Z% e eeddd          g eeddd          gdgd>d          d`ddd<d@            Z& e eeddd          g eeddd          g eeddd          g eeddd          gdgdAd          	 	 d_d,d-ddBdC            Z' e eeddd          g eeddd          g eeddd          g eeddd          gdgdDd          dd)dE            Z( e eeddd          g eeddd          gdgdFd          dbdd)dG            Z) e eeddd          gdgdHd          dd)dI            Z* e eeddd          g eeddd          gdg eeddd          g eeddd          g eh dJ          dgdgdKd          	 dcdLd$dMdNdddOdP            Z+ e eeddd          g eeddd          gdgdgdQd          d`ddd$dRdS            Z, e eeddd          g eeddd          gdgd>d          d`ddd<dT            Z- eddg eeddd          g eeddd          g eeddd          g eeddd          gdgdgdUd          dddddVdddUdW            Z.dddXZ/ ee g eeddd          g eeddd          g eeddd          g eeddd          gdgdgdYd          dd,ddddZd[            Z0 ee g eeddd          dg eeddd          g eeddd          g eeddd          gdgdgdYd          dd,ddddZd\            Z1dS )ez*
Generate samples of synthetic data sets.
    N)Iterable)IntegralReal)linalg   )MultiLabelBinarizer)check_arraycheck_random_state)shuffle)Interval
StrOptionsvalidate_params)sample_without_replacementc                 r   |dk    r?t          j        |                    d| |dz
  f          t          | d|          g          S t	          d|z  | |                              dd          }t          j        |                    d                                        d	          d
d
| d
f         }|S )z5Returns distinct binary samples of length dimensions.   r   sizerandom_statez>u4F)dtypecopyz>u1)    N)	nphstackrandint_generate_hypercuber   astype
unpackbitsviewreshape)samples
dimensionsrngouts       c/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/datasets/_samples_generator.pyr   r      s    ByAWj2o$>??#GR55
 
 	
 %Q
]G#
N
N
N
U
U% V  C -
(
(
0
0
:
:111zkll?
KCJ       left)closedz
array-likebothneitherbooleanr   )	n_samples
n_featuresn_informativen_redundant
n_repeated	n_classesn_clusters_per_classweightsflip_y	class_sep	hypercubeshiftscaler   r   T)prefer_skip_nested_validationd      g{Gz?      ?        )r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r   r   c          	       	    t          |          }||z   |z   |k    rt          d          |t          j        z            k     r/d}|dz  }t          |                    |d|z                      t                    dz
  fvrt          d          t                    dz
  k    r^t          t                    rdt                    z
  gz   n<t          j	                  dt          dd	                   z
  d	<   n	dz  gz  ||z
  |z
  |z
  }z  } fd
t          |          D             }t           t          |          z
            D ]}|||z  xx         dz  cc<   t          j         |f          }t          j         t                    }t          |||                              t          d          }|d|	z  z  }||	z  }|
s6||                    |df          z  }||                    d|f          z  }|                     |f          |ddd|f<   d}t%          |          D ]e\  }}||||         z   }}|z  |||<   |||d|f         }d|                    ||f          z  dz
  }t          j        ||          |d<   ||z  }f|dk    rKd|                    ||f          z  dz
  }t          j        |ddd|f         |          |dd|||z   f<   |dk    rY||z   }|dz
  |                    |          z  dz                       t          j                  } |dd| f         |dd|||z   f<   |dk    r"|                     |f          |dd| df<   |dk    rF|                               |k     }!|                    |!                                          ||!<   |d|                    |          z  dz
  |	z  }||z  }|dd|                    |          z  z   }||z  }|rSt-          |||          \  }}t          j        |          } |                    |            |dd| f         |ddddf<   ||fS )a  Generate a random n-class classification problem.

    This initially creates clusters of points normally distributed (std=1)
    about vertices of an ``n_informative``-dimensional hypercube with sides of
    length ``2*class_sep`` and assigns an equal number of clusters to each
    class. It introduces interdependence between these features and adds
    various types of further noise to the data.

    Without shuffling, ``X`` horizontally stacks features in the following
    order: the primary ``n_informative`` features, followed by ``n_redundant``
    linear combinations of the informative features, followed by ``n_repeated``
    duplicates, drawn randomly with replacement from the informative and
    redundant features. The remaining features are filled with random noise.
    Thus, without shuffling, all useful features are contained in the columns
    ``X[:, :n_informative + n_redundant + n_repeated]``.

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

    Parameters
    ----------
    n_samples : int, default=100
        The number of samples.

    n_features : int, default=20
        The total number of features. These comprise ``n_informative``
        informative features, ``n_redundant`` redundant features,
        ``n_repeated`` duplicated features and
        ``n_features-n_informative-n_redundant-n_repeated`` useless features
        drawn at random.

    n_informative : int, default=2
        The number of informative features. Each class is composed of a number
        of gaussian clusters each located around the vertices of a hypercube
        in a subspace of dimension ``n_informative``. For each cluster,
        informative features are drawn independently from  N(0, 1) and then
        randomly linearly combined within each cluster in order to add
        covariance. The clusters are then placed on the vertices of the
        hypercube.

    n_redundant : int, default=2
        The number of redundant features. These features are generated as
        random linear combinations of the informative features.

    n_repeated : int, default=0
        The number of duplicated features, drawn randomly from the informative
        and the redundant features.

    n_classes : int, default=2
        The number of classes (or labels) of the classification problem.

    n_clusters_per_class : int, default=2
        The number of clusters per class.

    weights : array-like of shape (n_classes,) or (n_classes - 1,),              default=None
        The proportions of samples assigned to each class. If None, then
        classes are balanced. Note that if ``len(weights) == n_classes - 1``,
        then the last class weight is automatically inferred.
        More than ``n_samples`` samples may be returned if the sum of
        ``weights`` exceeds 1. Note that the actual class proportions will
        not exactly match ``weights`` when ``flip_y`` isn't 0.

    flip_y : float, default=0.01
        The fraction of samples whose class is assigned randomly. Larger
        values introduce noise in the labels and make the classification
        task harder. Note that the default setting flip_y > 0 might lead
        to less than ``n_classes`` in y in some cases.

    class_sep : float, default=1.0
        The factor multiplying the hypercube size.  Larger values spread
        out the clusters/classes and make the classification task easier.

    hypercube : bool, default=True
        If True, the clusters are put on the vertices of a hypercube. If
        False, the clusters are put on the vertices of a random polytope.

    shift : float, ndarray of shape (n_features,) or None, default=0.0
        Shift features by the specified value. If None, then features
        are shifted by a random value drawn in [-class_sep, class_sep].

    scale : float, ndarray of shape (n_features,) or None, default=1.0
        Multiply features by the specified value. If None, then features
        are scaled by a random value drawn in [1, 100]. Note that scaling
        happens after shifting.

    shuffle : bool, default=True
        Shuffle the samples and the features.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset creation. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    X : ndarray of shape (n_samples, n_features)
        The generated samples.

    y : ndarray of shape (n_samples,)
        The integer labels for class membership of each sample.

    See Also
    --------
    make_blobs : Simplified variant.
    make_multilabel_classification : Unrelated generator for multilabel tasks.

    Notes
    -----
    The algorithm is adapted from Guyon [1] and was designed to generate
    the "Madelon" dataset.

    References
    ----------
    .. [1] I. Guyon, "Design of experiments for the NIPS 2003 variable
           selection benchmark", 2003.

    Examples
    --------
    >>> from sklearn.datasets import make_classification
    >>> X, y = make_classification(random_state=42)
    >>> X.shape
    (100, 20)
    >>> y.shape
    (100,)
    >>> list(y[:5])
    [np.int64(0), np.int64(0), np.int64(1), np.int64(1), np.int64(0)]
    ziNumber of informative, redundant and repeated features must sum to less than the number of total featuresz0n_classes({}) * n_clusters_per_class({}) must bez) smaller or equal 2**n_informative({})={}r   Nr(   z:Weights specified but incompatible with number of classes.r>   r   c                 L    g | ] }t          |z           z  z            !S  )int).0kr3   r4   r.   r5   s     r&   
<listcomp>z'make_classification.<locals>.<listcomp>   sE        	II..1EEFF  r'   r   Fr   r   r   .      ?r?   r<   r   )r
   
ValueErrorr   log2formatlen
isinstancelistsumresizerangezerosrC   r   r   floatuniformstandard_normal	enumeratedotintpr   util_shufflearanger   )"r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r   r   	generatormsg	n_useless
n_clustersn_samples_per_clusteriXy	centroidsstoprE   centroidstartX_kABnindices	flip_masks"   `    ```                          r&   make_classificationrn   (   s   J #<00I {"Z/*<<
 
 	
 rwy+??@@@@@::JJy"6q-GWXX
 
 	
 w<<	9q=999L   w<<9q=(('4(( 6!S3w<<%7$88)GY77!C$5$55?#i/]*[8:EI11J      z""  
 9s#8999:: 3 3a*n---2---- 	)Z())A
#&&&A $JyIIPPE Q  I YII @Y&&ZO&<<<	Y&&Q,>&???	 %449m:T4UUAaaa- D ++  8D#8#;;tI%*d
N]N*+	!!}'E!FFFJ6#q>>Cx Q	!!{'C!DDDqH<>Faaa- !=
 =
!!!]][88
89
 A~~K'EY..J.???#EMMbgVV#$QQQZ=!!!QZ
  1}}%55Iy;Q5RR!!!iZ[[. }}%%9%55>	 (((II) }Y&&J&777!;yHJA}C)+++<<<<JA  Aqy9991 )J'''"""AAAwJ-!!!QQQ$a4Kr'   densesparse)
r.   r/   r3   n_labelslengthallow_unlabeledrp   return_indicatorreturn_distributionsr      2   F)r3   rq   rr   rs   rp   rt   ru   r   c                   t          |	                              |          }
|
|
                                z  }
t          j        |
                              |f          t          j        d          z  fd}t          j        d          }t          j        ddg          }g }t          |           D ][} |            \  }}|                    |           |                    t          |                     |                    |           \t          j
        t          |          t          j                  }t          j        |||f| f          }|                                 |s|                                }|dv rJt!          |d	k    
          }|                    t          |          g                              |          }|r|||
fS ||fS )a`  Generate a random multilabel classification problem.

    For each sample, the generative process is:
        - pick the number of labels: n ~ Poisson(n_labels)
        - n times, choose a class c: c ~ Multinomial(theta)
        - pick the document length: k ~ Poisson(length)
        - k times, choose a word: w ~ Multinomial(theta_c)

    In the above process, rejection sampling is used to make sure that
    n is never zero or more than `n_classes`, and that the document length
    is never zero. Likewise, we reject classes which have already been chosen.

    For an example of usage, see
    :ref:`sphx_glr_auto_examples_datasets_plot_random_multilabel_dataset.py`.

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

    Parameters
    ----------
    n_samples : int, default=100
        The number of samples.

    n_features : int, default=20
        The total number of features.

    n_classes : int, default=5
        The number of classes of the classification problem.

    n_labels : int, default=2
        The average number of labels per instance. More precisely, the number
        of labels per sample is drawn from a Poisson distribution with
        ``n_labels`` as its expected value, but samples are bounded (using
        rejection sampling) by ``n_classes``, and must be nonzero if
        ``allow_unlabeled`` is False.

    length : int, default=50
        The sum of the features (number of words if documents) is drawn from
        a Poisson distribution with this expected value.

    allow_unlabeled : bool, default=True
        If ``True``, some instances might not belong to any class.

    sparse : bool, default=False
        If ``True``, return a sparse feature matrix.

        .. versionadded:: 0.17
           parameter to allow *sparse* output.

    return_indicator : {'dense', 'sparse'} or False, default='dense'
        If ``'dense'`` return ``Y`` in the dense binary indicator format. If
        ``'sparse'`` return ``Y`` in the sparse binary indicator format.
        ``False`` returns a list of lists of labels.

    return_distributions : bool, default=False
        If ``True``, return the prior class probability and conditional
        probabilities of features given classes, from which the data was
        drawn.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset creation. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    X : ndarray of shape (n_samples, n_features)
        The generated samples.

    Y : {ndarray, sparse matrix} of shape (n_samples, n_classes)
        The label sets. Sparse matrix should be of CSR format.

    p_c : ndarray of shape (n_classes,)
        The probability of each class being drawn. Only returned if
        ``return_distributions=True``.

    p_w_c : ndarray of shape (n_features, n_classes)
        The probability of each feature being drawn given each class.
        Only returned if ``return_distributions=True``.

    Examples
    --------
    >>> from sklearn.datasets import make_multilabel_classification
    >>> X, y = make_multilabel_classification(n_labels=3, random_state=42)
    >>> X.shape
    (100, 20)
    >>> y.shape
    (100, 5)
    >>> list(y[:3])
    [array([1, 1, 0, 1, 0]), array([0, 1, 1, 1, 0]), array([0, 1, 0, 0, 0])]
    r   r   axisc            	      2   j         \  } }|dz   }s|dk    s||k    r#
                              }s|dk    ||k    #t                      }t          |          |k    rat	          j        	
                    |t          |          z
                      }|                    |           t          |          |k    at          |          }d}|dk    r
                              }|dk    t          |          dk    r
	                    |          }||fS 
                    |d                              d                                          }||d         z  }t	          j        |
                    |                    }||fS )Nr(   r   r   ry   r   )shapepoissonsetrM   r   searchsortedrU   updaterO   r   takerP   cumsum)_r3   y_sizerc   cn_wordswordscumulative_p_w_samplers   cumulative_p_cr\   rr   r/   rq   p_w_cs           r&   sample_examplez6make_multilabel_classification.<locals>.sample_example  s   {9 Q" 	1v{{v	7I7I&&x00F # 	1v{{v	7I7I EE!ff	0A0AvPSTUPVPV0A0W0WXXAHHQKKK !ff GG ll''//G ll q66Q;;%%jw%??E!8O !&

11
 5 5 9 9q 9 A A H H J J!6r!:: 5y7H7Hg7H7V7VWWaxr'   ra   rG   )r|   )Trp   ro   rp   )sparse_output)r
   rU   rP   r   r   arrayrR   extendappendrM   onesfloat64sp
csr_matrixsum_duplicatestoarrayr   fit	transform)r.   r/   r3   rq   rr   rs   rp   rt   ru   r   p_cr   	X_indicesX_indptrYra   r   rc   X_datarb   lbr   r\   r   s    ` ```               @@@r&   make_multilabel_classificationr   @  s   n #<00I




+
+C37799CYs^^NJ	#:;;E	RVE""""E          B C  I{3$$H
A9  !>##qI'''	WS^^2:666F
vy(3Iz;RSSSA IIKK 444 0@H0LNNNFFE)$$%&&0033  !S%a4Kr'   )r.   r   .  r   c                   t          |          }| df}|                    |                              |          }|dz                      d          dk                        t
          j        d          }d	||d
k    <   ||fS )ai  Generate data for binary classification used in Hastie et al. 2009, Example 10.2.

    The ten features are standard independent Gaussian and
    the target ``y`` is defined by::

      y[i] = 1 if np.sum(X[i] ** 2) > 9.34 else -1

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

    Parameters
    ----------
    n_samples : int, default=12000
        The number of samples.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset creation. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    X : ndarray of shape (n_samples, 10)
        The input samples.

    y : ndarray of shape (n_samples,)
        The output values.

    See Also
    --------
    make_gaussian_quantiles : A generalization of this dataset approach.

    References
    ----------
    .. [1] T. Hastie, R. Tibshirani and J. Friedman, "Elements of Statistical
           Learning Ed. 2", Springer, 2009.

    Examples
    --------
    >>> from sklearn.datasets import make_hastie_10_2
    >>> X, y = make_hastie_10_2(n_samples=24000, random_state=42)
    >>> X.shape
    (24000, 10)
    >>> y.shape
    (24000,)
    >>> list(y[:5])
    [np.float64(-1.0), np.float64(1.0), np.float64(-1.0), np.float64(1.0),
    np.float64(-1.0)]
    
   r          @r(   ry   gGz"@FrH         r?   )r
   normalr!   rP   r   r   r   )r.   r   rsr|   rb   rc   s         r&   make_hastie_10_2r     s    p 
L	)	)BOE
		u	%%e,,A
S&1			$,,RZe,DDAAa3hKa4Kr'   )r.   r/   r0   	n_targetsbiaseffective_ranktail_strengthnoiser   coefr   r   rI   )	r0   r   r   r   r   r   r   r   r   c       	            t          ||          }t          |
          }||                    | |f          }nt          | ||||          }t	          j        ||f          }d|                    ||f          z  |d|ddf<   t	          j        ||          |z   }|dk    r||                    ||j	                  z  }|r[t          |||          \  }}t	          j        |          }|                    |           |dd|f         |ddddf<   ||         }t	          j        |          }|	r||t	          j        |          fS ||fS )aS  Generate a random regression problem.

    The input set can either be well conditioned (by default) or have a low
    rank-fat tail singular profile. See :func:`make_low_rank_matrix` for
    more details.

    The output is generated by applying a (potentially biased) random linear
    regression model with `n_informative` nonzero regressors to the previously
    generated input and some gaussian centered noise with some adjustable
    scale.

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

    Parameters
    ----------
    n_samples : int, default=100
        The number of samples.

    n_features : int, default=100
        The number of features.

    n_informative : int, default=10
        The number of informative features, i.e., the number of features used
        to build the linear model used to generate the output.

    n_targets : int, default=1
        The number of regression targets, i.e., the dimension of the y output
        vector associated with a sample. By default, the output is a scalar.

    bias : float, default=0.0
        The bias term in the underlying linear model.

    effective_rank : int, default=None
        If not None:
            The approximate number of singular vectors required to explain most
            of the input data by linear combinations. Using this kind of
            singular spectrum in the input allows the generator to reproduce
            the correlations often observed in practice.
        If None:
            The input set is well conditioned, centered and gaussian with
            unit variance.

    tail_strength : float, default=0.5
        The relative importance of the fat noisy tail of the singular values
        profile if `effective_rank` is not None. When a float, it should be
        between 0 and 1.

    noise : float, default=0.0
        The standard deviation of the gaussian noise applied to the output.

    shuffle : bool, default=True
        Shuffle the samples and the features.

    coef : bool, default=False
        If True, the coefficients of the underlying linear model are returned.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset creation. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    X : ndarray of shape (n_samples, n_features)
        The input samples.

    y : ndarray of shape (n_samples,) or (n_samples, n_targets)
        The output values.

    coef : ndarray of shape (n_features,) or (n_features, n_targets)
        The coefficient of the underlying linear model. It is returned only if
        coef is True.

    Examples
    --------
    >>> from sklearn.datasets import make_regression
    >>> X, y = make_regression(n_samples=5, n_features=2, noise=1, random_state=42)
    >>> X
    array([[ 0.4967..., -0.1382... ],
        [ 0.6476...,  1.523...],
        [-0.2341..., -0.2341...],
        [-0.4694...,  0.5425...],
        [ 1.579...,  0.7674...]])
    >>> y
    array([  6.737...,  37.79..., -10.27...,   0.4017...,   42.22...])
    Nr   r.   r/   r   r   r   r<   r?   r:   r   r   )minr
   rV   make_low_rank_matrixr   rS   rU   rX   r   r|   rZ   r[   r   squeeze)r.   r/   r0   r   r   r   r   r   r   r   r   r\   rb   ground_truthrc   rl   s                   r&   make_regressionr   8  s   h 
M22M"<00I%%Iz+B%CC !!)'"
 
 
 8Z344L&)I,=,=Y' -> - - 'L-"# 	q,$&A s{{	YE888  -Aqy9991)J'''"""AAAwJ-!!!QQQ$#G,

1A !RZ---- !tr'   )r.   r   r   r   factorg?)r   r   r   r   c                   t          | t          j                  r| dz  }| |z
  }n't          |           dk    rt	          d          | \  }}t          |          }t          j        ddt          j        z  |d          }t          j        ddt          j        z  |d          }	t          j	        |          }
t          j
        |          }t          j	        |	          |z  }t          j
        |	          |z  }t          j        t          j        |
|          t          j        ||          g          j        }t          j        t          j        |t          j                  t          j        |t          j                  g          }|rt%          |||          \  }}|||                    ||j        	          z  }||fS )
ah  Make a large circle containing a smaller circle in 2d.

    A simple toy dataset to visualize clustering and classification
    algorithms.

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

    Parameters
    ----------
    n_samples : int or tuple of shape (2,), dtype=int, default=100
        If int, it is the total number of points generated.
        For odd numbers, the inner circle will have one point more than the
        outer circle.
        If two-element tuple, number of points in outer circle and inner
        circle.

        .. versionchanged:: 0.23
           Added two-element tuple.

    shuffle : bool, default=True
        Whether to shuffle the samples.

    noise : float, default=None
        Standard deviation of Gaussian noise added to the data.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset shuffling and noise.
        Pass an int for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    factor : float, default=.8
        Scale factor between inner and outer circle in the range `[0, 1)`.

    Returns
    -------
    X : ndarray of shape (n_samples, 2)
        The generated samples.

    y : ndarray of shape (n_samples,)
        The integer labels (0 or 1) for class membership of each sample.

    Examples
    --------
    >>> from sklearn.datasets import make_circles
    >>> X, y = make_circles(random_state=42)
    >>> X.shape
    (100, 2)
    >>> y.shape
    (100,)
    >>> list(y[:5])
    [np.int64(1), np.int64(1), np.int64(1), np.int64(0), np.int64(0)]
    r   z7When a tuple, n_samples must have exactly two elements.r   F)endpointrG   r   Nr   )rN   numbersr   rM   rJ   r
   r   linspacepicossinvstackr   Tr   rS   rY   r   rZ   r   r|   )r.   r   r   r   r   n_samples_outn_samples_inr\   linspace_outlinspace_inouter_circ_xouter_circ_yinner_circ_xinner_circ_yrb   rc   s                   r&   make_circlesr     s   B )W-.. 0!Q =0y>>QVWWW&/#|"<00I;q!be)]UKKKL+aRUL5IIIK6,''L6,''L6+&&/L6+&&/L
		<	.	.	,0U0UV	 	  			-rw	/	/	/RW1U1U1UV	 	A  :Aqy9991	YE888a4Kr'   )r.   r   r   r   )r   r   r   c                   t          | t          j                  r| dz  }| |z
  }n)	 | \  }}n"# t          $ r}t          d          |d}~ww xY wt	          |          }t          j        t          j        dt
          j        |                    }t          j	        t          j        dt
          j        |                    }	dt          j        t          j        dt
          j        |                    z
  }
dt          j	        t          j        dt
          j        |                    z
  dz
  }t          j
        t          j        ||
          t          j        |	|          g          j        }t          j        t          j        |t
          j                  t          j        |t
          j                  g          }|rt#          |||          \  }}|||                    ||j        	          z  }||fS )
a%  Make two interleaving half circles.

    A simple toy dataset to visualize clustering and classification
    algorithms. Read more in the :ref:`User Guide <sample_generators>`.

    Parameters
    ----------
    n_samples : int or tuple of shape (2,), dtype=int, default=100
        If int, the total number of points generated.
        If two-element tuple, number of points in each of two moons.

        .. versionchanged:: 0.23
           Added two-element tuple.

    shuffle : bool, default=True
        Whether to shuffle the samples.

    noise : float, default=None
        Standard deviation of Gaussian noise added to the data.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset shuffling and noise.
        Pass an int for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    X : ndarray of shape (n_samples, 2)
        The generated samples.

    y : ndarray of shape (n_samples,)
        The integer labels (0 or 1) for class membership of each sample.

    Examples
    --------
    >>> from sklearn.datasets import make_moons
    >>> X, y = make_moons(n_samples=200, noise=0.2, random_state=42)
    >>> X.shape
    (200, 2)
    >>> y.shape
    (200,)
    r   z8`n_samples` can be either an int or a two-element tuple.Nr   r(   rI   rG   r   r   )rN   r   r   rJ   r
   r   r   r   r   r   r   r   r   r   rS   rY   r   rZ   r   r|   )r.   r   r   r   r   r   er\   r   r   r   r   rb   rc   s                 r&   
make_moonsr   >  s   j )W-.. 	!Q =0	*3'M<< 	 	 	J 	
 #<00I6"+a>>??L6"+a>>??Lrvbk!RULAABBBLrvbk!RULAABBBSHL
		<	.	.	,0U0UV	 	  			-rw	/	/	/RW1U1U1UV	 	A  :Aqy9991	YE888a4Ks   - 
AAA)r.   r/   centerscluster_std
center_boxr   r   return_centers)g      $g      $@)r   r   r   r   r   r   c                :   t          |          }t          | t          j                  rq|d}t          |t          j                  r)|}	|                    |d         |d         |	|f          }nt          |          }|j        d         }|j        d         }	nt          |           }	|&|                    |d         |d         |	|f          }t          |t                    s"t          d
                    |                    t          |          |	k    rt          d|  d|           t          |          }|j        d         }t          |d	          r6t          |          |	k    r#t          d

                    ||                    t          |t          j                  r"t          j        t          |          |          }t          | t                    r| }
n;t          | |	z            g|	z  }
t!          | |	z            D ]}|
|xx         dz  cc<   t          j        |
          }t          j        t'          |
          |ft          j                  }t          j        t'          |
          ft                    }t+          t-          |
|                    D ]O\  }\  }}|dk    r||dz
           nd}||         }|                    ||         |||f          |||<   ||||<   P|rt1          |||          \  }}|r|||fS ||fS )a
  Generate isotropic Gaussian blobs for clustering.

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

    Parameters
    ----------
    n_samples : int or array-like, default=100
        If int, it is the total number of points equally divided among
        clusters.
        If array-like, each element of the sequence indicates
        the number of samples per cluster.

        .. versionchanged:: v0.20
            one can now pass an array-like to the ``n_samples`` parameter

    n_features : int, default=2
        The number of features for each sample.

    centers : int or array-like of shape (n_centers, n_features), default=None
        The number of centers to generate, or the fixed center locations.
        If n_samples is an int and centers is None, 3 centers are generated.
        If n_samples is array-like, centers must be
        either None or an array of length equal to the length of n_samples.

    cluster_std : float or array-like of float, default=1.0
        The standard deviation of the clusters.

    center_box : tuple of float (min, max), default=(-10.0, 10.0)
        The bounding box for each cluster center when centers are
        generated at random.

    shuffle : bool, default=True
        Shuffle the samples.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset creation. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    return_centers : bool, default=False
        If True, then return the centers of each cluster.

        .. versionadded:: 0.23

    Returns
    -------
    X : ndarray of shape (n_samples, n_features)
        The generated samples.

    y : ndarray of shape (n_samples,)
        The integer labels for cluster membership of each sample.

    centers : ndarray of shape (n_centers, n_features)
        The centers of each cluster. Only returned if
        ``return_centers=True``.

    See Also
    --------
    make_classification : A more intricate variant.

    Examples
    --------
    >>> from sklearn.datasets import make_blobs
    >>> X, y = make_blobs(n_samples=10, centers=3, n_features=2,
    ...                   random_state=0)
    >>> print(X.shape)
    (10, 2)
    >>> y
    array([0, 0, 1, 0, 2, 2, 2, 1, 1, 0])
    >>> X, y = make_blobs(n_samples=[3, 3, 4], centers=None, n_features=2,
    ...                   random_state=0)
    >>> print(X.shape)
    (10, 2)
    >>> y
    array([0, 1, 2, 0, 2, 2, 2, 1, 1, 0])
    N   r   r(   r   z8Parameter `centers` must be array-like. Got {!r} insteadzMLength of `n_samples` not consistent with number of centers. Got n_samples = z and centers = __len__zeLength of `clusters_std` not consistent with number of centers. Got centers = {} and cluster_std = {}r|   r   locr:   r   r   )r
   rN   r   r   rU   r	   r|   rM   r   rJ   rL   hasattrr   r   fullrC   rR   r   emptyrP   r   rW   zipr   rZ   )r.   r/   r   r   r   r   r   r   r\   	n_centersn_samples_per_centerra   cum_sum_n_samplesrb   rc   rk   std	start_idxend_idxs                      r&   
make_blobsr     s   H #<00I)W-.. #&?Ggw/00 		)I''1z!}Iz3J (  GG
 "'**G q)Ja(II 	NN	?''1z!}Iz3J (  G '8,, 	JQQ   
 w<<9$$P,5P PFMP P   g&&]1%
 {I&& 
3{+;+;y+H+H##)6';#?#?
 
 	
 +w|,, 9gc'llK88)X&& )( #I$: ; ;<yHy9,-- 	) 	)A ###q(####	"677
011:>bjQQQA
01133???A %9;!G!GHH ! !8As01A%a!e,,1	#A&(//
#Q
O  0  
  
)G
  !)G
 :Aqy9991 !W}!tr'   )r.   r/   r   r   )r   r   c                n   t          |          }|                    | |f          }dt          j        t          j        |dddf         z  |dddf         z            z  d|dddf         dz
  dz  z  z   d|ddd	f         z  z   d
|dddf         z  z   ||                    |           z  z   }||fS )aC  Generate the "Friedman #1" regression problem.

    This dataset is described in Friedman [1] and Breiman [2].

    Inputs `X` are independent features uniformly distributed on the interval
    [0, 1]. The output `y` is created according to the formula::

        y(X) = 10 * sin(pi * X[:, 0] * X[:, 1]) + 20 * (X[:, 2] - 0.5) ** 2 + 10 * X[:, 3] + 5 * X[:, 4] + noise * N(0, 1).

    Out of the `n_features` features, only 5 are actually used to compute
    `y`. The remaining features are independent of `y`.

    The number of features has to be >= 5.

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

    Parameters
    ----------
    n_samples : int, default=100
        The number of samples.

    n_features : int, default=10
        The number of features. Should be at least 5.

    noise : float, default=0.0
        The standard deviation of the gaussian noise applied to the output.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset noise. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    X : ndarray of shape (n_samples, n_features)
        The input samples.

    y : ndarray of shape (n_samples,)
        The output values.

    References
    ----------
    .. [1] J. Friedman, "Multivariate adaptive regression splines", The Annals
           of Statistics 19 (1), pages 1-67, 1991.

    .. [2] L. Breiman, "Bagging predictors", Machine Learning 24,
           pages 123-140, 1996.

    Examples
    --------
    >>> from sklearn.datasets import make_friedman1
    >>> X, y = make_friedman1(random_state=42)
    >>> X.shape
    (100, 10)
    >>> y.shape
    (100,)
    >>> list(y[:3])
    [np.float64(16.8...), np.float64(5.8...), np.float64(9.4...)]
    r   r   Nr   r(   r=   r   rI   r   rv      )r
   rU   r   r   r   rV   )r.   r/   r   r   r\   rb   rc   s          r&   make_friedman1r   I  s    L #<00I	:677A
RVBEAaaadGOa1g-...
!!!Q$#!#
#	$
qAw,	 a1g+	 )++)+==
=		>  a4Kr'   )r.   r   r   c                    t          |          }|                    | df          }|dddfxx         dz  cc<   |dddfxx         dt          j        z  z  cc<   |dddfxx         dt          j        z  z  cc<   |ddd	fxx         d
z  cc<   |ddd	fxx         dz  cc<   |dddf         dz  |dddf         |dddf         z  d|dddf         |ddd	f         z  z  z
  dz  z   dz  ||                    |           z  z   }||fS )a  Generate the "Friedman #2" regression problem.

    This dataset is described in Friedman [1] and Breiman [2].

    Inputs `X` are 4 independent features uniformly distributed on the
    intervals::

        0 <= X[:, 0] <= 100,
        40 * pi <= X[:, 1] <= 560 * pi,
        0 <= X[:, 2] <= 1,
        1 <= X[:, 3] <= 11.

    The output `y` is created according to the formula::

        y(X) = (X[:, 0] ** 2 + (X[:, 1] * X[:, 2]  - 1 / (X[:, 1] * X[:, 3])) ** 2) ** 0.5 + noise * N(0, 1).

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

    Parameters
    ----------
    n_samples : int, default=100
        The number of samples.

    noise : float, default=0.0
        The standard deviation of the gaussian noise applied to the output.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset noise. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    X : ndarray of shape (n_samples, 4)
        The input samples.

    y : ndarray of shape (n_samples,)
        The output values.

    References
    ----------
    .. [1] J. Friedman, "Multivariate adaptive regression splines", The Annals
           of Statistics 19 (1), pages 1-67, 1991.

    .. [2] L. Breiman, "Bagging predictors", Machine Learning 24,
           pages 123-140, 1996.

    Examples
    --------
    >>> from sklearn.datasets import make_friedman2
    >>> X, y = make_friedman2(random_state=42)
    >>> X.shape
    (100, 4)
    >>> y.shape
    (100,)
    >>> list(y[:3])
    [np.float64(1229.4...), np.float64(27.0...), np.float64(65.6...)]
    r   r   Nr   r<   r(     (   r   r   r   rI   )r
   rU   r   r   rV   r.   r   r   r\   rb   rc   s         r&   make_friedman2r     sb   H #<00I	1~..AaaadGGGsNGGGaaadGGGsRU{GGGaaadGGGrBEzGGGaaadGGGrMGGGaaadGGGqLGGG 	
!!!Q$1!!!Q$!AAAqD')A111a41QQQT71B,CCII		y00y0BBB	CA a4Kr'   c                2   t          |          }|                    | df          }|dddfxx         dz  cc<   |dddfxx         dt          j        z  z  cc<   |dddfxx         dt          j        z  z  cc<   |ddd	fxx         d
z  cc<   |ddd	fxx         dz  cc<   t          j        |dddf         |dddf         z  d|dddf         |ddd	f         z  z  z
  |dddf         z            ||                    |           z  z   }||fS )a  Generate the "Friedman #3" regression problem.

    This dataset is described in Friedman [1] and Breiman [2].

    Inputs `X` are 4 independent features uniformly distributed on the
    intervals::

        0 <= X[:, 0] <= 100,
        40 * pi <= X[:, 1] <= 560 * pi,
        0 <= X[:, 2] <= 1,
        1 <= X[:, 3] <= 11.

    The output `y` is created according to the formula::

        y(X) = arctan((X[:, 1] * X[:, 2] - 1 / (X[:, 1] * X[:, 3])) / X[:, 0]) + noise * N(0, 1).

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

    Parameters
    ----------
    n_samples : int, default=100
        The number of samples.

    noise : float, default=0.0
        The standard deviation of the gaussian noise applied to the output.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset noise. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    X : ndarray of shape (n_samples, 4)
        The input samples.

    y : ndarray of shape (n_samples,)
        The output values.

    References
    ----------
    .. [1] J. Friedman, "Multivariate adaptive regression splines", The Annals
           of Statistics 19 (1), pages 1-67, 1991.

    .. [2] L. Breiman, "Bagging predictors", Machine Learning 24,
           pages 123-140, 1996.

    Examples
    --------
    >>> from sklearn.datasets import make_friedman3
    >>> X, y = make_friedman3(random_state=42)
    >>> X.shape
    (100, 4)
    >>> y.shape
    (100,)
    >>> list(y[:3])
    [np.float64(1.5...), np.float64(0.9...), np.float64(0.4...)]
    r   r   Nr   r<   r(   r   r   r   r   r   )r
   rU   r   r   arctanrV   r   s         r&   make_friedman3r     s]   H #<00I	1~..AaaadGGGsNGGGaaadGGGsRU{GGGaaadGGGrBEzGGGaaadGGGrMGGGaaadGGGqLGGG
		
111a41QQQT7	Q!AAAqD'AaaadG"34	4!!!Q$?	 		))	);;;	<A a4Kr'   r   )r   r   r   c                N   t          |          }t          | |          }t          j        |                    | |f          dd          \  }}t          j        |                    ||f          dd          \  }	}t          j        |t
          j                  }
d|z
  t          j        d|
|z  dz  z            z  }|t          j        d	|
z  |z            z  }t          j	        |          ||z   z  }t          j
        t          j
        ||          |	j                  S )
a  Generate a mostly low rank matrix with bell-shaped singular values.

    Most of the variance can be explained by a bell-shaped curve of width
    effective_rank: the low rank part of the singular values profile is::

        (1 - tail_strength) * exp(-1.0 * (i / effective_rank) ** 2)

    The remaining singular values' tail is fat, decreasing as::

        tail_strength * exp(-0.1 * i / effective_rank).

    The low rank part of the profile can be considered the structured
    signal part of the data while the tail can be considered the noisy
    part of the data that cannot be summarized by a low number of linear
    components (singular vectors).

    This kind of singular profiles is often seen in practice, for instance:
     - gray level pictures of faces
     - TF-IDF vectors of text documents crawled from the web

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

    Parameters
    ----------
    n_samples : int, default=100
        The number of samples.

    n_features : int, default=100
        The number of features.

    effective_rank : int, default=10
        The approximate number of singular vectors required to explain most of
        the data by linear combinations.

    tail_strength : float, default=0.5
        The relative importance of the fat noisy tail of the singular values
        profile. The value should be between 0 and 1.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset creation. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    X : ndarray of shape (n_samples, n_features)
        The matrix.

    Examples
    --------
    >>> from numpy.linalg import svd
    >>> from sklearn.datasets import make_low_rank_matrix
    >>> X = make_low_rank_matrix(
    ...     n_samples=50,
    ...     n_features=25,
    ...     effective_rank=5,
    ...     tail_strength=0.01,
    ...     random_state=0,
    ... )
    >>> X.shape
    (50, 25)
    r   economicF)modecheck_finiterG   r(   r   r   g)r
   r   r   qrrV   r   r[   r   expidentityrX   r   )r.   r/   r   r   r   r\   rk   ur   vsingular_indlow_ranktailss                 r&   r   r   E  s*   ` #<00IIz""A 9!!	1~!66  DAq
 9!!
A!77  DAq 9Qbj111L M!RVDL>4QVW3W,W%X%XXH26$"5"FGGGD
A(T/*A6"&A,,$$$r'   )r.   n_componentsr/   n_nonzero_coefsr   c                &   t          |          }|                    ||f          }|t          j        t          j        |dz  d                    z  }t          j        || f          }t          |           D ]P}t          j        |          }	|                    |	           |	d|         }	|                    |          ||	|f<   Qt          j	        ||          }
|
j
        |j
        |j
        }}}
t          t          j        |
||f          S )a  Generate a signal as a sparse combination of dictionary elements.

    Returns matrices `Y`, `D` and `X` such that `Y = XD` where `X` is of shape
    `(n_samples, n_components)`, `D` is of shape `(n_components, n_features)`, and
    each row of `X` has exactly `n_nonzero_coefs` non-zero elements.

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

    Parameters
    ----------
    n_samples : int
        Number of samples to generate.

    n_components : int
        Number of components in the dictionary.

    n_features : int
        Number of features of the dataset to generate.

    n_nonzero_coefs : int
        Number of active (non-zero) coefficients in each sample.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset creation. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    data : ndarray of shape (n_samples, n_features)
        The encoded signal (Y).

    dictionary : ndarray of shape (n_components, n_features)
        The dictionary with normalized components (D).

    code : ndarray of shape (n_samples, n_components)
        The sparse code such that each column of this matrix has exactly
        n_nonzero_coefs non-zero items (X).

    Examples
    --------
    >>> from sklearn.datasets import make_sparse_coded_signal
    >>> data, dictionary, code = make_sparse_coded_signal(
    ...     n_samples=50,
    ...     n_components=100,
    ...     n_features=10,
    ...     n_nonzero_coefs=4,
    ...     random_state=0
    ... )
    >>> data.shape
    (50, 10)
    >>> dictionary.shape
    (100, 10)
    >>> code.shape
    (50, 100)
    r   r   r   ry   N)r
   rV   r   sqrtrP   rS   rR   r[   r   rX   r   mapr   )r.   r   r/   r   r   r\   Drb   ra   idxr   s              r&   make_sparse_coded_signalr     s   T #<00I 	!!
L'A!BBAAQ'''	(	((A 	,	*++A9 D Di%%#"?"#--?-CC#q&		 	q!A c13!qArzAq!9%%%r'   )r.   r/   r   c                "   t          |          }|                    dd| |f          }|                    |dddf         d|dddf         z  z   d|dddf         z  z
  d|dddf         z  z
  t          j        |                     }||fS )	ai  Generate a random regression problem with sparse uncorrelated design.

    This dataset is described in Celeux et al [1]. as::

        X ~ N(0, 1)
        y(X) = X[:, 0] + 2 * X[:, 1] - 2 * X[:, 2] - 1.5 * X[:, 3]

    Only the first 4 features are informative. The remaining features are
    useless.

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

    Parameters
    ----------
    n_samples : int, default=100
        The number of samples.

    n_features : int, default=10
        The number of features.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset creation. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    X : ndarray of shape (n_samples, n_features)
        The input samples.

    y : ndarray of shape (n_samples,)
        The output values.

    References
    ----------
    .. [1] G. Celeux, M. El Anbari, J.-M. Marin, C. P. Robert,
           "Regularization in regression: comparing Bayesian and frequentist
           methods in a poorly informative situation", 2009.

    Examples
    --------
    >>> from sklearn.datasets import make_sparse_uncorrelated
    >>> X, y = make_sparse_uncorrelated(random_state=0)
    >>> X.shape
    (100, 10)
    >>> y.shape
    (100,)
    r   r(   r   Nr         ?r   )r   r:   )r
   r   r   r   )r.   r/   r   r\   rb   rc   s         r&   make_sparse_uncorrelatedr    s    r #<00IQay*.EFFAqqq!tWq1QQQT7{"Q111a4[03111a4=@gi   	 	 	A
 a4Kr'   )n_dimr   c                Z   t          |          }|                    | | f          }t          j        t	          j        |j        |          d          \  }}}t	          j        t	          j        |dt	          j        |                    |                     z             |          }|S )ak  Generate a random symmetric, positive-definite matrix.

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

    Parameters
    ----------
    n_dim : int
        The matrix dimension.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset creation. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    X : ndarray of shape (n_dim, n_dim)
        The random symmetric, positive-definite matrix.

    See Also
    --------
    make_sparse_spd_matrix: Generate a sparse symmetric definite positive matrix.

    Examples
    --------
    >>> from sklearn.datasets import make_spd_matrix
    >>> make_spd_matrix(n_dim=2, random_state=42)
    array([[2.09..., 0.34...],
           [0.34..., 0.21...]])
    r   F)r   r>   )r
   rU   r   svdr   rX   r   diag)r  r   r\   ri   Ur   Vtrb   s           r&   make_spd_matrixr	  T  s    L #<00Iu~..Az"&a..u===HAq"
rvarwy'8'8e'8'D'DEEEFFKKAHr'   >   bsrcoocsccsrdiadoklil)r  alpha	norm_diagsmallest_coeflargest_coefsparse_formatr   gffffff?g?g?)r  r  r  r  r  r   c                   t                    t          j        |            }t          j        | | d|z
  fd          }t          j        |dd          }                    |           }	||	         j        |	         }||z  }|j        |z  }
|rCt          j        dt          j	        |

                                          z            }||
z  |z  }
||
                                S |
                    |          S )a4  Generate a sparse symmetric definite positive matrix.

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

    Parameters
    ----------
    n_dim : int, default=1
        The size of the random matrix to generate.

        .. versionchanged:: 1.4
            Renamed from ``dim`` to ``n_dim``.

    alpha : float, default=0.95
        The probability that a coefficient is zero (see notes). Larger values
        enforce more sparsity. The value should be in the range 0 and 1.

    norm_diag : bool, default=False
        Whether to normalize the output matrix to make the leading diagonal
        elements all 1.

    smallest_coef : float, default=0.1
        The value of the smallest coefficient between 0 and 1.

    largest_coef : float, default=0.9
        The value of the largest coefficient between 0 and 1.

    sparse_format : str, default=None
        String representing the output sparse format, such as 'csc', 'csr', etc.
        If ``None``, return a dense numpy ndarray.

        .. versionadded:: 1.4

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset creation. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    prec : ndarray or sparse matrix of shape (dim, dim)
        The generated matrix. If ``sparse_format=None``, this would be an ndarray.
        Otherwise, this will be a sparse matrix of the specified format.

    See Also
    --------
    make_spd_matrix : Generate a random symmetric, positive-definite matrix.

    Notes
    -----
    The sparsity is actually imposed on the cholesky factor of the matrix.
    Thus alpha does not translate directly into the filling fraction of
    the matrix itself.

    Examples
    --------
    >>> from sklearn.datasets import make_sparse_spd_matrix
    >>> make_sparse_spd_matrix(n_dim=4, norm_diag=False, random_state=42)
    array([[1., 0., 0., 0.],
           [0., 1., 0., 0.],
           [0., 0., 1., 0.],
           [0., 0., 0., 1.]])
    r(   c                 4                         |           S )N)lowhighr   )rU   )xr  r   r  s    r&   <lambda>z(make_sparse_spd_matrix.<locals>.<lambda>  s#    <//Lq 0 
 
 r'   )mrk   densitydata_rvsr   r   r  )rE   rL   r>   )r
   r   eyerandomtrilpermutationr   diagsr   r   diagonalr   asformat)r  r  r  r  r  r  r   cholauxr"  precds      `` `     r&   make_sparse_spd_matrixr*    s   n &l33LF5MM>D
)

E	
 
 
 
 
 
 "  C '#E
*
*
*C **511K
k

[
)CCKD6D=D HS274==??333444x!|||~~}}]+++r'   )r.   r   r   hole)r   r   r+  c                    t          |          }|sFdt          j        z  dd|                    |           z  z   z  }d|                    |           z  }nt          j        d t          d          D                       }t          j        |dd	
          }|                    d|           }|                    d| f          t          j        t          j        gdgg          z  }	||         j        |	z   \  }}|t          j	        |          z  }
|t          j
        |          z  }t          j        |
||f          }|||                    d| f          z  z  }|j        }t          j        |          }||fS )aN  Generate a swiss roll dataset.

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

    Parameters
    ----------
    n_samples : int, default=100
        The number of sample points on the Swiss Roll.

    noise : float, default=0.0
        The standard deviation of the gaussian noise.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset creation. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    hole : bool, default=False
        If True generates the swiss roll with hole dataset.

    Returns
    -------
    X : ndarray of shape (n_samples, 3)
        The points.

    t : ndarray of shape (n_samples,)
        The univariate position of the sample according to the main dimension
        of the points in the manifold.

    Notes
    -----
    The algorithm is from Marsland [1].

    References
    ----------
    .. [1] S. Marsland, "Machine Learning: An Algorithmic Perspective", 2nd edition,
           Chapter 6, 2014.
           https://homepages.ecs.vuw.ac.nz/~marslast/Code/Ch6/lle.py

    Examples
    --------
    >>> from sklearn.datasets import make_swiss_roll
    >>> X, t = make_swiss_roll(noise=0.05, random_state=0)
    >>> X.shape
    (100, 3)
    >>> t.shape
    (100,)
    r  r(   r   r      c                 `    g | ]+}t          d           D ]}t          j        d|z   z  |dz  g,S )r   r     )rR   r   r   )rD   ra   js      r&   rF   z#make_swiss_roll.<locals>.<listcomp><  s?    LLLA588LLabesQwQ'LLLLr'   r   r   r   ry      r/  )r
   r   r   rU   r   rR   deletechoicer   r   r   r   rV   r   )r.   r   r   r+  r\   trc   cornerscorner_index
parametersr  zrb   s                r&   make_swiss_rollr9    sz   t #<00I 
4"%K1q9#4#4)#4#D#DDDE""	"222(LLqLLL
 
 )GQQ/// ''955&&Q	N&;;bhRSQT~>V>VV
|$&31	BF1IIA	BF1IIA
	1a)A**I*??	??A	A

1Aa4Kr'   c                   t          |          }dt          j        z  |                    d| f          dz
  z  }t          j        | dft          j                  }t          j        |          |dddf<   d|                    |           z  |dddf<   t          j        |          t          j        |          dz
  z  |ddd	f<   |||	                    d| f          j
        z  z  }t          j        |          }||fS )
a  Generate an S curve dataset.

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

    Parameters
    ----------
    n_samples : int, default=100
        The number of sample points on the S curve.

    noise : float, default=0.0
        The standard deviation of the gaussian noise.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset creation. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    X : ndarray of shape (n_samples, 3)
        The points.

    t : ndarray of shape (n_samples,)
        The univariate position of the sample according
        to the main dimension of the points in the manifold.

    Examples
    --------
    >>> from sklearn.datasets import make_s_curve
    >>> X, t = make_s_curve(noise=0.05, random_state=0)
    >>> X.shape
    (100, 3)
    >>> t.shape
    (100,)
    r   r(   r   rI   r   Nr   r   r   )r
   r   r   rU   r   r   r   signr   rV   r   r   )r.   r   r   r\   r4  rb   s         r&   make_s_curver<  N  s    X #<00I	BE	Y&&Q	N&;;cABA
	1~RZ888AfQiiAaaadGI%%9%555AaaadGgajjBF1IIM*AaaadG**I*??A	AAA

1Aa4Kr'   )meancovr.   r/   r3   r   r   r   c           	         ||k     rt          d          t          |          }| t          j        |          } nt          j        |           } |                    | |t          j        |          z  |f          }t          j        t          j        || t          j	        ddf         z
  dz  d                    }	||	ddf         }||z  }
t          j
        t          j        t          j        |          |
          t          j        |dz
  ||
|z  z
            g          }|rt          |||          \  }}||fS )a  Generate isotropic Gaussian and label samples by quantile.

    This classification dataset is constructed by taking a multi-dimensional
    standard normal distribution and defining classes separated by nested
    concentric multi-dimensional spheres such that roughly equal numbers of
    samples are in each class (quantiles of the :math:`\chi^2` distribution).

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

    Parameters
    ----------
    mean : array-like of shape (n_features,), default=None
        The mean of the multi-dimensional normal distribution.
        If None then use the origin (0, 0, ...).

    cov : float, default=1.0
        The covariance matrix will be this value times the unit matrix. This
        dataset only produces symmetric normal distributions.

    n_samples : int, default=100
        The total number of points equally divided among classes.

    n_features : int, default=2
        The number of features for each sample.

    n_classes : int, default=3
        The number of classes.

    shuffle : bool, default=True
        Shuffle the samples.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset creation. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    X : ndarray of shape (n_samples, n_features)
        The generated samples.

    y : ndarray of shape (n_samples,)
        The integer labels for quantile membership of each sample.

    Notes
    -----
    The dataset is from Zhu et al [1].

    References
    ----------
    .. [1] J. Zhu, H. Zou, S. Rosset, T. Hastie, "Multi-class AdaBoost", 2009.

    Examples
    --------
    >>> from sklearn.datasets import make_gaussian_quantiles
    >>> X, y = make_gaussian_quantiles(random_state=42)
    >>> X.shape
    (100, 2)
    >>> y.shape
    (100,)
    >>> list(y[:5])
    [np.int64(2), np.int64(0), np.int64(1), np.int64(0), np.int64(2)]
    z$n_samples must be at least n_classesNr   r(   ry   r   )rJ   r
   r   rS   r   multivariate_normalr   argsortrP   newaxisr   repeatr[   rZ   )r=  r>  r.   r/   r3   r   r   r\   rb   r   steprc   s               r&   make_gaussian_quantilesrE    sF   j 9?@@@"<00I|x
##x~~ 	%%dC"+j2I2I,II<XXA *RVQbj!!!m!44:CCC
D
DC	#qqq&	A 	!D
	Ibi	**D11Ii!mY	1A%ABB	
	 	A  :Aqy9991a4Kr'   c                     t          |          }| j        \  }}|                    |          }|                    |          }| |         d d |f         }|||fS N)r
   r|   r"  )datar   r\   n_rowsn_colsrow_idxcol_idxresults           r&   _shufflerN    sc    "<00IZNFF##F++G##F++G']111g:&F7G##r'   )r|   r_   r   minvalmaxvalr   r   )r   rO  rP  r   r   c                   t          |          }| \  }}	|                    |||          }
|                    |t          j        d|z  |                    }|                    |	t          j        d|z  |                    }t          j        d t          t          |          |          D                       t          j        d t          t          |          |          D                       t          j        | t          j	                  }t          |          D ]5}t          j
        |k    |k              }||xx         |
|         z  cc<   6|dk    r||                    ||j                  z  }|r$t          ||          \  }}}|         |         t          j        fdt          |          D                       }t          j        fdt          |          D                       }|||fS )	aS  Generate a constant block diagonal structure array for biclustering.

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

    Parameters
    ----------
    shape : tuple of shape (n_rows, n_cols)
        The shape of the result.

    n_clusters : int
        The number of biclusters.

    noise : float, default=0.0
        The standard deviation of the gaussian noise.

    minval : float, default=10
        Minimum value of a bicluster.

    maxval : float, default=100
        Maximum value of a bicluster.

    shuffle : bool, default=True
        Shuffle the samples.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset creation. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    X : ndarray of shape `shape`
        The generated array.

    rows : ndarray of shape (n_clusters, X.shape[0])
        The indicators for cluster membership of each row.

    cols : ndarray of shape (n_clusters, X.shape[1])
        The indicators for cluster membership of each column.

    See Also
    --------
    make_checkerboard: Generate an array with block checkerboard structure for
        biclustering.

    References
    ----------

    .. [1] Dhillon, I. S. (2001, August). Co-clustering documents and
        words using bipartite spectral graph partitioning. In Proceedings
        of the seventh ACM SIGKDD international conference on Knowledge
        discovery and data mining (pp. 269-274). ACM.

    Examples
    --------
    >>> from sklearn.datasets import make_biclusters
    >>> data, rows, cols = make_biclusters(
    ...     shape=(10, 20), n_clusters=2, random_state=42
    ... )
    >>> data.shape
    (10, 20)
    >>> rows.shape
    (2, 10)
    >>> cols.shape
    (2, 20)
    r>   c                 >    g | ]\  }}t          j        ||          S rB   r   rC  rD   valreps      r&   rF   z#make_biclusters.<locals>.<listcomp>g  (    OOOc3		OOOr'   c                 >    g | ]\  }}t          j        ||          S rB   rS  rT  s      r&   rF   z#make_biclusters.<locals>.<listcomp>j  rW  r'   rG   r   r   c                     g | ]}|k    	S rB   rB   )rD   r   
row_labelss     r&   rF   z#make_biclusters.<locals>.<listcomp>z      AAA!jAoAAAr'   c                     g | ]}|k    	S rB   rB   )rD   r   
col_labelss     r&   rF   z#make_biclusters.<locals>.<listcomp>{  r[  r'   )r
   rU   multinomialr   rC  r   r   rR   rS   r   outerr   r|   rN  r   )r|   r_   r   rO  rP  r   r   r\   rI  rJ  consts	row_sizes	col_sizesrM  ra   selectorrK  rL  rowscolsr]  rZ  s                       @@r&   make_biclustersrf    s   p #<00INFFvvz::F %%fbij8H*.U.UVVI%%fbij8H*.U.UVVIOOSz1B1BI-N-NOOO J OOSz1B1BI-N-NOOO J Xe2:...F: & &8J!OZ1_==xF1I%qyy)""V\"BBB )#+FL#A#A (
(
9AAAAuZ/@/@AAABBD9AAAAuZ/@/@AAABBD4r'   c          	      Z   t          |          }t          |d          r|\  }n|x}| \  }	}
|                    |	t          j        d|z  |                    }|                    |
t          j        dz                      }t          j        d t          t          |          |          D                       t          j        d t          t                    |          D                       t          j        | t          j	                  }t          |          D ]U}t                    D ]C}t          j
        |k    |k              }||xx         |                    ||          z  cc<   DV|dk    r||                    ||j                  z  }|r$t          ||          \  }}}|         |         t          j        fdt          |          D                       }t          j        fd	t          |          D                       }|||fS )
a  Generate an array with block checkerboard structure for biclustering.

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

    Parameters
    ----------
    shape : tuple of shape (n_rows, n_cols)
        The shape of the result.

    n_clusters : int or array-like or shape (n_row_clusters, n_column_clusters)
        The number of row and column clusters.

    noise : float, default=0.0
        The standard deviation of the gaussian noise.

    minval : float, default=10
        Minimum value of a bicluster.

    maxval : float, default=100
        Maximum value of a bicluster.

    shuffle : bool, default=True
        Shuffle the samples.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset creation. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    X : ndarray of shape `shape`
        The generated array.

    rows : ndarray of shape (n_clusters, X.shape[0])
        The indicators for cluster membership of each row.

    cols : ndarray of shape (n_clusters, X.shape[1])
        The indicators for cluster membership of each column.

    See Also
    --------
    make_biclusters : Generate an array with constant block diagonal structure
        for biclustering.

    References
    ----------
    .. [1] Kluger, Y., Basri, R., Chang, J. T., & Gerstein, M. (2003).
        Spectral biclustering of microarray data: coclustering genes
        and conditions. Genome research, 13(4), 703-716.

    Examples
    --------
    >>> from sklearn.datasets import make_checkerboard
    >>> data, rows, columns = make_checkerboard(shape=(300, 300), n_clusters=10,
    ...                                         random_state=42)
    >>> data.shape
    (300, 300)
    >>> rows.shape
    (100, 300)
    >>> columns.shape
    (100, 300)
    >>> print(rows[0][:5], columns[0][:5])
    [False False False  True False] [False False False False False]
    r   r>   c                 >    g | ]\  }}t          j        ||          S rB   rS  rT  s      r&   rF   z%make_checkerboard.<locals>.<listcomp>  (    SSSc3		SSSr'   c                 >    g | ]\  }}t          j        ||          S rB   rS  rT  s      r&   rF   z%make_checkerboard.<locals>.<listcomp>  ri  r'   rG   r   r   c                 @    g | ]}t                    D ]}|k    	S rB   rR   )rD   labelr   n_col_clustersrZ  s      r&   rF   z%make_checkerboard.<locals>.<listcomp>  sM     	
 	
 	
>**	
 	
  %	
 	
 	
 	
r'   c                 @    g | ]}t                    D ]}|k    	S rB   rl  )rD   r   rm  r]  rn  s      r&   rF   z%make_checkerboard.<locals>.<listcomp>	  sM     	
 	
 	
~..	
 	
  %	
 	
 	
 	
r'   )r
   r   r^  r   rC  r   r   rR   rS   r   r_  rU   r   r|   rN  r   )r|   r_   r   rO  rP  r   r   r\   n_row_clustersrI  rJ  ra  rb  rM  ra   r0  rc  rK  rL  rd  re  r]  rn  rZ  s                        @@@r&   make_checkerboardrq    s   n #<00Iz9%% 5)3&*44 NFF%%	#.?? I %%	#.?? I SSS~1F1F	-R-RSSS J SSS~1F1F	-R-RSSS J Xe2:...F>"" B B~&& 	B 	BAx
aqAAH8	 1 1&& A AA	B qyy)""V\"BBB )#+FL#A#A (
(
9	
 	
 	
 	
 	
~..	
 	
 	
 D 9	
 	
 	
 	
 	
>**	
 	
 	
 D 4r'   )r<   r=   )r   )r<   r<   )r<   )r<   r   )r<   r   )r(   rG  )2__doc__r   r   collections.abcr   r   r   numpyr   scipy.sparserp   r   scipyr   preprocessingr   utilsr	   r
   r   rZ   utils._param_validationr   r   r   utils.randomr   r   rn   r   r   r   tupler   r   r   r   r   r   r   r   r  r	  r*  r9  r<  rE  rN  rf  rq  rB   r'   r&   <module>r|     s      $ $ $ $ $ $ " " " " " " " "                 / / / / / / 3 3 3 3 3 3 3 3 + + + + + + K K K K K K K K K K 5 5 5 5 5 5    hxD@@@Ax!T&AAAB"(8QVDDDE 1d6BBBCx!T&AAABhxD@@@A!)(AtF!K!K!K L $'8D!Qv6667htQY???@[(4tI>>>dS(4D;;;\4P;'( " #'%  * A 

!A A A A) (AH hxD@@@Ax!T&AAABhxD@@@AXh4???@8Haf===>%;+'Z((;<<iH!*'(  #'    d d d d d dN hxD@@@A'(  #'  8d 8 8 8 8 8v hxD@@@Ax!T&AAAB"(8QVDDDEhxD@@@A$d9===>#8HafEEEtL"(4Af===>(4D8889;'(  #'  " R 	
	R R R R!  Rj hxD@@@%H;(4D888$?'(8D!Qv6667  #'	 	 	 T"$T#T T T T	 	Tn hxD@@@%H;(4D888$?'(	  #'  KT K K K K K\ hxD@@@,Ox!T&AAABHXq$v>>>dS q$v>>>Mg;'($+	 	 #'   d d d d d dN hxD@@@Ax!T&AAAB(4d6:::;'(	  #'  H#D H H H H HV hxD@@@A(4D8889'( 
 #'  I3T I I I I IX hxD@@@A(4D8889'( 
 #'  I3T I I I I IX hxD@@@Ax!T&AAAB#8HafEEEF"(4Af===>'(  #'	 	 	 ]% ]% ]% ]% ]%	 	]%@ hxD@@@A!(AtFCCCDx!T&AAAB$HXq$vFFFG'(  #'	 	 	  T& T& T& T&	 	T&n hxD@@@Ax!T&AAAB'( 
 #'  94 9 9 9 9 9x (8QV<<<='(  #'   ,0 % % % % %P (8QV<<<=(4Af5556["(4Af===>!$1V<<<=JHHHII
 ((  #'    f, f, f, f, f, f,R hxD@@@A(4D8889'(	  #'  GCd G G G G GT hxD@@@A(4D8889'( 
 #'  .4 . . . . .b t$q$v6667hxD@@@Ax!T&AAABhxD@@@A;'(  #'   
g g g g gT$ $ $ $ x!T&AAAB(4D88898D$Y???@8D$Y???@;'(  #'    k k k k k\ x!T&AAA<P(4D88898D$Y???@8D$Y???@;'(  #'          r'   