return imputer_mask, features_with_missing <ins>    def _validate_input(self, X):        if not is_scalar_nan(self.missing_values):            force_all_finite = True        else:            force_all_finite = "allow-nan"        X = check_array(X, accept_sparse=('csc', 'csr'), dtype=None,                        force_all_finite=force_all_finite)        _check_inputs_dtype(X, self.missing_values)        if X.dtype.kind not in ("i", "u", "f", "O"):            raise ValueError("MissingIndicator does not support data with "                             "dtype {0}. Please provide either a numeric array"                             " (with a floating point or integer dtype) or "                             "categorical data represented either as an array "                             "with integer dtype or an array of string values "                             "with an object dtype.".format(X.dtype))        return X</ins>     def fit(self, X, y=None):         """Fit the transformer on X.


self : object             Returns self.         """        if not is_scalar_nan(self.missing_values):            force_all_finite = True        else:            force_all_finite = "allow-nan"        X = check_array(X, accept_sparse=('csc', 'csr'),                        force_all_finite=force_all_finite)        _check_inputs_dtype(X, self.missing_values)        X = self._validate_input(X)         self._n_features = X.shape[1]          if self.features not in ('missing-only', 'all'):


"""         check_is_fitted(self, "features_")        if not is_scalar_nan(self.missing_values):            force_all_finite = True        else:            force_all_finite = "allow-nan"        X = check_array(X, accept_sparse=('csc', 'csr'),                        force_all_finite=force_all_finite)        _check_inputs_dtype(X, self.missing_values)        X = self._validate_input(X)          if X.shape[1] != self._n_features:             raise ValueError("X has a different number of features "diff --git a/sklearn/utils/estimator_checks.py b/sklearn/utils/estimator_checks.py-- a/sklearn/utils/estimator_checks.py++ b/sklearn/utils/estimator_checks.py


'OrthogonalMatchingPursuit', 'PLSCanonical', 'PLSRegression',                 'RANSACRegressor', 'RadiusNeighborsRegressor',                 'RandomForestRegressor', 'Ridge', 'RidgeCV'] ALLOW_NAN = ['Imputer', 'SimpleImputer', 'MissingIndicator',              'MaxAbsScaler', 'MinMaxScaler', 'RobustScaler', 'StandardScaler',              'PowerTransformer', 'QuantileTransformer']SUPPORT_STRING = ['SimpleImputer', 'MissingIndicator']   def _yield_non_meta_checks(name, estimator):


if "Unknown label type" not in str(e):             raise     X[0, 0] = {'foo': 'bar'}    msg = "argument must be a string or a number"    assert_raises_regex(TypeError, msg, estimator.fit, X, y)    if name not in SUPPORT_STRING:        X[0, 0] = {'foo': 'bar'}        msg = "argument must be a string or a number"        assert_raises_regex(TypeError, msg, estimator.fit, X, y)    else:        # Estimators supporting string will not call np.asarray to convert the        # data to numeric and therefore, the error will not be raised.        # Checking for each element dtype in the input array will be costly.        # Refer to #11401 for full discussion.        estimator.fit(X, y)   def check_complex_data(name, estimator_orig):


return expit(-(self.a_ * T + self.b_))  def calibration_curve(y_true, y_prob, normalize=False, n_bins=5):def calibration_curve(y_true, y_prob, normalize=False, n_bins=5,                      strategy='uniform'):     """Compute true and predicted probabilities for a calibration curve.       The method assumes the inputs come from a binary classifier.


points (i.e. without corresponding values in y_prob) will not be         returned, thus there may be fewer than n_bins in the return value. <ins>    strategy : {'uniform', 'quantile'}, (default='uniform')        Strategy used to define the widths of the bins.        uniform            All bins have identical widths.        quantile            All bins have the same number of points.</ins>     Returns     -------     prob_true : array, shape (n_bins,) or smaller


y_true = _check_binary_probabilistic_predictions(y_true, y_prob)     bins = np.linspace(0., 1. + 1e-8, n_bins + 1)    if strategy == 'quantile':  # Determine bin edges by distribution of data        quantiles = np.linspace(0, 1, n_bins + 1)        bins = np.percentile(y_prob, quantiles * 100)        bins[-1] = bins[-1] + 1e-8    elif strategy == 'uniform':        bins = np.linspace(0., 1. + 1e-8, n_bins + 1)    else:        raise ValueError("Invalid entry to 'strategy' input. Strategy "                         "must be either 'quantile' or 'uniform'.")     binids = np.digitize(y_prob, bins) - 1      bin_sums = np.bincount(binids, weights=y_prob, minlength=len(bins))


``n_splits`` default value will change from 3 to 5 in v0.22.      shuffle : boolean, optional        Whether to shuffle each stratification of the data before splitting        into batches.        Whether to shuffle each class's samples before splitting into batches.      random_state : int, RandomState instance or None, optional, default=None         If int, random_state is the seed used by the random number generator;


super().__init__(n_splits, shuffle, random_state)      def _make_test_folds(self, X, y=None):        rng = self.random_state        rng = check_random_state(self.random_state)         y = np.asarray(y)         type_of_target_y = type_of_target(y)         allowed_target_types = ('binary', 'multiclass')


# 1D k-means procedure                 km = KMeans(n_clusters=n_bins[jj], init=init, n_init=1)                 centers = km.fit(column[:, None]).cluster_centers_[:, 0]<ins>                # Must sort, centers may be unsorted even with sorted init                centers.sort()</ins>                 bin_edges[jj] = (centers[1:] + centers[:-1]) * 0.5                 bin_edges[jj] = np.r_[col_min, bin_edges[jj], col_max]


best_params = self._get_parameters()                 best_n_iter = n_iter <del>        # Always do a final e-step to guarantee that the labels returned by        # fit_predict(X) are always consistent with fit(X).predict(X)        # for any value of max_iter and tol (and any random_state).        _, log_resp = self._e_step(X)</del>         if not self.converged_:             warnings.warn('Initialization %d did not converge. '                           'Try different init parameters, '


self.n_iter_ = best_n_iter         self.lower_bound_ = max_lower_bound <ins>        # Always do a final e-step to guarantee that the labels returned by        # fit_predict(X) are always consistent with fit(X).predict(X)        # for any value of max_iter and tol (and any random_state).        _, log_resp = self._e_step(X)</ins>         return log_resp.argmax(axis=1)      def _e_step(self, X):


>>> f1_score(y_true, y_pred, average=None)     array([0.8, 0. , 0. ]) <ins>    Notes    -----    When ``true positive + false positive == 0`` or    ``true positive + false negative == 0``, f-score returns 0 and raises    ``UndefinedMetricWarning``.</ins>     """     return fbeta_score(y_true, y_pred, 1, labels=labels,                        pos_label=pos_label, average=average,


... # doctest: +ELLIPSIS     array([0.71..., 0.        , 0.        ]) <ins>    Notes    -----    When ``true positive + false positive == 0`` or    ``true positive + false negative == 0``, f-score returns 0 and raises    ``UndefinedMetricWarning``.</ins>     """     _, _, f, _ = precision_recall_fscore_support(y_true, y_pred,                                                  beta=beta,


array([0., 0., 1.]), array([0. , 0. , 0.8]),      array([2, 2, 2])) <ins>    Notes    -----    When ``true positive + false positive == 0``, precision is undefined;    When ``true positive + false negative == 0``, recall is undefined.    In such cases, the metric will be set to 0, as will f-score, and    ``UndefinedMetricWarning`` will be raised.</ins>     """     average_options = (None, 'micro', 'macro', 'weighted', 'samples')     if average not in average_options and average != 'binary':


if average == 'binary':         if y_type == 'binary':            if pos_label not in present_labels:                if len(present_labels) < 2:                    # Only negative labels                    return (0., 0., 0., 0)                else:                    raise ValueError("pos_label=%r is not a valid label: %r" %                                     (pos_label, present_labels))            if pos_label not in present_labels and len(present_labels) >= 2:                raise ValueError("pos_label=%r is not a valid label: %r" %                                 (pos_label, present_labels))             labels = [pos_label]         else:             raise ValueError("Target is %s but average='binary'. Please "


true_sum = np.array([true_sum.sum()])      # Finally, we have all our sufficient statistics. Divide! #<del></del>     beta2 = beta ** 2     with np.errstate(divide='ignore', invalid='ignore'):         # Divide, and on zero-division, set scores to 0 and warn:


f_score[tp_sum == 0] = 0.0      # Average the results<del></del>     if average == 'weighted':         weights = true_sum         if weights.sum() == 0:


>>> precision_score(y_true, y_pred, average=None)  # doctest: +ELLIPSIS     array([0.66..., 0.        , 0.        ]) <ins>    Notes    -----    When ``true positive + false positive == 0``, precision returns 0 and    raises ``UndefinedMetricWarning``.</ins>     """     p, _, _, _ = precision_recall_fscore_support(y_true, y_pred,                                                  labels=labels,


>>> recall_score(y_true, y_pred, average=None)     array([1., 0., 0.]) <ins>    Notes    -----    When ``true positive + false negative == 0``, recall returns 0 and raises    ``UndefinedMetricWarning``.</ins>     """     _, r, _, _ = precision_recall_fscore_support(y_true, y_pred,                                                  labels=labels,


-------         score : float             R^2 of self.predict(X) wrt. y.        Notes        -----        The R2 score used when calling ``score`` on a regressor will use        ``multioutput='uniform_average'`` from version 0.23 to keep consistent        with `metrics.r2_score`. This will influence the ``score`` method of        all the multioutput regressors (except for        `multioutput.MultiOutputRegressor`). To use the new default, please        either call `metrics.r2_score` directly or make a custom scorer with        `metric.make_scorer`.         """          from .metrics import r2_score        return r2_score(y, self.predict(X), sample_weight=sample_weight,        from .metrics.regression import _check_reg_targets        y_pred = self.predict(X)        # XXX: Remove the check in 0.23        y_type, _, _, _ = _check_reg_targets(y, y_pred, None)        if y_type == 'continuous-multioutput':            warnings.warn("The default value of multioutput (not exposed in "                          "score method) will change from 'variance_weighted' "                          "to 'uniform_average' in 0.23 to keep consistent "                          "with 'metrics.r2_score'. To use the new default, "                          "please either call 'metrics.r2_score' directly or "                          "make a custom scorer with 'metric.make_scorer'.",                          FutureWarning)        return r2_score(y, y_pred, sample_weight=sample_weight,                         multioutput='variance_weighted')  diff --git a/sklearn/linear_model/coordinate_descent.py b/sklearn/linear_model/coordinate_descent.py-- a/sklearn/linear_model/coordinate_descent.py++ b/sklearn/linear_model/coordinate_descent.py


--------     >>> from sklearn.linear_model import MultiTaskLassoCV     >>> from sklearn.datasets import make_regression    >>> from sklearn.metrics import r2_score     >>> X, y = make_regression(n_targets=2, noise=4, random_state=0)     >>> reg = MultiTaskLassoCV(cv=5, random_state=0).fit(X, y)    >>> reg.score(X, y) # doctest: +ELLIPSIS    >>> r2_score(y, reg.predict(X)) # doctest: +ELLIPSIS     0.9994...     >>> reg.alpha_     0.5713...diff --git a/sklearn/multioutput.py b/sklearn/multioutput.py-- a/sklearn/multioutput.py++ b/sklearn/multioutput.py


super().partial_fit(             X, y, sample_weight=sample_weight) <ins>    # XXX Remove this method in 0.23</ins>     def score(self, X, y, sample_weight=None):         """Returns the coefficient of determination R^2 of the prediction.


Attributes     ----------     n_bins_ : int array, shape (n_features,)        Number of bins per feature.        Number of bins per feature. Bins whose width are too small        (i.e., <= 1e-8) are removed with a warning.      bin_edges_ : array of arrays, shape (n_features, )         The edges of each bin. Contain arrays of varying shapes ``(n_bins_, )``


:class:`sklearn.compose.ColumnTransformer` if you only want to preprocess     part of the features. <ins>    ``KBinsDiscretizer`` might produce constant features (e.g., when    ``encode = 'onehot'`` and certain bins do not contain any data).    These features can be removed with feature selection algorithms    (e.g., :class:`sklearn.feature_selection.VarianceThreshold`).</ins>     See also     --------      sklearn.preprocessing.Binarizer : class used to bin values as ``0`` or


bin_edges[jj] = (centers[1:] + centers[:-1]) * 0.5                 bin_edges[jj] = np.r_[col_min, bin_edges[jj], col_max] <ins>            # Remove bins whose width are too small (i.e., <= 1e-8)            if self.strategy in ('quantile', 'kmeans'):                mask = np.ediff1d(bin_edges[jj], to_begin=np.inf) > 1e-8                bin_edges[jj] = bin_edges[jj][mask]                if len(bin_edges[jj]) - 1 != n_bins[jj]:                    warnings.warn('Bins whose width are too small (i.e., <= '                                  '1e-8) in feature %d are removed. Consider '                                  'decreasing the number of bins.' % jj)                    n_bins[jj] = len(bin_edges[jj]) - 1</ins>         self.bin_edges_ = bin_edges         self.n_bins_ = n_bins


if self.gamma in ('scale', 'auto_deprecated'):             if sparse:                # std = sqrt(E[X^2] - E[X]^2)                X_std = np.sqrt((X.multiply(X)).mean() - (X.mean())**2)                # var = E[X^2] - E[X]^2                X_var = (X.multiply(X)).mean() - (X.mean()) ** 2             else:                X_std = X.std()                X_var = X.var()             if self.gamma == 'scale':                if X_std != 0:                    self._gamma = 1.0 / (X.shape[1] * X_std)                if X_var != 0:                    self._gamma = 1.0 / (X.shape[1] * X_var)                 else:                     self._gamma = 1.0             else:                 kernel_uses_gamma = (not callable(self.kernel) and self.kernel                                      not in ('linear', 'precomputed'))                if kernel_uses_gamma and not np.isclose(X_std, 1.0):                if kernel_uses_gamma and not np.isclose(X_var, 1.0):                     # NOTE: when deprecation ends we need to remove explicitly                     # setting `gamma` in examples (also in tests). See                     # https://github.com/scikit-learn/scikit-learn/pull/10331diff --git a/sklearn/svm/classes.py b/sklearn/svm/classes.py-- a/sklearn/svm/classes.py++ b/sklearn/svm/classes.py


Kernel coefficient for 'rbf', 'poly' and 'sigmoid'.          Current default is 'auto' which uses 1 / n_features,        if ``gamma='scale'`` is passed then it uses 1 / (n_features * X.std())        if ``gamma='scale'`` is passed then it uses 1 / (n_features * X.var())         as value of gamma. The current default of gamma, 'auto', will change         to 'scale' in version 0.22. 'auto_deprecated', a deprecated version of         'auto' is used as a default indicating that no explicit value of gamma


from scipy.sparse.linalg import eigsh  from ..utils import check_random_state<ins>from ..utils.extmath import svd_flip</ins> from ..utils.validation import check_is_fitted, check_array from ..exceptions import NotFittedError from ..base import BaseEstimator, TransformerMixin, _UnstableOn32BitMixin


maxiter=self.max_iter,                                                 v0=v0) <ins>        # flip eigenvectors' sign to enforce deterministic output        self.alphas_, _ = svd_flip(self.alphas_,                                   np.empty_like(self.alphas_).T)</ins>         # sort eigenvectors in descending order         indices = self.lambdas_.argsort()[::-1]         self.lambdas_ = self.lambdas_[indices]


- convert list of strings to object dtype         - check for missing values for object dtype data (check_array does           not do that)        - return list of features (arrays): this list of features is          constructed feature by feature to preserve the data types          of pandas DataFrame columns, as otherwise information is lost          and cannot be used, eg for the `categories_` attribute.          """        X_temp = check_array(X, dtype=None)        if not hasattr(X, 'dtype') and np.issubdtype(X_temp.dtype, np.str_):            X = check_array(X, dtype=np.object)        if not (hasattr(X, 'iloc') and getattr(X, 'ndim', 0) == 2):            # if not a dataframe, do normal check_array validation            X_temp = check_array(X, dtype=None)            if (not hasattr(X, 'dtype')                    and np.issubdtype(X_temp.dtype, np.str_)):                X = check_array(X, dtype=np.object)            else:                X = X_temp            needs_validation = False         else:            X = X_temp            # pandas dataframe, do validation later column by column, in order            # to keep the dtype information to be used in the encoder.            needs_validation = True         return X        n_samples, n_features = X.shape        X_columns = []     def _fit(self, X, handle_unknown='error'):        X = self._check_X(X)        for i in range(n_features):            Xi = self._get_feature(X, feature_idx=i)            Xi = check_array(Xi, ensure_2d=False, dtype=None,                             force_all_finite=needs_validation)            X_columns.append(Xi)         n_samples, n_features = X.shape        return X_columns, n_samples, n_features    def _get_feature(self, X, feature_idx):        if hasattr(X, 'iloc'):            # pandas dataframes            return X.iloc[:, feature_idx]        # numpy arrays, sparse arrays        return X[:, feature_idx]    def _fit(self, X, handle_unknown='error'):        X_list, n_samples, n_features = self._check_X(X)          if self._categories != 'auto':            if X.dtype != object:                for cats in self._categories:                    if not np.all(np.sort(cats) == np.array(cats)):                        raise ValueError("Unsorted categories are not "                                         "supported for numerical categories")             if len(self._categories) != n_features:                 raise ValueError("Shape mismatch: if n_values is an array,"                                  " it has to be of shape (n_features,).")


self.categories_ = []          for i in range(n_features):            Xi = X[:, i]            Xi = X_list[i]             if self._categories == 'auto':                 cats = _encode(Xi)             else:                cats = np.array(self._categories[i], dtype=X.dtype)                cats = np.array(self._categories[i], dtype=Xi.dtype)                if Xi.dtype != object:                    if not np.all(np.sort(cats) == cats):                        raise ValueError("Unsorted categories are not "                                         "supported for numerical categories")                 if handle_unknown == 'error':                     diff = _encode_check_unknown(Xi, cats)                     if diff:


self.categories_.append(cats)      def _transform(self, X, handle_unknown='error'):        X = self._check_X(X)        X_list, n_samples, n_features = self._check_X(X)         _, n_features = X.shape        X_int = np.zeros_like(X, dtype=np.int)        X_mask = np.ones_like(X, dtype=np.bool)        X_int = np.zeros((n_samples, n_features), dtype=np.int)        X_mask = np.ones((n_samples, n_features), dtype=np.bool)          for i in range(n_features):            Xi = X[:, i]            Xi = X_list[i]             diff, valid_mask = _encode_check_unknown(Xi, self.categories_[i],                                                      return_mask=True)


" classes.")             self.class_log_prior_ = np.log(class_prior)         elif self.fit_prior:            with warnings.catch_warnings():                # silence the warning when count is 0 because class was not yet                # observed                warnings.simplefilter("ignore", RuntimeWarning)                log_class_count = np.log(self.class_count_)             # empirical prior, with sample_weight taken into account            self.class_log_prior_ = (np.log(self.class_count_) -            self.class_log_prior_ = (log_class_count -                                      np.log(self.class_count_.sum()))         else:             self.class_log_prior_ = np.full(n_classes, -np.log(n_classes))


from warnings import warn  from ..tree import ExtraTreeRegressorfrom ..utils import check_random_state, check_arrayfrom ..utils import (    check_random_state,    check_array,    gen_batches,    get_chunk_n_rows,) from ..utils.fixes import _joblib_parallel_argsfrom ..utils.validation import check_is_fittedfrom ..utils.validation import check_is_fitted, _num_samples from ..base import OutlierMixin  from .bagging import BaseBagging


"match the input. Model n_features is {0} and "                              "input n_features is {1}."                              "".format(self.n_features_, X.shape[1]))        n_samples = X.shape[0]         n_samples_leaf = np.zeros(n_samples, order="f")        depths = np.zeros(n_samples, order="f")        # Take the opposite of the scores as bigger is better (here less        # abnormal)        return -self._compute_chunked_score_samples(X)    @property    def threshold_(self):        if self.behaviour != 'old':            raise AttributeError("threshold_ attribute does not exist when "                                 "behaviour != 'old'")        warn("threshold_ attribute is deprecated in 0.20 and will"             " be removed in 0.22.", DeprecationWarning)        return self._threshold_    def _compute_chunked_score_samples(self, X):        n_samples = _num_samples(X)          if self._max_features == X.shape[1]:             subsample_features = False         else:             subsample_features = True         # We get as many rows as possible within our working_memory budget        # (defined by sklearn.get_config()['working_memory']) to store        # self._max_features in each row during computation.        #        # Note:        #  - this will get at least 1 row, even if 1 row of score will        #    exceed working_memory.        #  - this does only account for temporary memory usage while loading        #    the data needed to compute the scores -- the returned scores        #    themselves are 1D.        chunk_n_rows = get_chunk_n_rows(row_bytes=16 * self._max_features,                                        max_n_rows=n_samples)        slices = gen_batches(n_samples, chunk_n_rows)        scores = np.zeros(n_samples, order="f")        for sl in slices:            # compute score on the slices of test samples:            scores[sl] = self._compute_score_samples(X[sl], subsample_features)        return scores    def _compute_score_samples(self, X, subsample_features):        """Compute the score of each samples in X going through the extra trees.        Parameters        ----------        X : array-like or sparse matrix        subsample_features : bool,            whether features should be subsampled        """        n_samples = X.shape[0]        depths = np.zeros(n_samples, order="f")         for tree, features in zip(self.estimators_, self.estimators_features_):            if subsample_features:                X_subset = X[:, features]            else:                X_subset = X            X_subset = X[:, features] if subsample_features else X             leaves_index = tree.apply(X_subset)             node_indicator = tree.decision_path(X_subset)             n_samples_leaf = tree.tree_.n_node_samples[leaves_index]


/ (len(self.estimators_)                * _average_path_length([self.max_samples_]))         )        # Take the opposite of the scores as bigger is better (here less        # abnormal)        return -scores    @property    def threshold_(self):        if self.behaviour != 'old':            raise AttributeError("threshold_ attribute does not exist when "                                 "behaviour != 'old'")        warn("threshold_ attribute is deprecated in 0.20 and will"             " be removed in 0.22.", DeprecationWarning)        return self._threshold_        return scores   def _average_path_length(n_samples_leaf):


classifier.set_params(class_weight=class_weight)     coef_manual = classifier.fit(X, y).coef_.copy()     assert_allclose(coef_balanced, coef_manual)    assert_allclose(coef_balanced, coef_manual,                    err_msg="Classifier %s is not computing"                    " class_weight=balanced properly."                    % name)   @ignore_warnings(category=(DeprecationWarning, FutureWarning))


self : object         """         X, y = check_X_y(            X, y, copy=False, accept_sparse=['csr'], y_numeric=True)            X, y, copy=False, accept_sparse=['csr'], y_numeric=True,            dtype=[np.float64, np.float32])         if sample_weight is not None:             sample_weight = np.array(sample_weight)             check_consistent_length(y, sample_weight)


X_scaled = X_std * (max - min) + min      where min, max = feature_range.<del> </del><ins></ins>     The transformation is calculated as (when ``axis=0``)::         X_scaled = scale * X + min - X.min(axis=0) * scale


-----     NaNs are treated as missing values: disregarded in fit, and maintained in     transform.<del>    </del><ins></ins>     We use a biased estimator for the standard deviation, equivalent to     `numpy.std(x, ddof=0)`. Note that the choice of `ddof` is unlikely to     affect model performance.


Parameters     ----------    n_quantiles : int, optional (default=1000)    n_quantiles : int, optional (default=1000 or n_samples)         Number of quantiles to be computed. It corresponds to the number         of landmarks used to discretize the cumulative distribution function.        If n_quantiles is larger than the number of samples, n_quantiles is set        to the number of samples as a larger number of quantiles does not give        a better approximation of the cumulative distribution function        estimator.      output_distribution : str, optional (default='uniform')         Marginal distribution for the transformed data. The choices are


Attributes     ----------<ins>    n_quantiles_ : integer        The actual number of quantiles used to discretize the cumulative        distribution function.</ins>     quantiles_ : ndarray, shape (n_quantiles, n_features)         The values corresponding the quantiles of reference.


self.subsample))          X = self._check_inputs(X)        n_samples = X.shape[0]        if self.n_quantiles > n_samples:            warnings.warn("n_quantiles (%s) is greater than the total number "                          "of samples (%s). n_quantiles is set to "                          "n_samples."                          % (self.n_quantiles, n_samples))        self.n_quantiles_ = max(1, min(self.n_quantiles, n_samples))         rng = check_random_state(self.random_state)          # Create the quantiles of reference        self.references_ = np.linspace(0, 1, self.n_quantiles,        self.references_ = np.linspace(0, 1, self.n_quantiles_,                                        endpoint=True)         if sparse.issparse(X):             self._sparse_fit(X, rng)


Axis used to compute the means and standard deviations along. If 0,         transform each feature, otherwise (if 1) transform each sample.     n_quantiles : int, optional (default=1000)    n_quantiles : int, optional (default=1000 or n_samples)         Number of quantiles to be computed. It corresponds to the number         of landmarks used to discretize the cumulative distribution function.        If n_quantiles is larger than the number of samples, n_quantiles is set        to the number of samples as a larger number of quantiles does not give        a better approximation of the cumulative distribution function        estimator.      output_distribution : str, optional (default='uniform')         Marginal distribution for the transformed data. The choices are


return_n_iter=False, return_intercept=False,                       X_scale=None, X_offset=None):     if return_intercept and sparse.issparse(X) and solver != 'sag':        if solver != 'auto':            warnings.warn("In Ridge, only 'sag' solver can currently fit the "                          "intercept when X is sparse. Solver has been "                          "automatically changed into 'sag'.")        solver = 'sag'    has_sw = sample_weight is not None    if solver == 'auto':        if return_intercept:            # only sag supports fitting intercept directly            solver = "sag"        elif not sparse.issparse(X):            solver = "cholesky"        else:            solver = "sparse_cg"    if solver not in ('sparse_cg', 'cholesky', 'svd', 'lsqr', 'sag', 'saga'):        raise ValueError("Known solvers are 'sparse_cg', 'cholesky', 'svd'"                         " 'lsqr', 'sag' or 'saga'. Got %s." % solver)    if return_intercept and solver != 'sag':        raise ValueError("In Ridge, only 'sag' solver can directly fit the "                         "intercept. Please change solver to 'sag' or set "                         "return_intercept=False.")      _dtype = [np.float64, np.float32]


raise ValueError("Number of samples in X and y does not correspond:"                          " %d != %d" % (n_samples, n_samples_))     has_sw = sample_weight is not None     if solver == 'auto':        # cholesky if it's a dense array and cg in any other case        if not sparse.issparse(X) or has_sw:            solver = 'cholesky'        else:            solver = 'sparse_cg'      if has_sw:         if np.atleast_1d(sample_weight).ndim > 1:


if alpha.size == 1 and n_targets > 1:         alpha = np.repeat(alpha, n_targets) <del>    if solver not in ('sparse_cg', 'cholesky', 'svd', 'lsqr', 'sag', 'saga'):        raise ValueError('Solver %s not understood' % solver)</del>      n_iter = None     if solver == 'sparse_cg':


# add the offset which was subtracted by _preprocess_data             self.intercept_ += y_offset         else:            if sparse.issparse(X):            if sparse.issparse(X) and self.solver == 'sparse_cg':                 # required to fit intercept with sparse_cg solver                 params = {'X_offset': X_offset, 'X_scale': X_scale}             else:


float_min = np.finfo(predictions.dtype).min             default_values = {'decision_function': float_min,                               'predict_log_proba': float_min,                              'predict_proba': 0}                              'predict_proba': 0.0}             predictions_for_all_classes = np.full((_num_samples(predictions),                                                    n_classes),                                                  default_values[method])                                                  default_values[method],                                                  predictions.dtype)             predictions_for_all_classes[:, estimator.classes_] = predictions             predictions = predictions_for_all_classes     return predictions, test


from collections import defaultdict import platform import inspect<ins>import re</ins>  import numpy as np


return self     def __repr__(self):    def __repr__(self, N_CHAR_MAX=700):        # N_CHAR_MAX is the (approximate) maximum number of non-blank        # characters to render. We pass it as an optional parameter to ease        # the tests.         from .utils._pprint import _EstimatorPrettyPrinter         N_CHAR_MAX = 700  # number of non-whitespace or newline chars         N_MAX_ELEMENTS_TO_SHOW = 30  # number of elements to show in sequences          # use ellipsis for sequences with a lot of elements


repr_ = pp.pformat(self)         # Use bruteforce ellipsis if string is very long        if len(''.join(repr_.split())) > N_CHAR_MAX:  # check non-blank chars            lim = N_CHAR_MAX // 2            repr_ = repr_[:lim] + '...' + repr_[-lim:]        # Use bruteforce ellipsis when there are a lot of non-blank characters        n_nonblank = len(''.join(repr_.split()))        if n_nonblank > N_CHAR_MAX:            lim = N_CHAR_MAX // 2  # apprx number of chars to keep on both ends            regex = r'^(\s*\S){%d}' % lim            # The regex '^(\s*\S){%d}' % n            # matches from the start of the string until the nth non-blank            # character:            # - ^ matches the start of string            # - (pattern){n} matches n repetitions of pattern            # - \s*\S matches a non-blank char following zero or more blanks            left_lim = re.match(regex, repr_).end()            right_lim = re.match(regex, repr_[::-1]).end()            if '\n' in repr_[left_lim:-right_lim]:                # The left side and right side aren't on the same line.                # To avoid weird cuts, e.g.:                # categoric...ore',                # we need to start the right side with an appropriate newline                # character so that it renders properly as:                # categoric...                # handle_unknown='ignore',                # so we add [^\n]*\n which matches until the next \n                regex += r'[^\n]*\n'                right_lim = re.match(regex, repr_[::-1]).end()            ellipsis = '...'            if left_lim + len(ellipsis) < len(repr_) - right_lim:                # Only add ellipsis if it results in a shorter repr                repr_ = repr_[:left_lim] + '...' + repr_[-right_lim:]         return repr_      def __getstate__(self):


if (relevant.size == 0 or relevant.size == n_labels):             # If all labels are relevant or unrelevant, the score is also             # equal to 1. The label ranking has no meaning.            out += 1.            continue            aux = 1.        else:            scores_i = y_score[i]            rank = rankdata(scores_i, 'max')[relevant]            L = rankdata(scores_i[relevant], 'max')            aux = (L / rank).mean()         scores_i = y_score[i]        rank = rankdata(scores_i, 'max')[relevant]        L = rankdata(scores_i[relevant], 'max')        aux = (L / rank).mean()         if sample_weight is not None:             aux = aux * sample_weight[i]         out += aux


if self._categories != 'auto':             if len(self._categories) != n_features:                raise ValueError("Shape mismatch: if n_values is an array,"                raise ValueError("Shape mismatch: if categories is an array,"                                  " it has to be of shape (n_features,).")          self.categories_ = []


def mean_squared_error(y_true, y_pred,                        sample_weight=None,                       multioutput='uniform_average'):                       multioutput='uniform_average', squared=True):     """Mean squared error regression loss      Read more in the :ref:`User Guide <mean_squared_error>`.


'uniform_average' :             Errors of all outputs are averaged with uniform weight. <ins>    squared : boolean value, optional (default = True)        If True returns MSE value, if False returns RMSE value.</ins>     Returns     -------     loss : float or ndarray of floats


>>> y_pred = [2.5, 0.0, 2, 8]     >>> mean_squared_error(y_true, y_pred)     0.375<ins>    >>> y_true = [3, -0.5, 2, 7]    >>> y_pred = [2.5, 0.0, 2, 8]    >>> mean_squared_error(y_true, y_pred, squared=False)    0.612...</ins>     >>> y_true = [[0.5, 1],[-1, 1],[7, -6]]     >>> y_pred = [[0, 2],[-1, 2],[8, -5]]     >>> mean_squared_error(y_true, y_pred)


# pass None as weights to np.average: uniform mean             multioutput = None     return np.average(output_errors, weights=multioutput)    mse = np.average(output_errors, weights=multioutput)    return mse if squared else np.sqrt(mse)   def mean_squared_log_error(y_true, y_pred,diff --git a/sklearn/metrics/scorer.py b/sklearn/metrics/scorer.py-- a/sklearn/metrics/scorer.py++ b/sklearn/metrics/scorer.py


greater_is_better=False) neg_median_absolute_error_scorer = make_scorer(median_absolute_error,                                                greater_is_better=False)<ins>neg_root_mean_squared_error_scorer = make_scorer(mean_squared_error,                                                 greater_is_better=False,                                                 squared=False)</ins> neg_mean_poisson_deviance_scorer = make_scorer(     mean_tweedie_deviance, p=1., greater_is_better=False )


neg_mean_absolute_error=neg_mean_absolute_error_scorer,                neg_mean_squared_error=neg_mean_squared_error_scorer,                neg_mean_squared_log_error=neg_mean_squared_log_error_scorer,<ins>               neg_root_mean_squared_error=neg_root_mean_squared_error_scorer,</ins>                neg_mean_poisson_deviance=neg_mean_poisson_deviance_scorer,                neg_mean_gamma_deviance=neg_mean_gamma_deviance_scorer,                accuracy=accuracy_scorer, roc_auc=roc_auc_scorer,


raw_predictions = np.zeros(shape=(X.shape[0], self.loss_.K),                                            dtype=np.float64)             else:                try:                    self.init_.fit(X, y, sample_weight=sample_weight)                except TypeError:                    if sample_weight_is_none:                        self.init_.fit(X, y)                    else:                        raise ValueError(                            "The initial estimator {} does not support sample "                            "weights.".format(self.init_.__class__.__name__))                # XXX clean this once we have a support_sample_weight tag                if sample_weight_is_none:                    self.init_.fit(X, y)                else:                    msg = ("The initial estimator {} does not support sample "                           "weights.".format(self.init_.__class__.__name__))                    try:                        self.init_.fit(X, y, sample_weight=sample_weight)                    except TypeError:  # regular estimator without SW support                        raise ValueError(msg)                    except ValueError as e:                        if 'not enough values to unpack' in str(e):  # pipeline                            raise ValueError(msg) from e                        else:  # regular estimator whose input checking failed                            raise                  raw_predictions = \                     self.loss_.get_init_raw_predictions(X, self.init_)              begin_at_stage = 0              # The rng state must be preserved if warm_start is True


Returns an instance of self.         """         X, y = check_X_y(X, y, accept_sparse=['csc', 'csr', 'coo'],                         force_all_finite=False)                         force_all_finite=False, allow_nd=True)         X, y = indexable(X, y)         le = LabelBinarizer().fit(y)         self.classes_ = le.classes_


verbose : int, optional (default=0)         Controls the verbosity of the tree building process. <ins>    warm_start : bool, optional (default=False)        When set to ``True``, reuse the solution of the previous call to fit        and add more estimators to the ensemble, otherwise, just fit a whole        new forest. See :term:`the Glossary <warm_start>`.        .. versionadded:: 0.21</ins>      Attributes     ----------


n_jobs=None,                  behaviour='old',                  random_state=None,                 verbose=0):                 verbose=0,                 warm_start=False):         super().__init__(             base_estimator=ExtraTreeRegressor(                 max_features=1,


n_estimators=n_estimators,             max_samples=max_samples,             max_features=max_features,<ins>            warm_start=warm_start,</ins>             n_jobs=n_jobs,             random_state=random_state,             verbose=verbose)


from ..preprocessing import scale from ..utils import check_random_state from ..utils.fixes import _astype_copy_falsefrom ..utils.validation import check_X_yfrom ..utils.validation import check_array, check_X_y from ..utils.multiclass import check_classification_targets


X, y = check_X_y(X, y, accept_sparse='csc', y_numeric=not discrete_target)     n_samples, n_features = X.shape     if discrete_features == 'auto':        discrete_features = issparse(X)    if isinstance(discrete_features, bool):    if isinstance(discrete_features, (str, bool)):        if isinstance(discrete_features, str):            if discrete_features == 'auto':                discrete_features = issparse(X)            else:                raise ValueError("Invalid string value for discrete_features.")         discrete_mask = np.empty(n_features, dtype=bool)         discrete_mask.fill(discrete_features)     else:        discrete_features = np.asarray(discrete_features)        discrete_features = check_array(discrete_features, ensure_2d=False)         if discrete_features.dtype != 'bool':             discrete_mask = np.zeros(n_features, dtype=bool)             discrete_mask[discrete_features] = True


except TypeError:  # regular estimator without SW support                         raise ValueError(msg)                     except ValueError as e:                        if 'not enough values to unpack' in str(e):  # pipeline                        if "pass parameters to specific steps of "\                           "your pipeline using the "\                           "stepname__parameter" in str(e):  # pipeline                             raise ValueError(msg) from e                         else:  # regular estimator whose input checking failed                             raisediff --git a/sklearn/pipeline.py b/sklearn/pipeline.py-- a/sklearn/pipeline.py++ b/sklearn/pipeline.py


fit_params_steps = {name: {} for name, step in self.steps                             if step is not None}         for pname, pval in fit_params.items():<ins>            if '__' not in pname:                raise ValueError(                    "Pipeline.fit does not accept the {} parameter. "                    "You can pass parameters to specific steps of your "                    "pipeline using the stepname__parameter format, e.g. "                    "`Pipeline.fit(X, y, logisticregression__sample_weight"                    "=sample_weight)`.".format(pname))</ins>             step, param = pname.split('__', 1)             fit_params_steps[step][param] = pval         Xt = X


import numpy as np  from ..utils import indexable, check_random_state, safe_indexing<ins>from ..utils import _approximate_mode</ins> from ..utils.validation import _num_samples, column_or_1d from ..utils.validation import check_array from ..utils.multiclass import type_of_target


return super().split(X, y, groups)  def _approximate_mode(class_counts, n_draws, rng):    """Computes approximate mode of multivariate hypergeometric.    This is an approximation to the mode of the multivariate    hypergeometric given by class_counts and n_draws.    It shouldn't be off by more than one.    It is the mostly likely outcome of drawing n_draws many    samples from the population given by class_counts.    Parameters    ----------    class_counts : ndarray of int        Population per class.    n_draws : int        Number of draws (samples to draw) from the overall population.    rng : random state        Used to break ties.    Returns    -------    sampled_classes : ndarray of int        Number of samples drawn from each class.        np.sum(sampled_classes) == n_draws    Examples    --------    >>> import numpy as np    >>> from sklearn.model_selection._split import _approximate_mode    >>> _approximate_mode(class_counts=np.array([4, 2]), n_draws=3, rng=0)    array([2, 1])    >>> _approximate_mode(class_counts=np.array([5, 2]), n_draws=4, rng=0)    array([3, 1])    >>> _approximate_mode(class_counts=np.array([2, 2, 2, 1]),    ...                   n_draws=2, rng=0)    array([0, 1, 1, 0])    >>> _approximate_mode(class_counts=np.array([2, 2, 2, 1]),    ...                   n_draws=2, rng=42)    array([1, 1, 0, 0])    """    rng = check_random_state(rng)    # this computes a bad approximation to the mode of the    # multivariate hypergeometric given by class_counts and n_draws    continuous = n_draws * class_counts / class_counts.sum()    # floored means we don't overshoot n_samples, but probably undershoot    floored = np.floor(continuous)    # we add samples according to how much "left over" probability    # they had, until we arrive at n_samples    need_to_add = int(n_draws - floored.sum())    if need_to_add > 0:        remainder = continuous - floored        values = np.sort(np.unique(remainder))[::-1]        # add according to remainder, but break ties        # randomly to avoid biases        for value in values:            inds, = np.where(remainder == value)            # if we need_to_add less than what's in inds            # we draw randomly from them.            # if we need to add more, we add them all and            # go to the next value            add_now = min(len(inds), need_to_add)            inds = rng.choice(inds, size=add_now, replace=False)            floored[inds] += 1            need_to_add -= add_now            if need_to_add == 0:                break    return floored.astype(np.int) class StratifiedShuffleSplit(BaseShuffleSplit):     """Stratified ShuffleSplit cross-validator diff --git a/sklearn/utils/__init__.py b/sklearn/utils/__init__.py-- a/sklearn/utils/__init__.py++ b/sklearn/utils/__init__.py


generator; If None, the random number generator is the RandomState         instance used by `np.random`. <ins>    stratify : array-like or None (default=None)        If not None, data is split in a stratified fashion, using this as        the class labels.</ins>     Returns     -------     resampled_arrays : sequence of indexable data-structures


>>> resample(y, n_samples=2, random_state=0)       array([0, 1])     Example using stratification::      >>> y = [0, 0, 1, 1, 1, 1, 1, 1, 1]      >>> resample(y, n_samples=5, replace=False, stratify=y,      ...          random_state=0)      [1, 1, 1, 0, 1]      See also     --------     :func:`sklearn.utils.shuffle`     """     random_state = check_random_state(options.pop('random_state', None))     replace = options.pop('replace', True)     max_n_samples = options.pop('n_samples', None)    stratify = options.pop('stratify', None)     if options:         raise ValueError("Unexpected kw arguments: %r" % options.keys())


check_consistent_length(*arrays)     if replace:        indices = random_state.randint(0, n_samples, size=(max_n_samples,))    if stratify is None:        if replace:            indices = random_state.randint(0, n_samples, size=(max_n_samples,))        else:            indices = np.arange(n_samples)            random_state.shuffle(indices)            indices = indices[:max_n_samples]     else:        indices = np.arange(n_samples)        random_state.shuffle(indices)        indices = indices[:max_n_samples]        # Code adapted from StratifiedShuffleSplit()        y = check_array(stratify, ensure_2d=False, dtype=None)        if y.ndim == 2:            # for multi-label y, map each distinct row to a string repr            # using join because str(row) uses an ellipsis if len(row) > 1000            y = np.array([' '.join(row.astype('str')) for row in y])        classes, y_indices = np.unique(y, return_inverse=True)        n_classes = classes.shape[0]        class_counts = np.bincount(y_indices)        # Find the sorted list of instances for each class:        # (np.unique above performs a sort, so code is O(n logn) already)        class_indices = np.split(np.argsort(y_indices, kind='mergesort'),                                 np.cumsum(class_counts)[:-1])        n_i = _approximate_mode(class_counts, max_n_samples, random_state)        indices = []        for i in range(n_classes):            indices_i = random_state.choice(class_indices[i], n_i[i],                                            replace=replace)            indices.extend(indices_i)        indices = random_state.permutation(indices)      # convert sparse matrices to CSR for row-based indexing     arrays = [a.tocsr() if issparse(a) else a for a in arrays]


return bool(isinstance(x, numbers.Real) and np.isnan(x))  <ins>def _approximate_mode(class_counts, n_draws, rng):    """Computes approximate mode of multivariate hypergeometric.    This is an approximation to the mode of the multivariate    hypergeometric given by class_counts and n_draws.    It shouldn't be off by more than one.    It is the mostly likely outcome of drawing n_draws many    samples from the population given by class_counts.    Parameters    ----------    class_counts : ndarray of int        Population per class.    n_draws : int        Number of draws (samples to draw) from the overall population.    rng : random state        Used to break ties.    Returns    -------    sampled_classes : ndarray of int        Number of samples drawn from each class.        np.sum(sampled_classes) == n_draws    Examples    --------    >>> import numpy as np    >>> from sklearn.utils import _approximate_mode    >>> _approximate_mode(class_counts=np.array([4, 2]), n_draws=3, rng=0)    array([2, 1])    >>> _approximate_mode(class_counts=np.array([5, 2]), n_draws=4, rng=0)    array([3, 1])    >>> _approximate_mode(class_counts=np.array([2, 2, 2, 1]),    ...                   n_draws=2, rng=0)    array([0, 1, 1, 0])    >>> _approximate_mode(class_counts=np.array([2, 2, 2, 1]),    ...                   n_draws=2, rng=42)    array([1, 1, 0, 0])    """    rng = check_random_state(rng)    # this computes a bad approximation to the mode of the    # multivariate hypergeometric given by class_counts and n_draws    continuous = n_draws * class_counts / class_counts.sum()    # floored means we don't overshoot n_samples, but probably undershoot    floored = np.floor(continuous)    # we add samples according to how much "left over" probability    # they had, until we arrive at n_samples    need_to_add = int(n_draws - floored.sum())    if need_to_add > 0:        remainder = continuous - floored        values = np.sort(np.unique(remainder))[::-1]        # add according to remainder, but break ties        # randomly to avoid biases        for value in values:            inds, = np.where(remainder == value)            # if we need_to_add less than what's in inds            # we draw randomly from them.            # if we need to add more, we add them all and            # go to the next value            add_now = min(len(inds), need_to_add)            inds = rng.choice(inds, size=add_now, replace=False)            floored[inds] += 1            need_to_add -= add_now            if need_to_add == 0:                break    return floored.astype(np.int)</ins> def check_matplotlib_support(caller_name):     """Raise ImportError with detailed error message if mpl is not installed.


Y_norm_squared : array-like, shape (n_samples_2, ), optional         Pre-computed dot-products of vectors in Y (e.g.,         ``(Y**2).sum(axis=1)``)<ins>        May be ignored in some cases, see the note below.</ins>      squared : boolean, optional         Return squared Euclidean distances.


X_norm_squared : array-like, shape = [n_samples_1], optional         Pre-computed dot-products of vectors in X (e.g.,         ``(X**2).sum(axis=1)``)        May be ignored in some cases, see the note below.    Notes    -----    To achieve better accuracy, `X_norm_squared` and `Y_norm_squared` may be    unused if they are passed as ``float32``.      Returns     -------    distances : {array, sparse matrix}, shape (n_samples_1, n_samples_2)    distances : array, shape (n_samples_1, n_samples_2)      Examples     --------


"""     X, Y = check_pairwise_arrays(X, Y) <ins>    # If norms are passed as float32, they are unused. If arrays are passed as    # float32, norms needs to be recomputed on upcast chunks.    # TODO: use a float64 accumulator in row_norms to avoid the latter.</ins>     if X_norm_squared is not None:         XX = check_array(X_norm_squared)         if XX.shape == (1, X.shape[0]):


elif XX.shape != (X.shape[0], 1):             raise ValueError(                 "Incompatible dimensions for X and X_norm_squared")        if XX.dtype == np.float32:            XX = None    elif X.dtype == np.float32:        XX = None     else:         XX = row_norms(X, squared=True)[:, np.newaxis]     if X is Y:  # shortcut in the common case euclidean_distances(X, X)    if X is Y and XX is not None:        # shortcut in the common case euclidean_distances(X, X)         YY = XX.T     elif Y_norm_squared is not None:         YY = np.atleast_2d(Y_norm_squared)


if YY.shape != (1, Y.shape[0]):             raise ValueError(                 "Incompatible dimensions for Y and Y_norm_squared")        if YY.dtype == np.float32:            YY = None    elif Y.dtype == np.float32:        YY = None     else:         YY = row_norms(Y, squared=True)[np.newaxis, :]     distances = safe_sparse_dot(X, Y.T, dense_output=True)    distances *= -2    distances += XX    distances += YY    if X.dtype == np.float32:        # To minimize precision issues with float32, we compute the distance        # matrix on chunks of X and Y upcast to float64        distances = _euclidean_distances_upcast(X, XX, Y, YY)    else:        # if dtype is already float64, no need to chunk and upcast        distances = - 2 * safe_sparse_dot(X, Y.T, dense_output=True)        distances += XX        distances += YY     np.maximum(distances, 0, out=distances)     # Ensure that distances between vectors and themselves are set to 0.0.    # This may not be the case due to floating point rounding errors.     if X is Y:        # Ensure that distances between vectors and themselves are set to 0.0.        # This may not be the case due to floating point rounding errors.        distances.flat[::distances.shape[0] + 1] = 0.0        np.fill_diagonal(distances, 0)      return distances if squared else np.sqrt(distances, out=distances)  def _euclidean_distances_upcast(X, XX=None, Y=None, YY=None):    """Euclidean distances between X and Y    Assumes X and Y have float32 dtype.    Assumes XX and YY have float64 dtype or are None.    X and Y are upcast to float64 by chunks, which size is chosen to limit    memory increase by approximately 10% (at least 10MiB).    """    n_samples_X = X.shape[0]    n_samples_Y = Y.shape[0]    n_features = X.shape[1]    distances = np.empty((n_samples_X, n_samples_Y), dtype=np.float32)    x_density = X.nnz / np.prod(X.shape) if issparse(X) else 1    y_density = Y.nnz / np.prod(Y.shape) if issparse(Y) else 1    # Allow 10% more memory than X, Y and the distance matrix take (at least    # 10MiB)    maxmem = max(        ((x_density * n_samples_X + y_density * n_samples_Y) * n_features         + (x_density * n_samples_X * y_density * n_samples_Y)) / 10,        10 * 2**17)    # The increase amount of memory in 8-byte blocks is:    # - x_density * batch_size * n_features (copy of chunk of X)    # - y_density * batch_size * n_features (copy of chunk of Y)    # - batch_size * batch_size (chunk of distance matrix)    # Hence x² + (xd+yd)kx = M, where x=batch_size, k=n_features, M=maxmem    #                                 xd=x_density and yd=y_density    tmp = (x_density + y_density) * n_features    batch_size = (-tmp + np.sqrt(tmp**2 + 4 * maxmem)) / 2    batch_size = max(int(batch_size), 1)    x_batches = gen_batches(X.shape[0], batch_size)    y_batches = gen_batches(Y.shape[0], batch_size)    for i, x_slice in enumerate(x_batches):        X_chunk = X[x_slice].astype(np.float64)        if XX is None:            XX_chunk = row_norms(X_chunk, squared=True)[:, np.newaxis]        else:            XX_chunk = XX[x_slice]        for j, y_slice in enumerate(y_batches):            if X is Y and j < i:                # when X is Y the distance matrix is symmetric so we only need                # to compute half of it.                d = distances[y_slice, x_slice].T            else:                Y_chunk = Y[y_slice].astype(np.float64)                if YY is None:                    YY_chunk = row_norms(Y_chunk, squared=True)[np.newaxis, :]                else:                    YY_chunk = YY[:, y_slice]                d = -2 * safe_sparse_dot(X_chunk, Y_chunk.T, dense_output=True)                d += XX_chunk                d += YY_chunk            distances[x_slice, y_slice] = d.astype(np.float32, copy=False)    return distances def _argmin_min_reduce(dist, start):     indices = dist.argmin(axis=1)     values = dist[np.arange(dist.shape[0]), indices]


"""============================================Curve Fitting with Bayesian Ridge Regression============================================Computes a Bayesian Ridge Regression of Sinusoids.See :ref:`bayesian_ridge_regression` for more information on the regressor.In general, when fitting a curve with a polynomial by Bayesian ridgeregression, the selection of initial values ofthe regularization parameters (alpha, lambda) may be important.This is because the regularization parameters are determined by an iterativeprocedure that depends on initial values.In this example, the sinusoid is approximated by a polynomial using differentpairs of initial values.When starting from the default values (alpha_init = 1.90, lambda_init = 1.),the bias of the resulting curve is large, and the variance is small.So, lambda_init should be relatively small (1.e-3) so as to reduce the bias.Also, by evaluating log marginal likelihood (L) ofthese models, we can determine which one is better.It can be concluded that the model with larger L is more likely."""print(__doc__)# Author: Yoshihiro Uchida <nimbus1after2a1sun7shower@gmail.com>import numpy as npimport matplotlib.pyplot as pltfrom sklearn.linear_model import BayesianRidgedef func(x): return np.sin(2*np.pi*x)# ############################################################################## Generate sinusoidal data with noisesize = 25rng = np.random.RandomState(1234)x_train = rng.uniform(0., 1., size)y_train = func(x_train) + rng.normal(scale=0.1, size=size)x_test = np.linspace(0., 1., 100)# ############################################################################## Fit by cubic polynomialn_order = 3X_train = np.vander(x_train, n_order + 1, increasing=True)X_test = np.vander(x_test, n_order + 1, increasing=True)# ############################################################################## Plot the true and predicted curves with log marginal likelihood (L)reg = BayesianRidge(tol=1e-6, fit_intercept=False, compute_score=True)fig, axes = plt.subplots(1, 2, figsize=(8, 4))for i, ax in enumerate(axes):    # Bayesian ridge regression with different initial value pairs    if i == 0:        init = [1 / np.var(y_train), 1.]  # Default values    elif i == 1:        init = [1., 1e-3]        reg.set_params(alpha_init=init[0], lambda_init=init[1])    reg.fit(X_train, y_train)    ymean, ystd = reg.predict(X_test, return_std=True)    ax.plot(x_test, func(x_test), color="blue", label="sin($2\\pi x$)")    ax.scatter(x_train, y_train, s=50, alpha=0.5, label="observation")    ax.plot(x_test, ymean, color="red", label="predict mean")    ax.fill_between(x_test, ymean-ystd, ymean+ystd,                    color="pink", alpha=0.5, label="predict std")    ax.set_ylim(-1.3, 1.3)    ax.legend()    title = "$\\alpha$_init$={:.2f},\\ \\lambda$_init$={}$".format(            init[0], init[1])    if i == 0:        title += " (Default)"    ax.set_title(title, fontsize=12)    text = "$\\alpha={:.1f}$\n$\\lambda={:.3f}$\n$L={:.1f}$".format(           reg.alpha_, reg.lambda_, reg.scores_[-1])    ax.text(0.05, -1.0, text, fontsize=12)plt.tight_layout()plt.show()diff --git a/sklearn/linear_model/bayes.py b/sklearn/linear_model/bayes.py-- a/sklearn/linear_model/bayes.py++ b/sklearn/linear_model/bayes.py


Gamma distribution prior over the lambda parameter.         Default is 1.e-6 <ins>    alpha_init : float        Initial value for alpha (precision of the noise).        If not set, alpha_init is 1/Var(y).            .. versionadded:: 0.22    lambda_init : float        Initial value for lambda (precision of the weights).        If not set, lambda_init is 1.            .. versionadded:: 0.22</ins>     compute_score : boolean, optional         If True, compute the log marginal likelihood at each iteration of the         optimization. Default is False.


>>> clf = linear_model.BayesianRidge()     >>> clf.fit([[0,0], [1, 1], [2, 2]], [0, 1, 2])     ... # doctest: +NORMALIZE_WHITESPACE    BayesianRidge(alpha_1=1e-06, alpha_2=1e-06, compute_score=False,            copy_X=True, fit_intercept=True, lambda_1=1e-06, lambda_2=1e-06,            n_iter=300, normalize=False, tol=0.001, verbose=False)    BayesianRidge(alpha_1=1e-06, alpha_2=1e-06, alpha_init=None,                  compute_score=False, copy_X=True, fit_intercept=True,                  lambda_1=1e-06, lambda_2=1e-06, lambda_init=None, n_iter=300,                  normalize=False, tol=0.001, verbose=False)     >>> clf.predict([[1, 1]])     array([1.])


"""      def __init__(self, n_iter=300, tol=1.e-3, alpha_1=1.e-6, alpha_2=1.e-6,                 lambda_1=1.e-6, lambda_2=1.e-6, compute_score=False,                 fit_intercept=True, normalize=False, copy_X=True,                 verbose=False):                 lambda_1=1.e-6, lambda_2=1.e-6, alpha_init=None,                 lambda_init=None, compute_score=False, fit_intercept=True,                 normalize=False, copy_X=True, verbose=False):         self.n_iter = n_iter         self.tol = tol         self.alpha_1 = alpha_1         self.alpha_2 = alpha_2         self.lambda_1 = lambda_1         self.lambda_2 = lambda_2        self.alpha_init = alpha_init        self.lambda_init = lambda_init         self.compute_score = compute_score         self.fit_intercept = fit_intercept         self.normalize = normalize


eps = np.finfo(np.float64).eps         # Add `eps` in the denominator to omit division by zero if `np.var(y)`         # is zero        alpha_ = 1. / (np.var(y) + eps)        lambda_ = 1.        alpha_ = self.alpha_init        lambda_ = self.lambda_init        if alpha_ is None:            alpha_ = 1. / (np.var(y) + eps)        if lambda_ is None:            lambda_ = 1.          verbose = self.verbose         lambda_1 = self.lambda_1


Returns         -------         feature_importances_ : array, shape (n_features,)            The values of this array sum to 1, unless all trees are single node            trees consisting of only the root node, in which case it will be an            array of zeros.         """         self._check_initialized()         total_sum = np.zeros((self.n_features_, ), dtype=np.float64)        for stage in self.estimators_:            stage_sum = sum(tree.tree_.compute_feature_importances(                normalize=False) for tree in stage) / len(stage)            total_sum += stage_sum        importances = total_sum / total_sum.sum()        return importances        relevant_trees = [tree                          for stage in self.estimators_ for tree in stage                          if tree.tree_.node_count > 1]        if not relevant_trees:            # degenerate case where all trees have only one node            return np.zeros(shape=self.n_features_, dtype=np.float64)        relevant_feature_importances = [            tree.tree_.compute_feature_importances(normalize=False)            for tree in relevant_trees        ]        avg_feature_importances = np.mean(relevant_feature_importances,                                          axis=0, dtype=np.float64)        return avg_feature_importances / np.sum(avg_feature_importances)      def _validate_y(self, y, sample_weight):         # 'sample_weight' is not utilised but is used for


from .isotonic import IsotonicRegression from .svm import LinearSVC from .model_selection import check_cv<del>from .metrics.classification import _check_binary_probabilistic_predictions</del>   class CalibratedClassifierCV(BaseEstimator, ClassifierMixin):


"""     y_true = column_or_1d(y_true)     y_prob = column_or_1d(y_prob)<ins>    check_consistent_length(y_true, y_prob)</ins>      if normalize:  # Normalize predicted values into interval [0, 1]         y_prob = (y_prob - y_prob.min()) / (y_prob.max() - y_prob.min())


raise ValueError("y_prob has values outside [0, 1] and normalize is "                          "set to False.")     y_true = _check_binary_probabilistic_predictions(y_true, y_prob)    labels = np.unique(y_true)    if len(labels) > 2:        raise ValueError("Only binary classification is supported. "                         "Provided labels %s." % labels)    y_true = label_binarize(y_true, labels)[:, 0]      if strategy == 'quantile':  # Determine bin edges by distribution of data         quantiles = np.linspace(0, 1, n_bins + 1)diff --git a/sklearn/metrics/classification.py b/sklearn/metrics/classification.py-- a/sklearn/metrics/classification.py++ b/sklearn/metrics/classification.py


from scipy.sparse import coo_matrix from scipy.sparse import csr_matrix from ..preprocessing import LabelBinarizer, label_binarizefrom ..preprocessing import LabelBinarizer from ..preprocessing import LabelEncoder from ..utils import assert_all_finite from ..utils import check_array


return np.average(losses, weights=sample_weight)  <del>def _check_binary_probabilistic_predictions(y_true, y_prob):    """Check that y_true is binary and y_prob contains valid probabilities"""    check_consistent_length(y_true, y_prob)    labels = np.unique(y_true)    if len(labels) > 2:        raise ValueError("Only binary classification is supported. "                         "Provided labels %s." % labels)    if y_prob.max() > 1:        raise ValueError("y_prob contains values greater than 1.")    if y_prob.min() < 0:        raise ValueError("y_prob contains values less than 0.")    return label_binarize(y_true, labels)[:, 0]</del> def brier_score_loss(y_true, y_prob, sample_weight=None, pos_label=None):     """Compute the Brier score.     The smaller the Brier score, the better, hence the naming with "loss".


Sample weights.      pos_label : int or str, default=None        Label of the positive class. If None, the maximum label is used as        positive class        Label of the positive class.        Defaults to the greater label unless y_true is all 0 or all -1        in which case pos_label defaults to 1.      Returns     -------


assert_all_finite(y_prob)     check_consistent_length(y_true, y_prob, sample_weight)     labels = np.unique(y_true)    if len(labels) > 2:        raise ValueError("Only binary classification is supported. "                         "Labels in y_true: %s." % labels)    if y_prob.max() > 1:        raise ValueError("y_prob contains values greater than 1.")    if y_prob.min() < 0:        raise ValueError("y_prob contains values less than 0.")    # if pos_label=None, when y_true is in {-1, 1} or {0, 1},    # pos_labe is set to 1 (consistent with precision_recall_curve/roc_curve),    # otherwise pos_label is set to the greater label    # (different from precision_recall_curve/roc_curve,    # the purpose is to keep backward compatibility).     if pos_label is None:        pos_label = y_true.max()        if (np.array_equal(labels, [0]) or                np.array_equal(labels, [-1])):            pos_label = 1        else:            pos_label = y_true.max()     y_true = np.array(y_true == pos_label, int)    y_true = _check_binary_probabilistic_predictions(y_true, y_prob)     return np.average((y_true - y_prob) ** 2, weights=sample_weight)diff --git a/sklearn/metrics/ranking.py b/sklearn/metrics/ranking.py-- a/sklearn/metrics/ranking.py++ b/sklearn/metrics/ranking.py


Parameters     ----------     y_true : array, shape = [n_samples]        True targets of binary classification in range {-1, 1} or {0, 1}.        True binary labels. If labels are not either {-1, 1} or {0, 1}, then        pos_label should be explicitly given.      probas_pred : array, shape = [n_samples]         Estimated probabilities or decision function.      pos_label : int or str, default=None        The label of the positive class        The label of the positive class.        When ``pos_label=None``, if y_true is in {-1, 1} or {0, 1},        ``pos_label`` is set to 1, otherwise an error will be raised.      sample_weight : array-like of shape = [n_samples], optional         Sample weights.


(as returned by "decision_function" on some classifiers).      pos_label : int or str, default=None        Label considered as positive and others are considered negative.        The label of the positive class.        When ``pos_label=None``, if y_true is in {-1, 1} or {0, 1},        ``pos_label`` is set to 1, otherwise an error will be raised.      sample_weight : array-like of shape = [n_samples], optional         Sample weights.


from ..utils.validation import check_is_fitted, check_array, FLOAT_DTYPES from ..utils import _IS_32BIT from ..utils.fixes import _astype_copy_false<ins>from ..exceptions import ChangedBehaviorWarning</ins>   __all__ = ['HashingVectorizer',


self._stop_words_id = id(self.stop_words)             return 'error'     def _validate_custom_analyzer(self):        # This is to check if the given custom analyzer expects file or a        # filename instead of data.        # Behavior changed in v0.21, function could be removed in v0.23        import tempfile        with tempfile.NamedTemporaryFile() as f:            fname = f.name        # now we're sure fname doesn't exist        msg = ("Since v0.21, vectorizers pass the data to the custom analyzer "               "and not the file names or the file objects. This warning "               "will be removed in v0.23.")        try:            self.analyzer(fname)        except FileNotFoundError:            warnings.warn(msg, ChangedBehaviorWarning)        except AttributeError as e:            if str(e) == "'str' object has no attribute 'read'":                warnings.warn(msg, ChangedBehaviorWarning)        except Exception:            pass     def build_analyzer(self):         """Return a callable that handles preprocessing and tokenization"""         if callable(self.analyzer):            return self.analyzer            if self.input in ['file', 'filename']:                self._validate_custom_analyzer()            return lambda doc: self.analyzer(self.decode(doc))          preprocess = self.build_preprocessor()


If a callable is passed it is used to extract the sequence of features         out of the raw, unprocessed input. <ins>        .. versionchanged:: 0.21        Since v0.21, if ``input`` is ``filename`` or ``file``, the data is        first read from the file and then passed to the given callable        analyzer.</ins>     n_features : integer, default=(2 ** 20)         The number of features (columns) in the output matrices. Small numbers         of features are likely to cause hash collisions, but large numbers


If a callable is passed it is used to extract the sequence of features         out of the raw, unprocessed input. <ins>        .. versionchanged:: 0.21        Since v0.21, if ``input`` is ``filename`` or ``file``, the data is        first read from the file and then passed to the given callable        analyzer.</ins>     max_df : float in range [0.0, 1.0] or int, default=1.0         When building the vocabulary ignore terms that have a document         frequency strictly higher than the given threshold (corpus-specific


If a callable is passed it is used to extract the sequence of features         out of the raw, unprocessed input. <ins>        .. versionchanged:: 0.21        Since v0.21, if ``input`` is ``filename`` or ``file``, the data is        first read from the file and then passed to the given callable        analyzer.</ins>     stop_words : string {'english'}, list, or None (default=None)         If a string, it is passed to _check_stop_list and the appropriate stop         list is returned. 'english' is currently the only supported string


from ..base import BaseEstimator from .base import SelectorMixin from ..utils import check_arrayfrom ..utils.sparsefuncs import mean_variance_axisfrom ..utils.sparsefuncs import mean_variance_axis, min_max_axis from ..utils.validation import check_is_fitted


if hasattr(X, "toarray"):   # sparse matrix             _, self.variances_ = mean_variance_axis(X, axis=0)            if self.threshold == 0:                mins, maxes = min_max_axis(X, axis=0)                peak_to_peaks = maxes - mins         else:             self.variances_ = np.var(X, axis=0)            if self.threshold == 0:                peak_to_peaks = np.ptp(X, axis=0)        if self.threshold == 0:            # Use peak-to-peak to avoid numeric precision issues            # for constant features            self.variances_ = np.minimum(self.variances_, peak_to_peaks)          if np.all(self.variances_ <= self.threshold):             msg = "No feature in X meets the variance threshold {0:.5f}"


to be installed. It can be faster on very large, sparse problems,         but may also lead to instabilities. <ins>    n_components : integer, optional, default=n_clusters        Number of eigen vectors to use for the spectral embedding</ins>     random_state : int, RandomState instance or None (default)         A pseudo random number generator used for the initialization of the         lobpcg eigen vectors decomposition when ``eigen_solver='amg'`` and by


>>> clustering # doctest: +NORMALIZE_WHITESPACE     SpectralClustering(affinity='rbf', assign_labels='discretize', coef0=1,               degree=3, eigen_solver=None, eigen_tol=0.0, gamma=1.0,              kernel_params=None, n_clusters=2, n_init=10, n_jobs=None,              n_neighbors=10, random_state=0)              kernel_params=None, n_clusters=2, n_components=None, n_init=10,              n_jobs=None, n_neighbors=10, random_state=0)      Notes     -----


https://www1.icsi.berkeley.edu/~stellayu/publication/doc/2003kwayICCV.pdf     """     def __init__(self, n_clusters=8, eigen_solver=None, random_state=None,                 n_init=10, gamma=1., affinity='rbf', n_neighbors=10,                 eigen_tol=0.0, assign_labels='kmeans', degree=3, coef0=1,                 kernel_params=None, n_jobs=None):    def __init__(self, n_clusters=8, eigen_solver=None, n_components=None,                 random_state=None, n_init=10, gamma=1., affinity='rbf',                 n_neighbors=10, eigen_tol=0.0, assign_labels='kmeans',                 degree=3, coef0=1, kernel_params=None, n_jobs=None):         self.n_clusters = n_clusters         self.eigen_solver = eigen_solver        self.n_components = n_components         self.random_state = random_state         self.n_init = n_init         self.gamma = gamma


random_state = check_random_state(self.random_state)         self.labels_ = spectral_clustering(self.affinity_matrix_,                                            n_clusters=self.n_clusters,<ins>                                           n_components=self.n_components,</ins>                                            eigen_solver=self.eigen_solver,                                            random_state=random_state,                                            n_init=self.n_init,


if sample_weight is not None:             for name, step in self.estimators:<ins>                if step is None:                    continue</ins>                 if not has_fit_parameter(step, 'sample_weight'):                     raise ValueError('Underlying estimator \'%s\' does not'                                      ' support sample weights.' % name)


def _parallel_fit_estimator(estimator, X, y, sample_weight=None):     """Private function used to fit an estimator within a job."""     if sample_weight is not None:        estimator.fit(X, y, sample_weight=sample_weight)        try:            estimator.fit(X, y, sample_weight=sample_weight)        except TypeError as exc:            if "unexpected keyword argument 'sample_weight'" in str(exc):                raise ValueError(                    "Underlying estimator {} does not support sample weights."                    .format(estimator.__class__.__name__)                ) from exc            raise     else:         estimator.fit(X, y)     return estimator


"""Get the weights of not `None` estimators"""         if self.weights is None:             return None        return [w for est, w in zip(self.estimators,                                    self.weights) if est[1] is not None]        return [w for est, w in zip(self.estimators, self.weights)                if est[1] not in (None, 'drop')]      def _predict(self, X):         """Collect results from clf.predict calls. """


'; got %d weights, %d estimators'                              % (len(self.weights), len(self.estimators)))         if sample_weight is not None:            for name, step in self.estimators:                if step is None:                    continue                if not has_fit_parameter(step, 'sample_weight'):                    raise ValueError('Underlying estimator \'%s\' does not'                                     ' support sample weights.' % name)         names, clfs = zip(*self.estimators)         self._validate_names(names)         n_isnone = np.sum([clf is None for _, clf in self.estimators])        n_isnone = np.sum(            [clf in (None, 'drop') for _, clf in self.estimators]        )         if n_isnone == len(self.estimators):            raise ValueError('All estimators are None. At least one is '                             'required!')            raise ValueError(                'All estimators are None or "drop". At least one is required!'            )          self.estimators_ = Parallel(n_jobs=self.n_jobs)(                 delayed(_parallel_fit_estimator)(clone(clf), X, y,                                                  sample_weight=sample_weight)                for clf in clfs if clf is not None)                for clf in clfs if clf not in (None, 'drop')            )          self.named_estimators_ = Bunch()         for k, e in zip(self.estimators, self.estimators_):


estimators : list of (string, estimator) tuples         Invoking the ``fit`` method on the ``VotingClassifier`` will fit clones         of those original estimators that will be stored in the class attribute        ``self.estimators_``. An estimator can be set to `None` using        ``set_params``.        ``self.estimators_``. An estimator can be set to ``None`` or ``'drop'``        using ``set_params``.      voting : str, {'hard', 'soft'} (default='hard')         If 'hard', uses predicted class labels for majority rule voting.


Parameters     ----------     estimators : list of (string, estimator) tuples<del>        Invoking the ``fit`` method on the ``VotingRegressor`` will fit        clones of those original estimators that will be stored in the class        attribute ``self.estimators_``. An estimator can be set to `None`</del><ins>        Invoking the ``fit`` method on the ``VotingRegressor`` will fit clones        of those original estimators that will be stored in the class attribute        ``self.estimators_``. An estimator can be set to ``None`` or ``'drop'``</ins>         using ``set_params``.      weights : array-like, shape (n_regressors,), optional (default=`None`)


y : Ignored          """        X = check_array(X, accept_sparse='csr')        if self.affinity == "precomputed":            accept_sparse = False        else:            accept_sparse = 'csr'        X = check_array(X, accept_sparse=accept_sparse)         if self.affinity == "precomputed":             self.affinity_matrix_ = X         elif self.affinity == "euclidean":


maxmem = max(         ((x_density * n_samples_X + y_density * n_samples_Y) * n_features          + (x_density * n_samples_X * y_density * n_samples_Y)) / 10,        10 * 2**17)        10 * 2 ** 17)      # The increase amount of memory in 8-byte blocks is:     # - x_density * batch_size * n_features (copy of chunk of X)


# Hence x² + (xd+yd)kx = M, where x=batch_size, k=n_features, M=maxmem     #                                 xd=x_density and yd=y_density     tmp = (x_density + y_density) * n_features    batch_size = (-tmp + np.sqrt(tmp**2 + 4 * maxmem)) / 2    batch_size = (-tmp + np.sqrt(tmp ** 2 + 4 * maxmem)) / 2     batch_size = max(int(batch_size), 1)      x_batches = gen_batches(X.shape[0], batch_size)


K = safe_sparse_dot(X, Y.T, dense_output=True)     K *= gamma     K += coef0    np.tanh(K, K)   # compute tanh in-place    np.tanh(K, K)  # compute tanh in-place     return K


K = euclidean_distances(X, Y, squared=True)     K *= -gamma    np.exp(K, K)    # exponentiate K in-place    np.exp(K, K)  # exponentiate K in-place     return K


gamma = 1.0 / X.shape[1]      K = -gamma * manhattan_distances(X, Y)    np.exp(K, K)    # exponentiate K in-place    np.exp(K, K)  # exponentiate K in-place     return K


dtype = bool if metric in PAIRWISE_BOOLEAN_FUNCTIONS else None         if dtype == bool and (X.dtype != bool or Y.dtype != bool):        if (dtype == bool and                (X.dtype != bool or (Y is not None and Y.dtype != bool))):             msg = "Data was converted to boolean for metric %s" % metric             warnings.warn(msg, DataConversionWarning)


'yule', ] <del></del> # Helper functions - distance PAIRWISE_KERNEL_FUNCTIONS = {     # If updating this dictionary, update the doc in both distance_metrics()


if Y is None:         Y = X    X, Y, dtype = _return_float_dtype(X, Y)      if effective_n_jobs(n_jobs) == 1:         return func(X, Y, **kwds)      # enforce a threading backend to prevent data communication overhead     fd = delayed(_dist_wrapper)    ret = np.empty((X.shape[0], Y.shape[0]), dtype=X.dtype, order='F')    ret = np.empty((X.shape[0], Y.shape[0]), dtype=dtype, order='F')     Parallel(backend="threading", n_jobs=n_jobs)(         fd(func, ret, s, X, Y[s], **kwds)         for s in gen_even_slices(_num_samples(Y), effective_n_jobs(n_jobs)))     if (X is Y or Y is None) and func is euclidean_distances:        # zeroing diagonal for euclidean norm.        # TODO: do it also for other norms.        np.fill_diagonal(ret, 0)     return ret


return distances if squared else np.sqrt(distances, out=distances)  def _euclidean_distances_upcast(X, XX=None, Y=None, YY=None):def _euclidean_distances_upcast(X, XX=None, Y=None, YY=None, batch_size=None):     """Euclidean distances between X and Y      Assumes X and Y have float32 dtype.


distances = np.empty((n_samples_X, n_samples_Y), dtype=np.float32)     x_density = X.nnz / np.prod(X.shape) if issparse(X) else 1    y_density = Y.nnz / np.prod(Y.shape) if issparse(Y) else 1    # Allow 10% more memory than X, Y and the distance matrix take (at least    # 10MiB)    maxmem = max(        ((x_density * n_samples_X + y_density * n_samples_Y) * n_features         + (x_density * n_samples_X * y_density * n_samples_Y)) / 10,        10 * 2 ** 17)    # The increase amount of memory in 8-byte blocks is:    # - x_density * batch_size * n_features (copy of chunk of X)    # - y_density * batch_size * n_features (copy of chunk of Y)    # - batch_size * batch_size (chunk of distance matrix)    # Hence x² + (xd+yd)kx = M, where x=batch_size, k=n_features, M=maxmem    #                                 xd=x_density and yd=y_density    tmp = (x_density + y_density) * n_features    batch_size = (-tmp + np.sqrt(tmp ** 2 + 4 * maxmem)) / 2    batch_size = max(int(batch_size), 1)    x_batches = gen_batches(X.shape[0], batch_size)    y_batches = gen_batches(Y.shape[0], batch_size)    if batch_size is None:        x_density = X.nnz / np.prod(X.shape) if issparse(X) else 1        y_density = Y.nnz / np.prod(Y.shape) if issparse(Y) else 1        # Allow 10% more memory than X, Y and the distance matrix take (at        # least 10MiB)        maxmem = max(            ((x_density * n_samples_X + y_density * n_samples_Y) * n_features             + (x_density * n_samples_X * y_density * n_samples_Y)) / 10,            10 * 2 ** 17)        # The increase amount of memory in 8-byte blocks is:        # - x_density * batch_size * n_features (copy of chunk of X)        # - y_density * batch_size * n_features (copy of chunk of Y)        # - batch_size * batch_size (chunk of distance matrix)        # Hence x² + (xd+yd)kx = M, where x=batch_size, k=n_features, M=maxmem        #                                 xd=x_density and yd=y_density        tmp = (x_density + y_density) * n_features        batch_size = (-tmp + np.sqrt(tmp ** 2 + 4 * maxmem)) / 2        batch_size = max(int(batch_size), 1)    x_batches = gen_batches(n_samples_X, batch_size)      for i, x_slice in enumerate(x_batches):         X_chunk = X[x_slice].astype(np.float64)


else:             XX_chunk = XX[x_slice] <ins>        y_batches = gen_batches(n_samples_Y, batch_size)</ins>         for j, y_slice in enumerate(y_batches):             if X is Y and j < i:                 # when X is Y the distance matrix is symmetric so we only need


Returns         -------         X_binned : array-like, shape (n_samples, n_features)            The binned data.            The binned data (fortran-aligned).         """         X = check_array(X, dtype=[X_DTYPE])         check_is_fitted(self, ['bin_thresholds_', 'actual_n_bins_'])diff --git a/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py b/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py-- a/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py++ b/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py


# data.         self._in_fit = True <del>        # bin the data        if self.verbose:            print("Binning {:.3f} GB of data: ".format(X.nbytes / 1e9), end="",                  flush=True)        tic = time()        self.bin_mapper_ = _BinMapper(max_bins=self.max_bins, random_state=rng)        X_binned = self.bin_mapper_.fit_transform(X)        toc = time()        if self.verbose:            duration = toc - tic            print("{:.3f} s".format(duration))</del>          self.loss_ = self._get_loss()


# stratify for classification             stratify = y if hasattr(self.loss_, 'predict_proba') else None             X_binned_train, X_binned_val, y_train, y_val = train_test_split(                X_binned, y, test_size=self.validation_fraction,                stratify=stratify, random_state=rng)            X_train, X_val, y_train, y_val = train_test_split(                X, y, test_size=self.validation_fraction, stratify=stratify,                random_state=rng)        else:            X_train, y_train = X, y            X_val, y_val = None, None             # Predicting is faster of C-contiguous arrays, training is faster            # on Fortran arrays.            X_binned_val = np.ascontiguousarray(X_binned_val)            X_binned_train = np.asfortranarray(X_binned_train)        # Bin the data        self.bin_mapper_ = _BinMapper(max_bins=self.max_bins, random_state=rng)        X_binned_train = self._bin_data(X_train, rng, is_training_data=True)        if X_val is not None:            X_binned_val = self._bin_data(X_val, rng, is_training_data=False)         else:            X_binned_train, y_train = X_binned, y            X_binned_val, y_val = None, None            X_binned_val = None          if self.verbose:             print("Fitting gradient boosted rounds:")


for score in recent_scores]         return not any(recent_improvements) <ins>    def _bin_data(self, X, rng, is_training_data):        """Bin data X.        If is_training_data, then set the bin_mapper_ attribute.        Else, the binned data is converted to a C-contiguous array.        """        description = 'training' if is_training_data else 'validation'        if self.verbose:            print("Binning {:.3f} GB of {} data: ".format(                X.nbytes / 1e9, description), end="", flush=True)        tic = time()        if is_training_data:            X_binned = self.bin_mapper_.fit_transform(X)  # F-aligned array        else:            X_binned = self.bin_mapper_.transform(X)  # F-aligned array            # We convert the array to C-contiguous since predicting is faster            # with this layout (training is faster on F-arrays though)            X_binned = np.ascontiguousarray(X_binned)        toc = time()        if self.verbose:            duration = toc - tic            print("{:.3f} s".format(duration))        return X_binned</ins>     def _print_iteration_stats(self, iteration_start_time):         """Print info about the current fitting iteration."""         log_msg = ''


# License: BSD 3 clause  import numpy as npfrom scipy import linalgfrom scipy import linalg, sparse  from .base import _BasePCA from ..utils import check_array, gen_batches


but not scaled for each feature before applying the SVD.      Depending on the size of the input data, this algorithm can be much more    memory efficient than a PCA.    memory efficient than a PCA, and allows sparse input.      This algorithm has constant memory complexity, on the order    of ``batch_size``, enabling use of np.memmap files without loading the    entire file into memory.    of ``batch_size * n_features``, enabling use of np.memmap files without    loading the entire file into memory. For sparse matrices, the input    is converted to dense in batches (in order to be able to subtract the    mean) which avoids storing the entire dense matrix at any one time.      The computational overhead of each SVD is     ``O(batch_size * n_features ** 2)``, but only 2 * batch_size samples


--------     >>> from sklearn.datasets import load_digits     >>> from sklearn.decomposition import IncrementalPCA    >>> from scipy import sparse     >>> X, _ = load_digits(return_X_y=True)     >>> transformer = IncrementalPCA(n_components=7, batch_size=200)     >>> # either partially fit on smaller batches of data     >>> transformer.partial_fit(X[:100, :])     IncrementalPCA(batch_size=200, n_components=7)     >>> # or let the fit function itself divide the data into batches    >>> X_transformed = transformer.fit_transform(X)    >>> X_sparse = sparse.csr_matrix(X)    >>> X_transformed = transformer.fit_transform(X_sparse)     >>> X_transformed.shape     (1797, 7)


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


self.singular_values_ = None         self.noise_variance_ = None         X = check_array(X, copy=self.copy, dtype=[np.float64, np.float32])        X = check_array(X, accept_sparse=['csr', 'csc', 'lil'],                        copy=self.copy, dtype=[np.float64, np.float32])         n_samples, n_features = X.shape          if self.batch_size is None:


for batch in gen_batches(n_samples, self.batch_size_,                                  min_batch_size=self.n_components or 0):            self.partial_fit(X[batch], check_input=False)            X_batch = X[batch]            if sparse.issparse(X_batch):                X_batch = X_batch.toarray()            self.partial_fit(X_batch, check_input=False)          return self


Returns the instance itself.         """         if check_input:<ins>            if sparse.issparse(X):                raise TypeError(                    "IncrementalPCA.partial_fit does not support "                    "sparse input. Either convert data to dense "                    "or use IncrementalPCA.fit to do so in batches.")</ins>             X = check_array(X, copy=self.copy, dtype=[np.float64, np.float32])         n_samples, n_features = X.shape         if not hasattr(self, 'components_'):


np.sqrt((self.n_samples_seen_ * n_samples) /                         n_total_samples) * (self.mean_ - col_batch_mean)             X = np.vstack((self.singular_values_.reshape((-1, 1)) *                          self.components_, X, mean_correction))                           self.components_, X, mean_correction))          U, S, V = linalg.svd(X, full_matrices=False)         U, V = svd_flip(U, V, u_based_decision=False)


else:             self.noise_variance_ = 0.         return self<ins>    def transform(self, X):        """Apply dimensionality reduction to X.        X is projected on the first principal components previously extracted        from a training set, using minibatches of size batch_size if X is        sparse.        Parameters        ----------        X : array-like, shape (n_samples, n_features)            New data, where n_samples is the number of samples            and n_features is the number of features.        Returns        -------        X_new : array-like, shape (n_samples, n_components)        Examples        --------        >>> import numpy as np        >>> from sklearn.decomposition import IncrementalPCA        >>> X = np.array([[-1, -1], [-2, -1], [-3, -2],        ...               [1, 1], [2, 1], [3, 2]])        >>> ipca = IncrementalPCA(n_components=2, batch_size=3)        >>> ipca.fit(X)        IncrementalPCA(batch_size=3, n_components=2)        >>> ipca.transform(X) # doctest: +SKIP        """        if sparse.issparse(X):            n_samples = X.shape[0]            output = []            for batch in gen_batches(n_samples, self.batch_size_,                                     min_batch_size=self.n_components or 0):                output.append(super().transform(X[batch].toarray()))            return np.vstack(output)        else:            return super().transform(X)</ins>


if self.add_indicator:             self.indicator_ = MissingIndicator(                missing_values=self.missing_values)                missing_values=self.missing_values, error_on_new=False)             self.indicator_.fit(X)         else:             self.indicator_ = Nonediff --git a/sklearn/impute/_iterative.py b/sklearn/impute/_iterative.py-- a/sklearn/impute/_iterative.py++ b/sklearn/impute/_iterative.py


if self.add_indicator:             self.indicator_ = MissingIndicator(                missing_values=self.missing_values)                missing_values=self.missing_values, error_on_new=False)             X_trans_indicator = self.indicator_.fit_transform(X)         else:             self.indicator_ = None


from .predictor import TreePredictor from .utils import sum_parallel from .types import PREDICTOR_RECORD_DTYPE<ins>from .types import Y_DTYPEEPS = np.finfo(Y_DTYPE).eps  # to avoid zero division errors</ins>   class TreeNode:


https://arxiv.org/abs/1603.02754         """         node.value = -self.shrinkage * node.sum_gradients / (            node.sum_hessians + self.splitter.l2_regularization)            node.sum_hessians + self.splitter.l2_regularization + EPS)         self.finalized_leaves.append(node)      def _finalize_splittable_nodes(self):diff --git a/sklearn/utils/estimator_checks.py b/sklearn/utils/estimator_checks.py-- a/sklearn/utils/estimator_checks.py++ b/sklearn/utils/estimator_checks.py


hasattr(estimator, "predict_proba")):          estimator.fit(X, y)        a = estimator.predict_proba(X_test)[:, 1]        b = estimator.decision_function(X_test)        # Since the link function from decision_function() to predict_proba()        # is sometimes not precise enough (typically expit), we round to the        # 10th decimal to avoid numerical issues.        a = estimator.predict_proba(X_test)[:, 1].round(decimals=10)        b = estimator.decision_function(X_test).round(decimals=10)         assert_array_equal(rankdata(a), rankdata(b))


value_fmt = "{}{} value: {}\n"      if feature_names:        feature_names_ = [feature_names[i] for i in tree_.feature]        feature_names_ = [feature_names[i] if i != _tree.TREE_UNDEFINED                          else None for i in tree_.feature]     else:         feature_names_ = ["feature_{}".format(i) for i in tree_.feature]