"""     generator = check_random_state(random_state)     if isinstance(centers, numbers.Integral):        centers = generator.uniform(center_box[0], center_box[1],                                    size=(centers, n_features))    if isinstance(n_samples, numbers.Integral):        # Set n_centers by looking at centers arg        if centers is None:            centers = 3        if isinstance(centers, numbers.Integral):            n_centers = centers            centers = generator.uniform(center_box[0], center_box[1],                                        size=(n_centers, n_features))        else:            centers = check_array(centers)            n_features = centers.shape[1]            n_centers = centers.shape[0]     else:        centers = check_array(centers)        n_features = centers.shape[1]        # Set n_centers by looking at [n_samples] arg        n_centers = len(n_samples)        if centers is None:            centers = generator.uniform(center_box[0], center_box[1],                                        size=(n_centers, n_features))        try:            assert len(centers) == n_centers        except TypeError:            raise ValueError("Parameter `centers` must be array-like. "                             "Got {!r} instead".format(centers))        except AssertionError:            raise ValueError("Length of `n_samples` not consistent"                             " with number of centers. Got n_samples = {} "                             "and centers = {}".format(n_samples, centers))        else:            centers = check_array(centers)            n_features = centers.shape[1]    # stds: if cluster_std is given as list, it must be consistent    # with the n_centers    if (hasattr(cluster_std, "__len__") and len(cluster_std) != n_centers):        raise ValueError("Length of `clusters_std` not consistent with "                         "number of centers. Got centers = {} "                         "and cluster_std = {}".format(centers, cluster_std))      if isinstance(cluster_std, numbers.Real):         cluster_std = np.ones(len(centers)) * cluster_std


X = []     y = []     n_centers = centers.shape[0]    n_samples_per_center = [int(n_samples // n_centers)] * n_centers    if isinstance(n_samples, Iterable):        n_samples_per_center = n_samples    else:        n_samples_per_center = [int(n_samples // n_centers)] * n_centers     for i in range(n_samples % n_centers):        n_samples_per_center[i] += 1        for i in range(n_samples % n_centers):            n_samples_per_center[i] += 1      for i, (n, std) in enumerate(zip(n_samples_per_center, cluster_std)):        X.append(centers[i] + generator.normal(scale=std,                                               size=(n, n_features)))        X.append(generator.normal(loc=centers[i], scale=std,                                  size=(n, n_features)))         y += [i] * n      X = np.concatenate(X)     y = np.array(y)      if shuffle:        indices = np.arange(n_samples)        total_n_samples = np.sum(n_samples)        indices = np.arange(total_n_samples)         generator.shuffle(indices)         X = X[indices]         y = y[indices]


raise ValueError('precompute should be one of True, False or'                              ' array-like. Got %r' % self.precompute)         # Remember if X is copied        X_copied = False         # We expect X and y to be float64 or float32 Fortran ordered arrays         # when bypassing checks         if check_input:            X_copied = self.copy_X and self.fit_intercept             X, y = check_X_y(X, y, accept_sparse='csc',                              order='F', dtype=[np.float64, np.float32],                             copy=self.copy_X and self.fit_intercept,                             multi_output=True, y_numeric=True)                             copy=X_copied, multi_output=True, y_numeric=True)             y = check_array(y, order='F', copy=False, dtype=X.dtype.type,                             ensure_2d=False)         # Ensure copying happens only once, don't do it again if done above        should_copy = self.copy_X and not X_copied         X, y, X_offset, y_offset, X_scale, precompute, Xy = \             _pre_fit(X, y, None, self.precompute, self.normalize,                     self.fit_intercept, copy=False)                     self.fit_intercept, copy=should_copy)         if y.ndim == 1:             y = y[:, np.newaxis]         if Xy is not None and Xy.ndim == 1:


if n_targets == 1:             self.n_iter_ = self.n_iter_[0]            self.coef_ = coef_[0]            self.dual_gap_ = dual_gaps_[0]        else:            self.coef_ = coef_            self.dual_gap_ = dual_gaps_         self.coef_, self.dual_gap_ = map(np.squeeze, [coef_, dual_gaps_])         self._set_intercept(X_offset, y_offset, X_scale)          # workaround since _set_intercept will cast self.coef_ into X.dtype


if len(self.vocabulary_) == 0:             raise ValueError("Vocabulary is empty") <ins>    def _validate_params(self):        """Check validity of ngram_range parameter"""        min_n, max_m = self.ngram_range        if min_n > max_m:            raise ValueError(                "Invalid value for ngram_range=%s "                "lower boundary larger than the upper boundary."                % str(self.ngram_range))</ins>  class HashingVectorizer(BaseEstimator, VectorizerMixin, TransformerMixin):     """Convert a collection of text documents to a matrix of token occurrences


"Iterable over raw text documents expected, "                 "string object received.") <ins>        self._validate_params()</ins>         self._get_hasher().fit(X, y=y)         return self


"Iterable over raw text documents expected, "                 "string object received.") <ins>        self._validate_params()</ins>         analyzer = self.build_analyzer()         X = self._get_hasher().transform(analyzer(doc) for doc in X)         if self.binary:


"Iterable over raw text documents expected, "                 "string object received.") <ins>        self._validate_params()</ins>         self._validate_vocabulary()         max_df = self.max_df         min_df = self.min_df


import numpy as np from scipy.special import gammainc from ..base import BaseEstimatorfrom ..utils import check_array, check_random_statefrom ..utils import check_array, check_random_state, check_consistent_length from ..utils.extmath import row_norms from .ball_tree import BallTree, DTYPE from .kd_tree import KDTree


else:             raise ValueError("invalid algorithm: '{0}'".format(algorithm))     def fit(self, X, y=None):    def fit(self, X, y=None, sample_weight=None):         """Fit the Kernel Density model on the data.          Parameters


X : array_like, shape (n_samples, n_features)             List of n_features-dimensional data points.  Each row             corresponds to a single data point.        sample_weight: array_like, shape (n_samples,), optional            List of sample weights attached to the data X.         """         algorithm = self._choose_algorithm(self.algorithm, self.metric)         X = check_array(X, order='C', dtype=DTYPE)         if sample_weight is not None:            sample_weight = check_array(sample_weight, order='C', dtype=DTYPE,                                        ensure_2d=False)            if sample_weight.ndim != 1:                raise ValueError("the shape of sample_weight must be ({0},),"                                 " but was {1}".format(X.shape[0],                                                       sample_weight.shape))            check_consistent_length(X, sample_weight)            if sample_weight.min() <= 0:                raise ValueError("sample_weight must have positive values")         kwargs = self.metric_params         if kwargs is None:             kwargs = {}         self.tree_ = TREE_DICT[algorithm](X, metric=self.metric,                                           leaf_size=self.leaf_size,                                          sample_weight=sample_weight,                                           **kwargs)         return self


# For it to be a probability, we must scale it.  For this reason         # we'll also scale atol.         X = check_array(X, order='C', dtype=DTYPE)        N = self.tree_.data.shape[0]        if self.tree_.sample_weight is None:            N = self.tree_.data.shape[0]        else:            N = self.tree_.sum_weight         atol_N = self.atol * N         log_density = self.tree_.kernel_density(             X, h=self.bandwidth, kernel=self.kernel, atol=atol_N,


data = np.asarray(self.tree_.data)          rng = check_random_state(random_state)        i = rng.randint(data.shape[0], size=n_samples)        u = rng.uniform(0, 1, size=n_samples)        if self.tree_.sample_weight is None:            i = (u * data.shape[0]).astype(np.int64)        else:            cumsum_weight = np.cumsum(np.asarray(self.tree_.sample_weight))            sum_weight = cumsum_weight[-1]            i = np.searchsorted(cumsum_weight, u * sum_weight)         if self.kernel == 'gaussian':             return np.atleast_2d(rng.normal(data[i], self.bandwidth))


labels_true, labels_pred = check_clusterings(labels_true, labels_pred)     n_samples, = labels_true.shape     c = contingency_matrix(labels_true, labels_pred, sparse=True)    c = contingency_matrix(labels_true, labels_pred,                           sparse=True).astype(np.int64)     tk = np.dot(c.data, c.data) - n_samples     pk = np.sum(np.asarray(c.sum(axis=0)).ravel() ** 2) - n_samples     qk = np.sum(np.asarray(c.sum(axis=1)).ravel() ** 2) - n_samples    return tk / np.sqrt(pk * qk) if tk != 0. else 0.    return np.sqrt(tk / pk) * np.sqrt(tk / qk) if tk != 0. else 0.   def entropy(labels):


def fit(self, X, y=None):         """Estimate model parameters with the EM algorithm.         The method fits the model `n_init` times and set the parameters with        The method fits the model ``n_init`` times and sets the parameters with         which the model has the largest likelihood or lower bound. Within each        trial, the method iterates between E-step and M-step for `max_iter`        trial, the method iterates between E-step and M-step for ``max_iter``         times until the change of likelihood or lower bound is less than        `tol`, otherwise, a `ConvergenceWarning` is raised.        ``tol``, otherwise, a ``ConvergenceWarning`` is raised.        If ``warm_start`` is ``True``, then ``n_init`` is ignored and a single        initialization is performed upon the first call. Upon consecutive        calls, training starts where it left off.          Parameters         ----------


if do_init:                 self._initialize_parameters(X, random_state)                self.lower_bound_ = -np.infty            lower_bound = (-np.infty if do_init else self.lower_bound_)              for n_iter in range(1, self.max_iter + 1):                prev_lower_bound = self.lower_bound_                prev_lower_bound = lower_bound                  log_prob_norm, log_resp = self._e_step(X)                 self._m_step(X, log_resp)                self.lower_bound_ = self._compute_lower_bound(                lower_bound = self._compute_lower_bound(                     log_resp, log_prob_norm)                 change = self.lower_bound_ - prev_lower_bound                change = lower_bound - prev_lower_bound                 self._print_verbose_msg_iter_end(n_iter, change)                  if abs(change) < self.tol:                     self.converged_ = True                     break             self._print_verbose_msg_init_end(self.lower_bound_)            self._print_verbose_msg_init_end(lower_bound)             if self.lower_bound_ > max_lower_bound:                max_lower_bound = self.lower_bound_            if lower_bound > max_lower_bound:                max_lower_bound = lower_bound                 best_params = self._get_parameters()                 best_n_iter = n_iter


self._set_parameters(best_params)         self.n_iter_ = best_n_iter        self.lower_bound_ = max_lower_bound          return log_resp.argmax(axis=1) diff --git a/sklearn/mixture/gaussian_mixture.py b/sklearn/mixture/gaussian_mixture.py-- a/sklearn/mixture/gaussian_mixture.py++ b/sklearn/mixture/gaussian_mixture.py


If 'warm_start' is True, the solution of the last fitting is used as         initialization for the next call of fit(). This can speed up         convergence when fit is called several times on similar problems.<ins>        In that case, 'n_init' is ignored and only a single initialization        occurs upon the first call.</ins>         See :term:`the Glossary <warm_start>`.      verbose : int, default to 0.


Number of step used by the best fit of EM to reach the convergence.      lower_bound_ : float        Log-likelihood of the best fit of EM.        Lower bound value on the log-likelihood (of the training data with        respect to the model) of the best fit of EM.      See Also     --------


func, w0, fprime=None,                 args=(X, target, 1. / C, sample_weight),                 iprint=(verbose > 0) - 1, pgtol=tol, maxiter=max_iter)            if info["warnflag"] == 1 and verbose > 0:            if info["warnflag"] == 1:                 warnings.warn("lbfgs failed to converge. Increase the number "                               "of iterations.", ConvergenceWarning)             # In scipy <= 1.0.0, nit may exceed maxiter.diff --git a/sklearn/svm/base.py b/sklearn/svm/base.py-- a/sklearn/svm/base.py++ b/sklearn/svm/base.py


# on 32-bit platforms, we can't get to the UINT_MAX limit that     # srand supports     n_iter_ = max(n_iter_)    if n_iter_ >= max_iter and verbose > 0:    if n_iter_ >= max_iter:         warnings.warn("Liblinear failed to converge, increase "                       "the number of iterations.", ConvergenceWarning)


sublinear_tf : boolean, default=False         Apply sublinear tf scaling, i.e. replace tf with 1 + log(tf). <ins>    Attributes    ----------    idf_ : array, shape (n_features)        The inverse document frequency (IDF) vector; only defined        if  ``use_idf`` is True.</ins>     References     ----------


# which means hasattr(self, "idf_") is False         return np.ravel(self._idf_diag.sum(axis=0)) <ins>    @idf_.setter    def idf_(self, value):        value = np.asarray(value, dtype=np.float64)        n_features = value.shape[0]        self._idf_diag = sp.spdiags(value, diags=0, m=n_features,                                    n=n_features, format='csr')</ins>  class TfidfVectorizer(CountVectorizer):     """Convert a collection of raw documents to a matrix of TF-IDF features.


vocabulary_ : dict         A mapping of terms to feature indices.     idf_ : array, shape = [n_features], or None        The learned idf vector (global term weights)        when ``use_idf`` is set to True, None otherwise.    idf_ : array, shape (n_features)        The inverse document frequency (IDF) vector; only defined        if  ``use_idf`` is True.      stop_words_ : set         Terms that were ignored because they either:


def idf_(self):         return self._tfidf.idf_ <ins>    @idf_.setter    def idf_(self, value):        self._validate_vocabulary()        if hasattr(self, 'vocabulary_'):            if len(self.vocabulary_) != len(value):                raise ValueError("idf length = %d must be equal "                                 "to vocabulary size = %d" %                                 (len(value), len(self.vocabulary)))        self._tfidf.idf_ = value</ins>     def fit(self, raw_documents, y=None):         """Learn vocabulary and idf from training set.


def get_feature_names(self):         """Array mapping from feature integer indices to feature name"""<ins>        if not hasattr(self, 'vocabulary_'):            self._validate_vocabulary()</ins>         self._check_vocabulary()          return [t for t, i in sorted(six.iteritems(self.vocabulary_),


from collections import defaultdict import itertools import array<ins>import warnings</ins>  import numpy as np import scipy.sparse as sp


sklearn.preprocessing.OneHotEncoder : encode categorical integer features         using a one-hot aka one-of-K scheme.     """<ins></ins>     def __init__(self, classes=None, sparse_output=False):         self.classes = classes         self.sparse_output = sparse_output


"""         indices = array.array('i')         indptr = array.array('i', [0])        unknown = set()         for labels in y:            indices.extend(set(class_mapping[label] for label in labels))            index = set()            for label in labels:                try:                    index.add(class_mapping[label])                except KeyError:                    unknown.add(label)            indices.extend(index)             indptr.append(len(indices))        if unknown:            warnings.warn('unknown class(es) {0} will be ignored'                          .format(sorted(unknown, key=str)))         data = np.ones(len(indices), dtype=int)          return sp.csr_matrix((data, indices, indptr),


# not a data type (e.g. a column named dtype in a pandas DataFrame)         dtype_orig = None <ins>    # check if the object contains several dtypes (typically a pandas    # DataFrame), and store them. If not, store None.    dtypes_orig = None    if hasattr(array, "dtypes") and hasattr(array, "__array__"):        dtypes_orig = np.array(array.dtypes)</ins>     if dtype_numeric:         if dtype_orig is not None and dtype_orig.kind == "O":             # if input is object, convert to float.


if copy and np.may_share_memory(array, array_orig):         array = np.array(array, dtype=dtype, order=order) <ins>    if (warn_on_dtype and dtypes_orig is not None and            {array.dtype} != set(dtypes_orig)):        # if there was at the beginning some other types than the final one        # (for instance in a DataFrame that can contain several dtypes) then        # some data must have been converted        msg = ("Data with input dtype %s were all converted to %s%s."               % (', '.join(map(str, sorted(set(dtypes_orig)))), array.dtype,                  context))        warnings.warn(msg, DataConversionWarning, stacklevel=3)</ins>     return array


# look up sampled parameter settings in parameter grid             param_grid = ParameterGrid(self.param_distributions)             grid_size = len(param_grid)            if grid_size < self.n_iter:                raise ValueError(                    "The total space of parameters %d is smaller "                    "than n_iter=%d. For exhaustive searches, use "                    "GridSearchCV." % (grid_size, self.n_iter))            for i in sample_without_replacement(grid_size, self.n_iter,            n_iter = self.n_iter            if grid_size < n_iter:                warnings.warn(                    'The total space of parameters %d is smaller '                    'than n_iter=%d. Running %d iterations. For exhaustive '                    'searches, use GridSearchCV.'                    % (grid_size, self.n_iter, grid_size), UserWarning)                n_iter = grid_size            for i in sample_without_replacement(grid_size, n_iter,                                                 random_state=rnd):                 yield param_grid[i]


'shape (%d, %d) or (%d, %d)' % (                         coef.shape[0], coef.shape[1], classes.size,                         n_features, classes.size, n_features + 1))            w0[:, :coef.shape[1]] = coef            if n_classes == 1:                w0[0, :coef.shape[1]] = -coef                w0[1, :coef.shape[1]] = coef            else:                w0[:, :coef.shape[1]] = coef      if multi_class == 'multinomial':         # fmin_l_bfgs_b and newton-cg accepts only ravelled parameters.


"Expected n_neighbors > 0. Got %d" %                     self.n_neighbors                 )<ins>            else:                if not np.issubdtype(type(self.n_neighbors), np.integer):                    raise TypeError(                        "n_neighbors does not take %s value, "                        "enter integer value" %                        type(self.n_neighbors))</ins>          return self


if n_neighbors is None:             n_neighbors = self.n_neighbors<ins>        elif n_neighbors <= 0:            raise ValueError(                "Expected n_neighbors > 0. Got %d" %                n_neighbors            )        else:            if not np.issubdtype(type(n_neighbors), np.integer):                raise TypeError(                    "n_neighbors does not take %s value, "                    "enter integer value" %                    type(n_neighbors))</ins>          if X is not None:             query_is_train = False


return np.hstack((np.ones((n_samples, 1)) * value, X))  def _transform_selected(X, transform, selected="all", copy=True):def _transform_selected(X, transform, dtype, selected="all", copy=True):     """Apply a transform function to portion of selected features      Parameters


transform : callable         A callable transform(X) -> X_transformed <ins>    dtype : number type        Desired dtype of output.</ins>     copy : boolean, optional         Copy X even if it could be avoided.


return transform(X)     else:         X_sel = transform(X[:, ind[sel]])        X_not_sel = X[:, ind[not_sel]]        # The columns of X which are not transformed need        # to be casted to the desire dtype before concatenation.        # Otherwise, the stacking will cast to the higher-precision dtype.        X_not_sel = X[:, ind[not_sel]].astype(dtype)          if sparse.issparse(X_sel) or sparse.issparse(X_not_sel):             return sparse.hstack((X_sel, X_not_sel))


X : array-like, shape [n_samples, n_feature]             Input array of type int.         """        return _transform_selected(X, self._fit_transform,        return _transform_selected(X, self._fit_transform, self.dtype,                                    self.categorical_features, copy=True)      def _transform(self, X):


X_out : sparse matrix if sparse=True else a 2-d array, dtype=int             Transformed input.         """        return _transform_selected(X, self._transform,        return _transform_selected(X, self._transform, self.dtype,                                    self.categorical_features, copy=True)


validate : bool, optional default=True         Indicate that the input X array should be checked before calling        func. If validate is false, there will be no input validation.        If it is true, then X will be converted to a 2-dimensional NumPy        array or sparse matrix. If this conversion is not possible or X        contains NaN or infinity, an exception is raised.        ``func``. The possibilities are:        - If False, there is no input validation.        - If True, then X will be converted to a 2-dimensional NumPy array or          sparse matrix. If the conversion is not possible an exception is          raised.        .. deprecated:: 0.20           ``validate=True`` as default will be replaced by           ``validate=False`` in 0.22.      accept_sparse : boolean, optional         Indicate that func accepts a sparse matrix as input. If validate is


Dictionary of additional keyword arguments to pass to inverse_func.      """    def __init__(self, func=None, inverse_func=None, validate=True,    def __init__(self, func=None, inverse_func=None, validate=None,                  accept_sparse=False, pass_y='deprecated', check_inverse=True,                  kw_args=None, inv_kw_args=None):         self.func = func


self.kw_args = kw_args         self.inv_kw_args = inv_kw_args <ins>    def _check_input(self, X):        # FIXME: Future warning to be removed in 0.22        if self.validate is None:            self._validate = True            warnings.warn("The default validate=True will be replaced by "                          "validate=False in 0.22.", FutureWarning)        else:            self._validate = self.validate        if self._validate:            return check_array(X, accept_sparse=self.accept_sparse)        return X</ins>     def _check_inverse_transform(self, X):         """Check that func and inverse_func are the inverse."""         idx_selected = slice(None, None, max(1, X.shape[0] // 100))


-------         self         """        if self.validate:            X = check_array(X, self.accept_sparse)        X = self._check_input(X)         if (self.check_inverse and not (self.func is None or                                         self.inverse_func is None)):             self._check_inverse_transform(X)


kw_args=self.inv_kw_args)      def _transform(self, X, y=None, func=None, kw_args=None):        if self.validate:            X = check_array(X, self.accept_sparse)        X = self._check_input(X)          if func is None:             func = _identity


for check in _yield_all_checks(name, estimator):         try:             check(name, estimator)        except SkipTest as message:        except SkipTest as exception:             # the only SkipTest thrown currently results from not             # being able to import pandas.            warnings.warn(message, SkipTestWarning)            warnings.warn(str(exception), SkipTestWarning)   def _boston_subset(n_samples=200):


and not isinstance(estimator, BaseSGD)):         estimator.set_params(n_iter=5)     if "max_iter" in params:        warnings.simplefilter("ignore", ConvergenceWarning)         if estimator.max_iter is not None:             estimator.set_params(max_iter=min(5, estimator.max_iter))         # LinearSVR, LinearSVCdiff --git a/sklearn/utils/testing.py b/sklearn/utils/testing.py-- a/sklearn/utils/testing.py++ b/sklearn/utils/testing.py


result : the return value of `func`      """<del>    # very important to avoid uncontrolled state propagation</del>     clean_warning_registry()     with warnings.catch_warnings(record=True) as w:         # Cause all warnings to always be triggered.


"""Decorator to catch and hide warnings without visual nesting."""         @wraps(fn)         def wrapper(*args, **kwargs):<del>            # very important to avoid uncontrolled state propagation</del>             clean_warning_registry()             with warnings.catch_warnings():                 warnings.simplefilter("ignore", self.category)


return "%s(%s)" % (name, ", ".join(args))      def __enter__(self):        clean_warning_registry()  # be safe and not propagate state + chaos        warnings.simplefilter("ignore", self.category)         if self._entered:             raise RuntimeError("Cannot enter %r twice" % self)         self._entered = True         self._filters = self._module.filters         self._module.filters = self._filters[:]         self._showwarning = self._module.showwarning        clean_warning_registry()        warnings.simplefilter("ignore", self.category)      def __exit__(self, *exc_info):         if not self._entered:


self._module.filters = self._filters         self._module.showwarning = self._showwarning         self.log[:] = []        clean_warning_registry()  # be safe and not propagate state + chaos        clean_warning_registry()   assert_less = _dummy.assertLess


def clean_warning_registry():    """Safe way to reset warnings."""    warnings.resetwarnings()    """Clean Python warning registry for easier testing of warning messages.    We may not need to do this any more when getting rid of Python 2, not    entirely sure. See https://bugs.python.org/issue4180 and    https://bugs.python.org/issue21724 for more details.    """     reg = "__warningregistry__"     for mod_name, mod in list(sys.modules.items()):         if 'six.moves' in mod_name:


def classification_report(y_true, y_pred, labels=None, target_names=None,                          sample_weight=None, digits=2):                          sample_weight=None, digits=2, output_dict=False):     """Build a text report showing the main classification metrics      Read more in the :ref:`User Guide <classification_report>`.


digits : int         Number of digits for formatting output floating point values     output_dict: bool (default = False)        If True, return output as dict     Returns     -------    report : string    report : string / dict         Text summary of the precision, recall, F1 score for each class.        Dictionary returned if output_dict is True. Dictionary has the        following structure:            {'label 1': {'precision':0.5,                         'recall':1.0,                         'f1-score':0.67,                         'support':1},             'label 2': { ... },              ...            }          The reported averages are a prevalence-weighted macro-average across         classes (equivalent to :func:`precision_recall_fscore_support` with


row_fmt = u'{:>{width}s} ' + u' {:>9.{digits}f}' * 3 + u' {:>9}\n'     rows = zip(target_names, p, r, f1, s)    avg_total = [np.average(p, weights=s),                 np.average(r, weights=s),                 np.average(f1, weights=s),                 np.sum(s)]    if output_dict:        report_dict = {label[0]: label[1:] for label in rows}        for label, scores in report_dict.items():            report_dict[label] = dict(zip(headers, scores))        report_dict['avg / total'] = dict(zip(headers, avg_total))        return report_dict     for row in rows:         report += row_fmt.format(*row, width=width, digits=digits)      report += u'\n'     # compute averages    # append averages     report += row_fmt.format(last_line_heading,                             np.average(p, weights=s),                             np.average(r, weights=s),                             np.average(f1, weights=s),                             np.sum(s),                             *avg_total,                              width=width, digits=digits)      return report


else:                 self.mean_ = None                 self.var_ = None<ins>                if not hasattr(self, 'n_samples_seen_'):                    self.n_samples_seen_ = X.shape[0]                else:                    self.n_samples_seen_ += X.shape[0]</ins>         else:             # First pass             if not hasattr(self, 'n_samples_seen_'):


else:                     self.var_ = None             self.mean_, self.var_, self.n_samples_seen_ = \                _incremental_mean_and_var(X, self.mean_, self.var_,                                          self.n_samples_seen_)            if not self.with_mean and not self.with_std:                self.mean_ = None                self.var_ = None                self.n_samples_seen_ += X.shape[0]            else:                self.mean_, self.var_, self.n_samples_seen_ = \                    _incremental_mean_and_var(X, self.mean_, self.var_,                                              self.n_samples_seen_)          if self.with_std:             self.scale_ = _handle_zeros_in_scale(np.sqrt(self.var_))


# Unlike the scaler object, this function allows 1d input.     # If copy is required, it will be done inside the scaler object.     X = check_array(X, copy=False, ensure_2d=False, warn_on_dtype=True,                    dtype=FLOAT_DTYPES)                    dtype=FLOAT_DTYPES, force_all_finite='allow-nan')     original_ndim = X.ndim      if original_ndim == 1:


import warnings  import numpy as npfrom scipy import linalgfrom scipy.sparse import issparse, csr_matrixfrom scipy import linalg, sparse  from . import check_random_state, deprecated from .fixes import np_version


Performs no input validation.     """    if issparse(X):        if not isinstance(X, csr_matrix):            X = csr_matrix(X)    if sparse.issparse(X):        if not isinstance(X, sparse.csr_matrix):            X = sparse.csr_matrix(X)         norms = csr_row_norms(X)     else:         norms = np.einsum('ij,ij->i', X, X)


dot_product : array or sparse matrix         sparse if ``a`` or ``b`` is sparse and ``dense_output=False``.     """    if issparse(a) or issparse(b):    if sparse.issparse(a) or sparse.issparse(b):         ret = a * b         if dense_output and hasattr(ret, "toarray"):             ret = ret.toarray()


analysis       A. Szlam et al. 2014     """<ins>    if isinstance(M, (sparse.lil_matrix, sparse.dok_matrix)):        warnings.warn("Calculating SVD of a {} is expensive. "                      "csr_matrix is more efficient.".format(                          type(M).__name__),                      sparse.SparseEfficiencyWarning)</ins>     random_state = check_random_state(random_state)     n_random = n_components + n_oversamples     n_samples, n_features = M.shape


Adapated from http://stackoverflow.com/q/13426580      """    if issparse(X):    if sparse.issparse(X):         if len(X.data) == 0:             return 0         m = X.data.min()


"""Ensure `X.min()` >= `min_value`."""     min_ = safe_min(X)     if min_ < min_value:        if issparse(X):        if sparse.issparse(X):             raise ValueError("Cannot make the data matrix"                              " nonnegative because it is sparse."                              " Adding a value to every entry would"


def fit(self, X, y=None):         """Estimate model parameters with the EM algorithm.         The method fit the model `n_init` times and set the parameters with        The method fits the model `n_init` times and set the parameters with         which the model has the largest likelihood or lower bound. Within each         trial, the method iterates between E-step and M-step for `max_iter`         times until the change of likelihood or lower bound is less than


-------         self         """<ins>        self.fit_predict(X, y)        return self    def fit_predict(self, X, y=None):        """Estimate model parameters using X and predict the labels for X.        The method fits the model n_init times and sets the parameters with        which the model has the largest likelihood or lower bound. Within each        trial, the method iterates between E-step and M-step for `max_iter`        times until the change of likelihood or lower bound is less than        `tol`, otherwise, a `ConvergenceWarning` is raised. After fitting, it        predicts the most probable label for the input data points.        .. versionadded:: 0.20        Parameters        ----------        X : array-like, shape (n_samples, n_features)            List of n_features-dimensional data points. Each row            corresponds to a single data point.        Returns        -------        labels : array, shape (n_samples,)            Component labels.        """</ins>         X = _check_X(X, self.n_components, ensure_min_samples=2)         self._check_initial_parameters(X)


self._set_parameters(best_params)         self.n_iter_ = best_n_iter         return self        return log_resp.argmax(axis=1)      def _e_step(self, X):         """E step.


from functools import partial, reduce from itertools import product import operator<ins>import time</ins> import warnings  import numpy as np


if self.refit:             self.best_estimator_ = clone(base_estimator).set_params(                 **self.best_params_)            refit_start_time = time.time()             if y is not None:                 self.best_estimator_.fit(X, y, **fit_params)             else:                 self.best_estimator_.fit(X, **fit_params)            refit_end_time = time.time()            self.refit_time_ = refit_end_time - refit_start_time          # Store the only scorer not as a dict for single metric evaluation         self.scorer_ = scorers if self.multimetric_ else scorers['score']


n_splits_ : int         The number of cross-validation splits (folds/iterations). <ins>    refit_time_ : float        Seconds used for refitting the best model on the whole dataset.        This is present only if ``refit`` is not False.</ins>     Notes     ------     The parameters selected are those that maximize the score of the left out


n_splits_ : int         The number of cross-validation splits (folds/iterations). <ins>    refit_time_ : float        Seconds used for refitting the best model on the whole dataset.        This is present only if ``refit`` is not False.</ins>     Notes     -----     The parameters selected are those that maximize the score of the held-out


if attr in params:             setattr(self, attr, params.pop(attr))         # 2. Step replacement        names, _ = zip(*getattr(self, attr))        items = getattr(self, attr)        names = []        if items:            names, _ = zip(*items)         for name in list(six.iterkeys(params)):             if '__' not in name and name in names:                 self._replace_estimator(attr, name, params.pop(name))


"""     Gram = Gram.copy('F') if copy_Gram else np.asfortranarray(Gram)     if copy_Xy:    if copy_Xy or not Xy.flags.writeable:         Xy = Xy.copy()      min_float = np.finfo(Gram.dtype).eps


Xy = Xy[:, np.newaxis]         if tol is not None:             norms_squared = [norms_squared]<ins>    if copy_Xy or not Xy.flags.writeable:        # Make the copy once instead of many times in _gram_omp itself.        Xy = Xy.copy()</ins>      if n_nonzero_coefs is None and tol is None:         n_nonzero_coefs = int(0.1 * len(Gram))


out = _gram_omp(             Gram, Xy[:, k], n_nonzero_coefs,             norms_squared[k] if tol is not None else None, tol,            copy_Gram=copy_Gram, copy_Xy=copy_Xy,            copy_Gram=copy_Gram, copy_Xy=False,             return_path=return_path)         if return_path:             _, idx, coefs, n_iter = out


]  <ins>def _check_inputs_dtype(X, missing_values):    if (X.dtype.kind in ("f", "i", "u") and            not isinstance(missing_values, numbers.Real)):        raise ValueError("'X' and 'missing_values' types are expected to be"                         " both numerical. Got X.dtype={} and "                         " type(missing_values)={}."                         .format(X.dtype, type(missing_values)))</ins> def _get_mask(X, value_to_mask):     """Compute the boolean mask X == missing_values."""     if value_to_mask is np.nan:


else:             # np.isnan does not work on object dtypes.             return _object_dtype_isnan(X)<del></del>     else:         # X == value_to_mask with object dytpes does not always perform         # element-wise for old versions of numpy


else:                 raise ve <ins>        _check_inputs_dtype(X, self.missing_values)</ins>         if X.dtype.kind not in ("i", "u", "f", "O"):             raise ValueError("SimpleImputer does not support data with dtype "                              "{0}. Please provide either a numeric array (with"


X = check_array(X, dtype=FLOAT_DTYPES, order="F",                         force_all_finite=force_all_finite)<ins>        _check_inputs_dtype(X, self.missing_values)</ins>          mask_missing_values = _get_mask(X, self.missing_values)         if self.initial_imputer_ is None:


a new copy will always be made, even if `copy=False`:          - If X is not an array of floating values;<del>        - If X is sparse and `missing_values=0`;</del>         - If X is encoded as a CSR matrix.      Attributes


"data".format(fill_value))          if sparse.issparse(X):            self.statistics_ = self._sparse_fit(X,                                                self.strategy,                                                self.missing_values,                                                fill_value)            # missing_values = 0 not allowed with sparse data as it would            # force densification            if self.missing_values == 0:                raise ValueError("Imputation not possible when missing_values "                                 "== 0 and input is sparse. Provide a dense "                                 "array instead.")            else:                self.statistics_ = self._sparse_fit(X,                                                    self.strategy,                                                    self.missing_values,                                                    fill_value)         else:             self.statistics_ = self._dense_fit(X,                                                self.strategy,


def _sparse_fit(self, X, strategy, missing_values, fill_value):         """Fit the transformer on sparse data."""        # Count the zeros        if missing_values == 0:            n_zeros_axis = np.zeros(X.shape[1], dtype=int)        else:            n_zeros_axis = X.shape[0] - np.diff(X.indptr)        # Mean        if strategy == "mean":            if missing_values != 0:                n_non_missing = n_zeros_axis                # Mask the missing elements                mask_missing_values = _get_mask(X.data, missing_values)                mask_valids = np.logical_not(mask_missing_values)                # Sum only the valid elements                new_data = X.data.copy()                new_data[mask_missing_values] = 0                X = sparse.csc_matrix((new_data, X.indices, X.indptr),                                      copy=False)                sums = X.sum(axis=0)                # Count the elements != 0                mask_non_zeros = sparse.csc_matrix(                    (mask_valids.astype(np.float64),                     X.indices,                     X.indptr), copy=False)                s = mask_non_zeros.sum(axis=0)                n_non_missing = np.add(n_non_missing, s)        mask_data = _get_mask(X.data, missing_values)        n_implicit_zeros = X.shape[0] - np.diff(X.indptr)             else:                sums = X.sum(axis=0)                n_non_missing = np.diff(X.indptr)        statistics = np.empty(X.shape[1])             # Ignore the error, columns with a np.nan statistics_            # are not an error at this point. These columns will            # be removed in transform            with np.errstate(all="ignore"):                return np.ravel(sums) / np.ravel(n_non_missing)        if strategy == "constant":            # for constant strategy, self.statistcs_ is used to store            # fill_value in each column            statistics.fill(fill_value)         # Median + Most frequent + Constant         else:            # Remove the missing values, for each column            columns_all = np.hsplit(X.data, X.indptr[1:-1])            mask_missing_values = _get_mask(X.data, missing_values)            mask_valids = np.hsplit(np.logical_not(mask_missing_values),                                    X.indptr[1:-1])            # astype necessary for bug in numpy.hsplit before v1.9            columns = [col[mask.astype(bool, copy=False)]                       for col, mask in zip(columns_all, mask_valids)]            # Median            if strategy == "median":                median = np.empty(len(columns))                for i, column in enumerate(columns):                    median[i] = _get_median(column, n_zeros_axis[i])                return median            # Most frequent            elif strategy == "most_frequent":                most_frequent = np.empty(len(columns))                for i, column in enumerate(columns):                    most_frequent[i] = _most_frequent(column,                                                      0,                                                      n_zeros_axis[i])                return most_frequent            # Constant            elif strategy == "constant":                return np.full(X.shape[1], fill_value)            for i in range(X.shape[1]):                column = X.data[X.indptr[i]:X.indptr[i+1]]                mask_column = mask_data[X.indptr[i]:X.indptr[i+1]]                column = column[~mask_column]                # combine explicit and implicit zeros                mask_zeros = _get_mask(column, 0)                column = column[~mask_zeros]                n_explicit_zeros = mask_zeros.sum()                n_zeros = n_implicit_zeros[i] + n_explicit_zeros                if strategy == "mean":                    s = column.size + n_zeros                    statistics[i] = np.nan if s == 0 else column.sum() / s                elif strategy == "median":                    statistics[i] = _get_median(column,                                                n_zeros)                elif strategy == "most_frequent":                    statistics[i] = _most_frequent(column,                                                   0,                                                   n_zeros)        return statistics      def _dense_fit(self, X, strategy, missing_values, fill_value):         """Fit the transformer on dense data."""


# Constant         elif strategy == "constant":<ins>            # for constant strategy, self.statistcs_ is used to store            # fill_value in each column</ins>             return np.full(X.shape[1], fill_value, dtype=X.dtype)      def transform(self, X):


X = X[:, valid_statistics_indexes]          # Do actual imputation        if sparse.issparse(X) and self.missing_values != 0:            mask = _get_mask(X.data, self.missing_values)            indexes = np.repeat(np.arange(len(X.indptr) - 1, dtype=np.int),                                np.diff(X.indptr))[mask]        if sparse.issparse(X):            if self.missing_values == 0:                raise ValueError("Imputation not possible when missing_values "                                 "== 0 and input is sparse. Provide a dense "                                 "array instead.")            else:                mask = _get_mask(X.data, self.missing_values)                indexes = np.repeat(np.arange(len(X.indptr) - 1, dtype=np.int),                                    np.diff(X.indptr))[mask]             X.data[mask] = valid_statistics[indexes].astype(X.dtype,                                                            copy=False)                X.data[mask] = valid_statistics[indexes].astype(X.dtype,                                                                copy=False)         else:            if sparse.issparse(X):                X = X.toarray()             mask = _get_mask(X, self.missing_values)             n_missing = np.sum(mask, axis=0)             values = np.repeat(valid_statistics, n_missing)


on the decision function. If 'auto', the decision function threshold is         determined as in the original paper. <ins>        .. versionchanged:: 0.20           The default value of ``contamination`` will change from 0.1 in 0.20           to ``'auto'`` in 0.22.</ins>     max_features : int or float, optional (default=1.0)         The number of features to draw from X to train each base estimator.


n_jobs=n_jobs,             random_state=random_state,             verbose=verbose)<del>        if contamination == "legacy":            warnings.warn('default contamination parameter 0.1 will change '                          'in version 0.22 to "auto". This will change the '                          'predict method behavior.',                          DeprecationWarning)</del>         self.contamination = contamination      def _set_oob_score(self, X, y):


-------         self : object         """<ins>        if self.contamination == "legacy":            warnings.warn('default contamination parameter 0.1 will change '                          'in version 0.22 to "auto". This will change the '                          'predict method behavior.',                          FutureWarning)            self._contamination = 0.1        else:            self._contamination = self.contamination</ins>         X = check_array(X, accept_sparse=['csc'])         if issparse(X):             # Pre-sort indices to avoid that each individual tree of the


max_depth=max_depth,                                           sample_weight=sample_weight)         if self.contamination == "auto":        if self._contamination == "auto":             # 0.5 plays a special role as described in the original paper.             # we take the opposite as we consider the opposite of their score.             self.offset_ = -0.5             # need to save (depreciated) threshold_ in this case:             self._threshold_ = sp.stats.scoreatpercentile(                 self.score_samples(X), 100. * 0.1)        elif self.contamination == "legacy":  # to be rm in 0.22            self.offset_ = sp.stats.scoreatpercentile(                self.score_samples(X), 100. * 0.1)         else:             self.offset_ = sp.stats.scoreatpercentile(                self.score_samples(X), 100. * self.contamination)                self.score_samples(X), 100. * self._contamination)          return self


check_input=False, max_squared_sum=max_squared_sum,         sample_weight=sample_weight)     log_reg = LogisticRegression(fit_intercept=fit_intercept)    log_reg = LogisticRegression(multi_class=multi_class)      # The score method of Logistic Regression has a classes_ attribute.     if multi_class == 'ovr':


else:     from . import __check_build     from .base import clone<ins>    from .utils._show_versions import show_versions</ins>     __check_build  # avoid flakes unused variable error      __all__ = ['calibration', 'cluster', 'covariance', 'cross_decomposition',


'preprocessing', 'random_projection', 'semi_supervised',                'svm', 'tree', 'discriminant_analysis', 'impute', 'compose',                # Non-modules:               'clone', 'get_config', 'set_config', 'config_context']               'clone', 'get_config', 'set_config', 'config_context',               'show_versions']   def setup_module(module):diff --git a/sklearn/utils/_show_versions.py b/sklearn/utils/_show_versions.pynew file mode 100644-- /dev/null++ b/sklearn/utils/_show_versions.py


<ins>"""Utility methods to print system info for debuggingadapted from :func:`pandas.show_versions`"""# License: BSD 3 clauseimport platformimport sysimport importlibdef _get_sys_info():    """System information    Return    ------    sys_info : dict        system and Python version information    """    python = sys.version.replace('\n', ' ')    blob = [        ("python", python),        ('executable', sys.executable),        ("machine", platform.platform()),    ]    return dict(blob)def _get_deps_info():    """Overview of the installed version of main dependencies    Returns    -------    deps_info: dict        version information on relevant Python libraries    """    deps = [        "pip",        "setuptools",        "sklearn",        "numpy",        "scipy",        "Cython",        "pandas",    ]    def get_version(module):        return module.__version__    deps_info = {}    for modname in deps:        try:            if modname in sys.modules:                mod = sys.modules[modname]            else:                mod = importlib.import_module(modname)            ver = get_version(mod)            deps_info[modname] = ver        except ImportError:            deps_info[modname] = None    return deps_infodef _get_blas_info():    """Information on system BLAS    Uses the `scikit-learn` builtin method    :func:`sklearn._build_utils.get_blas_info` which may fail from time to time    Returns    -------    blas_info: dict        system BLAS information    """    from .._build_utils import get_blas_info    cblas_libs, blas_dict = get_blas_info()    macros = ['{key}={val}'.format(key=a, val=b)              for (a, b) in blas_dict.get('define_macros', [])]    blas_blob = [        ('macros', ', '.join(macros)),        ('lib_dirs', ':'.join(blas_dict.get('library_dirs', ''))),        ('cblas_libs', ', '.join(cblas_libs)),    ]    return dict(blas_blob)def show_versions():    "Print useful debugging information"    sys_info = _get_sys_info()    deps_info = _get_deps_info()    blas_info = _get_blas_info()    print('\nSystem')    print('------')    for k, stat in sys_info.items():        print("{k:>10}: {stat}".format(k=k, stat=stat))    print('\nBLAS')    print('----')    for k, stat in blas_info.items():        print("{k:>10}: {stat}".format(k=k, stat=stat))    print('\nPython deps')    print('-----------')    for k, stat in deps_info.items():        print("{k:>10}: {stat}".format(k=k, stat=stat))</ins>


The metric to use when calculating distance between instances in a         feature array. If metric is a string, it must be one of the options         allowed by :func:`sklearn.metrics.pairwise.pairwise_distances`. If X is        the distance array itself, use "precomputed" as the metric.        the distance array itself, use "precomputed" as the metric. Precomputed        distance matrices must have 0 along the diagonal.      `**kwds` : optional keyword parameters         Any further parameters are passed directly to the distance function.


"""     X, labels = check_X_y(X, labels, accept_sparse=['csc', 'csr'])<ins>    # Check for diagonal entries in precomputed distance matrix    if metric == 'precomputed':        if np.any(np.diagonal(X)):            raise ValueError(                'The precomputed distance matrix contains non-zero '                'elements on the diagonal. Use np.fill_diagonal(X, 0).'            )</ins>     le = LabelEncoder()     labels = le.fit_transform(labels)     n_samples = len(labels)


This implementation deviates from the original OPTICS by first performing     k-nearest-neighborhood searches on all points to identify core sizes, then     computing only the distances to unprocessed points when constructing the    cluster order. It also does not employ a heap to manage the expansion    candiates, but rather uses numpy masked arrays. This can be potentially    slower with some parameters (at the benefit from using fast numpy code).    cluster order. Note that we do not employ a heap to manage the expansion    candidates, so the time complexity will be O(n^2).      Read more in the :ref:`User Guide <optics>`.


This implementation deviates from the original OPTICS by first performing     k-nearest-neighborhood searches on all points to identify core sizes, then     computing only the distances to unprocessed points when constructing the    cluster order.    cluster order. Note that we do not employ a heap to manage the expansion    candidates, so the time complexity will be O(n^2).      Read more in the :ref:`User Guide <optics>`.


n_jobs=self.n_jobs)          nbrs.fit(X)        # Here we first do a kNN query for each point, this differs from        # the original OPTICS that only used epsilon range queries.         self.core_distances_ = self._compute_core_distances_(X, nbrs)        # OPTICS puts an upper limit on these, use inf for undefined.        self.core_distances_[self.core_distances_ > self.max_eps] = np.inf         self.ordering_ = self._calculate_optics_order(X, nbrs)          indices_, self.labels_ = _extract_optics(self.ordering_,


return self      # OPTICS helper functions<del></del>     def _compute_core_distances_(self, X, neighbors, working_memory=None):         """Compute the k-th nearest neighbor of each sample


def _calculate_optics_order(self, X, nbrs):         # Main OPTICS loop. Not parallelizable. The order that entries are         # written to the 'ordering_' list is important!        # Note that this implementation is O(n^2) theoretically, but        # supposedly with very low constant factors.         processed = np.zeros(X.shape[0], dtype=bool)         ordering = np.zeros(X.shape[0], dtype=int)        ordering_idx = 0        for point in range(X.shape[0]):            if processed[point]:                continue            if self.core_distances_[point] <= self.max_eps:                while not processed[point]:                    processed[point] = True                    ordering[ordering_idx] = point                    ordering_idx += 1                    point = self._set_reach_dist(point, processed, X, nbrs)            else:  # For very noisy points                ordering[ordering_idx] = point                ordering_idx += 1                processed[point] = True        for ordering_idx in range(X.shape[0]):            # Choose next based on smallest reachability distance            # (And prefer smaller ids on ties, possibly np.inf!)            index = np.where(processed == 0)[0]            point = index[np.argmin(self.reachability_[index])]            processed[point] = True            ordering[ordering_idx] = point            if self.core_distances_[point] != np.inf:                self._set_reach_dist(point, processed, X, nbrs)         return ordering      def _set_reach_dist(self, point_index, processed, X, nbrs):         P = X[point_index:point_index + 1]        # Assume that radius_neighbors is faster without distances        # and we don't need all distances, nevertheless, this means        # we may be doing some work twice.         indices = nbrs.radius_neighbors(P, radius=self.max_eps,                                         return_distance=False)[0]          # Getting indices of neighbors that have not been processed         unproc = np.compress((~np.take(processed, indices)).ravel(),                              indices, axis=0)        # Keep n_jobs = 1 in the following lines...please        # Neighbors of current point are already processed.         if not unproc.size:            # Everything is already processed. Return to main loop            return point_index            return         # Only compute distances to unprocessed neighbors:         if self.metric == 'precomputed':             dists = X[point_index, unproc]         else:


self.reachability_[unproc[improved]] = rdists[improved]         self.predecessor_[unproc[improved]] = point_index <del>        # Choose next based on smallest reachability distance        # (And prefer smaller ids on ties).        # All unprocessed points qualify, not just new neighbors ("unproc")        return (np.ma.array(self.reachability_, mask=processed)                .argmin(fill_value=np.inf))</del>     def extract_dbscan(self, eps):         """Performs DBSCAN extraction for an arbitrary epsilon.


from .base import _transform_selected from .label import _encode, _encode_check_unknown  range = six.moves.range  __all__ = [     'OneHotEncoder',     'OrdinalEncoder'


"The 'categorical_features' keyword is deprecated in "                     "version 0.20 and will be removed in 0.22. You can "                     "use the ColumnTransformer instead.", DeprecationWarning)<ins>                # Set categories_ to empty list if no categorical columns exist                n_features = X.shape[1]                sel = np.zeros(n_features, dtype=bool)                sel[np.asarray(self.categorical_features)] = True                if sum(sel) == 0:                    self.categories_ = []</ins>                 self._legacy_mode = True             self._categorical_features = self.categorical_features         else:


X_out : sparse matrix if sparse=True else a 2-d array             Transformed input.         """<ins>        check_is_fitted(self, 'categories_')</ins>         if self._legacy_mode:             return _transform_selected(X, self._legacy_transform, self.dtype,                                        self._categorical_features,


cats = self.categories_         if input_features is None:             input_features = ['x%d' % i for i in range(len(cats))]        elif(len(input_features) != len(self.categories_)):        elif len(input_features) != len(self.categories_):             raise ValueError(                 "input_features should have length equal to number of "                 "features ({}), got {}".format(len(self.categories_),


if len(x.shape) == 0:             raise TypeError("Singleton array %r cannot be considered"                             " a valid collection." % x)        return x.shape[0]        # Check that shape is returning an integer or default to len        # Dask dataframes may not return numeric shape[0] value        if isinstance(x.shape[0], numbers.Integral):            return x.shape[0]        else:            return len(x)     else:         return len(x)


# continue `The rows are marked `X_mask` and will be                     # removed later.                     X_mask[:, i] = valid_mask                    Xi = Xi.copy()                    # cast Xi into the largest string type necessary                    # to handle different lengths of numpy strings                    if (self.categories_[i].dtype.kind in ('U', 'S')                            and self.categories_[i].itemsize > Xi.itemsize):                        Xi = Xi.astype(self.categories_[i].dtype)                    else:                        Xi = Xi.copy()                     Xi[~valid_mask] = self.categories_[i][0]             _, encoded = _encode(Xi, self.categories_[i], encode=True)             X_int[:, i] = encoded


y_type = type_of_target(y)         y_pred = clf.predict_proba(X)         if y_type == "binary":            y_pred = y_pred[:, 1]            if y_pred.shape[1] == 2:                y_pred = y_pred[:, 1]            else:                raise ValueError('got predict_proba of shape {},'                                 ' but need classifier with two'                                 ' classes for {} scoring'.format(                                     y_pred.shape, self._score_func.__name__))         if sample_weight is not None:             return self._sign * self._score_func(y, y_pred,                                                  sample_weight=sample_weight,


y_pred = clf.predict_proba(X)                  if y_type == "binary":                    y_pred = y_pred[:, 1]                    if y_pred.shape[1] == 2:                        y_pred = y_pred[:, 1]                    else:                        raise ValueError('got predict_proba of shape {},'                                         ' but need classifier with two'                                         ' classes for {} scoring'.format(                                             y_pred.shape,                                             self._score_func.__name__))                 elif isinstance(y_pred, list):                     y_pred = np.vstack([p[:, -1] for p in y_pred]).T


a new copy will always be made, even if `copy=False`:          - If X is not an array of floating values;        - If X is encoded as a CSR matrix.        - If X is encoded as a CSR matrix;        - If add_indicator=True.    add_indicator : boolean, optional (default=False)        If True, a `MissingIndicator` transform will stack onto output        of the imputer's transform. This allows a predictive estimator        to account for missingness despite imputation. If a feature has no        missing values at fit/train time, the feature won't appear on        the missing indicator even if there are missing values at        transform/test time.      Attributes     ----------     statistics_ : array of shape (n_features,)         The imputation fill value for each feature.     indicator_ : :class:`sklearn.impute.MissingIndicator`        Indicator used to add binary indicators for missing values.        ``None`` if add_indicator is False.     See also     --------     IterativeImputer : Multivariate imputation of missing values.


>>> imp_mean = SimpleImputer(missing_values=np.nan, strategy='mean')     >>> imp_mean.fit([[7, 2, 3], [4, np.nan, 6], [10, 5, 9]])     ... # doctest: +NORMALIZE_WHITESPACE    SimpleImputer(copy=True, fill_value=None, missing_values=nan,           strategy='mean', verbose=0)    SimpleImputer(add_indicator=False, copy=True, fill_value=None,            missing_values=nan, strategy='mean', verbose=0)     >>> X = [[np.nan, 2, 3], [4, np.nan, 6], [10, np.nan, 9]]     >>> print(imp_mean.transform(X))     ... # doctest: +NORMALIZE_WHITESPACE


"""     def __init__(self, missing_values=np.nan, strategy="mean",                 fill_value=None, verbose=0, copy=True):                 fill_value=None, verbose=0, copy=True, add_indicator=False):         self.missing_values = missing_values         self.strategy = strategy         self.fill_value = fill_value         self.verbose = verbose         self.copy = copy        self.add_indicator = add_indicator      def _validate_input(self, X):         allowed_strategies = ["mean", "median", "most_frequent", "constant"]


self.missing_values,                                                fill_value) <ins>        if self.add_indicator:            self.indicator_ = MissingIndicator(                missing_values=self.missing_values)            self.indicator_.fit(X)        else:            self.indicator_ = None</ins>         return self      def _sparse_fit(self, X, strategy, missing_values, fill_value):


# for constant strategy, self.statistcs_ is used to store             # fill_value in each column             statistics.fill(fill_value)<del></del>         else:             for i in range(X.shape[1]):                 column = X.data[X.indptr[i]:X.indptr[i + 1]]


raise ValueError("X has %d features per sample, expected %d"                              % (X.shape[1], self.statistics_.shape[0])) <ins>        if self.add_indicator:            X_trans_indicator = self.indicator_.transform(X)</ins>         # Delete the invalid columns if strategy is not constant         if self.strategy == "constant":             valid_statistics = statistics


X[coordinates] = values <ins>        if self.add_indicator:            hstack = sparse.hstack if sparse.issparse(X) else np.hstack            X = hstack((X, X_trans_indicator))</ins>         return X      def _more_tags(self):


# XXX: not handling dictionaries     if estimator_type in (list, tuple, set, frozenset):         return estimator_type([clone(e, safe=safe) for e in estimator])    elif not hasattr(estimator, 'get_params'):    elif not hasattr(estimator, 'get_params') or isinstance(estimator, type):         if not safe:             return copy.deepcopy(estimator)         else:


# check if the object contains several dtypes (typically a pandas     # DataFrame), and store them. If not, store None.     dtypes_orig = None    if hasattr(array, "dtypes") and hasattr(array, "__array__"):    if hasattr(array, "dtypes") and len(array.dtypes):         dtypes_orig = np.array(array.dtypes)      if dtype_numeric:


from itertools import chain  import numpy as np<ins>import warnings</ins> from scipy import sparse  from ..base import clone, TransformerMixin


return False  def _validate_transformers(transformers):    """Checks if given transformers are valid.    This is a helper function to support the deprecated tuple order.    XXX Remove in v0.22    """    if not transformers:        return True    for t in transformers:        if t in ('drop', 'passthrough'):            continue        if (not (hasattr(t, "fit") or hasattr(t, "fit_transform")) or not                hasattr(t, "transform")):            return False    return Truedef _is_deprecated_tuple_order(tuples):    """Checks if the input follows the deprecated tuple order.    Returns    -------    Returns true if (transformer, columns) is not a valid assumption for the    input, but (columns, transformer) is valid. The latter is deprecated and    its support will stop in v0.22.    XXX Remove in v0.22    """    transformers, columns = zip(*tuples)    if (not _validate_transformers(transformers)            and _validate_transformers(columns)):        return True    return False def _get_transformer_list(estimators):     """     Construct (name, trans, column) tuples from list      """    transformers = [trans[1] for trans in estimators]    columns = [trans[0] for trans in estimators]    names = [trans[0] for trans in _name_estimators(transformers)]    message = ('`make_column_transformer` now expects (transformer, columns) '               'as input tuples instead of (columns, transformer). This '               'has been introduced in v0.20.1. `make_column_transformer` '               'will stop accepting the deprecated (columns, transformer) '               'order in v0.22.')    transformers, columns = zip(*estimators)    # XXX Remove in v0.22    if _is_deprecated_tuple_order(estimators):        transformers, columns = columns, transformers        warnings.warn(message, DeprecationWarning)    names, _ = zip(*_name_estimators(transformers))      transformer_list = list(zip(names, transformers, columns))     return transformer_list


Parameters     ----------    *transformers : tuples of column selections and transformers    *transformers : tuples of transformers and column selections      remainder : {'drop', 'passthrough'} or estimator, default 'drop'         By default, only the specified columns in `transformers` are


>>> from sklearn.preprocessing import StandardScaler, OneHotEncoder     >>> from sklearn.compose import make_column_transformer     >>> make_column_transformer(    ...     (['numerical_column'], StandardScaler()),    ...     (['categorical_column'], OneHotEncoder()))    ...     (StandardScaler(), ['numerical_column']),    ...     (OneHotEncoder(), ['categorical_column']))     ...     # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS     ColumnTransformer(n_jobs=None, remainder='drop', sparse_threshold=0.3,              transformer_weights=None,


y_pred : 1d array-like, or label indicator array / sparse matrix         Predicted labels, as returned by a classifier.     labels : array, shape = [n_labels], optional (default=None)    labels : array, shape = [n_labels], optional (default='deprecated')         Integer array of labels. If not provided, labels will be inferred         from y_true and y_pred.          .. versionadded:: 0.18        .. deprecated:: 0.21           This parameter ``labels`` is deprecated in version 0.21 and will           be removed in version 0.23. Hamming loss uses ``y_true.shape[1]``           for the number of labels when y_true is binary label indicators,           so it is unnecessary for the user to specify.      sample_weight : array-like of shape = [n_samples], optional         Sample weights.


y_type, y_true, y_pred = _check_targets(y_true, y_pred)     check_consistent_length(y_true, y_pred, sample_weight)     if labels is None:        labels = unique_labels(y_true, y_pred)    else:        labels = np.asarray(labels)    if labels is not None:        warnings.warn("The labels parameter is unused. It was"                      " deprecated in version 0.21 and"                      " will be removed in version 0.23",                      DeprecationWarning)      if sample_weight is None:         weight_average = 1.


n_differences = count_nonzero(y_true - y_pred,                                       sample_weight=sample_weight)         return (n_differences /                (y_true.shape[0] * len(labels) * weight_average))                (y_true.shape[0] * y_true.shape[1] * weight_average))      elif y_type in ["binary", "multiclass"]:         return _weighted_sum(y_true != y_pred, sample_weight, normalize=True)


return True      for t in transformers:        if t in ('drop', 'passthrough'):        if isinstance(t, six.string_types) and t in ('drop', 'passthrough'):             continue         if (not (hasattr(t, "fit") or hasattr(t, "fit_transform")) or not                 hasattr(t, "transform")):


if test_size is not None:         if np.asarray(test_size).dtype.kind == 'f':            if test_size >= 1.:            if test_size >= 1. or test_size <= 0:                 raise ValueError(                    'test_size=%f should be smaller '                    'than 1.0 or be an integer' % test_size)                    'test_size=%f should be in the (0, 1) range '                    'or be an integer' % test_size)         elif np.asarray(test_size).dtype.kind != 'i':             # int values are checked during split based on the input             raise ValueError("Invalid value for test_size: %r" % test_size)      if train_size is not None:         if np.asarray(train_size).dtype.kind == 'f':            if train_size >= 1.:                raise ValueError("train_size=%f should be smaller "                                 "than 1.0 or be an integer" % train_size)            if train_size >= 1. or train_size <= 0:                raise ValueError('train_size=%f should be in the (0, 1) range '                                 'or be an integer' % train_size)             elif (np.asarray(test_size).dtype.kind == 'f' and                    (train_size + test_size) > 1.):                    (                        (train_size + test_size) > 1. or                        (train_size + test_size) < 0)):                 raise ValueError('The sum of test_size and train_size = %f, '                                 'should be smaller than 1.0. Reduce '                                 'should be in the (0, 1) range. Reduce '                                  'test_size and/or train_size.' %                                  (train_size + test_size))         elif np.asarray(train_size).dtype.kind != 'i':


size of the data (n_samples)     """     if (test_size is not None and            np.asarray(test_size).dtype.kind == 'i' and            test_size >= n_samples):        raise ValueError('test_size=%d should be smaller than the number of '                         'samples %d' % (test_size, n_samples))            (np.asarray(test_size).dtype.kind == 'i' and                (test_size >= n_samples or test_size <= 0)) or            (np.asarray(test_size).dtype.kind == 'f' and                (test_size <= 0 or test_size >= 1))):        raise ValueError('test_size=%d should be either positive and smaller '                         'than the number of samples %d or a float in the '                         '(0,1) range' % (test_size, n_samples))      if (train_size is not None and            np.asarray(train_size).dtype.kind == 'i' and            train_size >= n_samples):        raise ValueError("train_size=%d should be smaller than the number of"                         " samples %d" % (train_size, n_samples))            (np.asarray(train_size).dtype.kind == 'i' and                (train_size >= n_samples or train_size <= 0)) or            (np.asarray(train_size).dtype.kind == 'f' and                (train_size <= 0 or train_size >= 1))):        raise ValueError('train_size=%d should be either positive and smaller '                         'than the number of samples %d or a float in the '                         '(0,1) range' % (train_size, n_samples))      if test_size == "default":         test_size = 0.1


...             }         The reported averages include micro average (averaging the        total true positives, false negatives and false positives), macro        average (averaging the unweighted mean per label), weighted average        (averaging the support-weighted mean per label) and sample average        (only for multilabel classification). See also        :func:`precision_recall_fscore_support` for more details on averages.        The reported averages include macro average (averaging the unweighted        mean per label), weighted average (averaging the support-weighted mean        per label), sample average (only for multilabel classification) and        micro average (averaging the total true positives, false negatives and        false positives) it is only shown for multi-label or multi-class        with a subset of classes because it is accuracy otherwise.        See also:func:`precision_recall_fscore_support` for more details        on averages.          Note that in binary classification, recall of the positive class         is also known as "sensitivity"; recall of the negative class is


class 1       0.00      0.00      0.00         1          class 2       1.00      0.67      0.80         3     <BLANKLINE>       micro avg       0.60      0.60      0.60         5        accuracy                           0.60         5        macro avg       0.50      0.56      0.49         5     weighted avg       0.70      0.60      0.61         5     <BLANKLINE>    >>> y_pred = [1, 1, 0]    >>> y_true = [1, 1, 1]    >>> print(classification_report(y_true, y_pred, labels=[1, 2, 3]))                  precision    recall  f1-score   support    <BLANKLINE>               1       1.00      0.67      0.80         3               2       0.00      0.00      0.00         0               3       0.00      0.00      0.00         0    <BLANKLINE>       micro avg       1.00      0.67      0.80         3       macro avg       0.33      0.22      0.27         3    weighted avg       1.00      0.67      0.80         3    <BLANKLINE>     """      y_type, y_true, y_pred = _check_targets(y_true, y_pred)


else:         labels = np.asarray(labels) <ins>    # labelled micro average    micro_is_accuracy = ((y_type == 'multiclass' or y_type == 'binary') and                         (not labels_given or                          (set(labels) == set(unique_labels(y_true, y_pred)))))</ins>     if target_names is not None and len(labels) != len(target_names):         if labels_given:             warnings.warn(


# compute all applicable averages     for average in average_options:        line_heading = average + ' avg'        if average.startswith('micro') and micro_is_accuracy:            line_heading = 'accuracy'        else:            line_heading = average + ' avg'         # compute averages with specified averaging method         avg_p, avg_r, avg_f1, _ = precision_recall_fscore_support(             y_true, y_pred, labels=labels,


report_dict[line_heading] = dict(                 zip(headers, [i.item() for i in avg]))         else:            report += row_fmt.format(line_heading, *avg,                                     width=width, digits=digits)            if line_heading == 'accuracy':                row_fmt_accuracy = u'{:>{width}s} ' + \                        u' {:>9.{digits}}' * 2 + u' {:>9.{digits}f}' + \                        u' {:>9}\n'                report += row_fmt_accuracy.format(line_heading, '', '',                                                  *avg[2:], width=width,                                                  digits=digits)            else:                report += row_fmt.format(line_heading, *avg,                                         width=width, digits=digits)      if output_dict:        if 'accuracy' in report_dict.keys():            report_dict['accuracy'] = report_dict['accuracy']['precision']         return report_dict     else:         return report


def davies_bouldin_score(X, labels):     """Computes the Davies-Bouldin score.     The score is defined as the ratio of within-cluster distances to    between-cluster distances.    The score is defined as the average similarity measure of each cluster with    its most similar cluster, where similarity is the ratio of within-cluster    distances to between-cluster distances. Thus, clusters which are farther    apart and less dispersed will result in a better score.    The minimum score is zero, with lower values indicating better clustering.      Read more in the :ref:`User Guide <davies-bouldin_index>`.


if np.allclose(intra_dists, 0) or np.allclose(centroid_distances, 0):         return 0.0     score = (intra_dists[:, None] + intra_dists) / centroid_distances    score[score == np.inf] = np.nan    return np.mean(np.nanmax(score, axis=1))    centroid_distances[centroid_distances == 0] = np.inf    combined_intra_dists = intra_dists[:, None] + intra_dists    scores = np.max(combined_intra_dists / centroid_distances, axis=1)    return np.mean(scores)


to spread out the most frequent values. It also reduces the impact of     (marginal) outliers: this is therefore a robust preprocessing scheme.     The transformation is applied on each feature independently.    The cumulative distribution function of a feature is used to project the    original values. Features values of new/unseen data that fall below    or above the fitted range will be mapped to the bounds of the output    The transformation is applied on each feature independently. First an    estimate of the cumulative distribution function of a feature is    used to map the original values to a uniform distribution. The obtained    values are then mapped to the desired output distribution using the    associated quantile function. Features values of new/unseen data that fall    below or above the fitted range will be mapped to the bounds of the output     distribution. Note that this transform is non-linear. It may distort linear     correlations between variables measured at the same scale but renders     variables measured at different scales more directly comparable.


def _transform_col(self, X_col, quantiles, inverse):         """Private function to transform a single feature"""         if self.output_distribution == 'normal':            output_distribution = 'norm'        else:            output_distribution = self.output_distribution        output_distribution = getattr(stats, output_distribution)        output_distribution = self.output_distribution          if not inverse:             lower_bound_x = quantiles[0]


upper_bound_x = 1             lower_bound_y = quantiles[0]             upper_bound_y = quantiles[-1]            #  for inverse transform, match a uniform PDF            #  for inverse transform, match a uniform distribution             with np.errstate(invalid='ignore'):  # hide NaN comparison warnings                X_col = output_distribution.cdf(X_col)                if output_distribution == 'normal':                    X_col = stats.norm.cdf(X_col)                # else output distribution is already a uniform distribution         # find index for lower and higher bounds         with np.errstate(invalid='ignore'):  # hide NaN comparison warnings            lower_bounds_idx = (X_col - BOUNDS_THRESHOLD <                                lower_bound_x)            upper_bounds_idx = (X_col + BOUNDS_THRESHOLD >                                upper_bound_x)            if output_distribution == 'normal':                lower_bounds_idx = (X_col - BOUNDS_THRESHOLD <                                    lower_bound_x)                upper_bounds_idx = (X_col + BOUNDS_THRESHOLD >                                    upper_bound_x)            if output_distribution == 'uniform':                lower_bounds_idx = (X_col == lower_bound_x)                upper_bounds_idx = (X_col == upper_bound_x)          isfinite_mask = ~np.isnan(X_col)         X_col_finite = X_col[isfinite_mask]


X_col[upper_bounds_idx] = upper_bound_y         X_col[lower_bounds_idx] = lower_bound_y        # for forward transform, match the output PDF        # for forward transform, match the output distribution         if not inverse:             with np.errstate(invalid='ignore'):  # hide NaN comparison warnings                X_col = output_distribution.ppf(X_col)            # find the value to clip the data to avoid mapping to            # infinity. Clip such that the inverse transform will be            # consistent            clip_min = output_distribution.ppf(BOUNDS_THRESHOLD -                                               np.spacing(1))            clip_max = output_distribution.ppf(1 - (BOUNDS_THRESHOLD -                                                    np.spacing(1)))            X_col = np.clip(X_col, clip_min, clip_max)                if output_distribution == 'normal':                    X_col = stats.norm.ppf(X_col)                    # find the value to clip the data to avoid mapping to                    # infinity. Clip such that the inverse transform will be                    # consistent                    clip_min = stats.norm.ppf(BOUNDS_THRESHOLD - np.spacing(1))                    clip_max = stats.norm.ppf(1 - (BOUNDS_THRESHOLD -                                                   np.spacing(1)))                    X_col = np.clip(X_col, clip_min, clip_max)                # else output distribution is uniform and the ppf is the                # identity function so we let X_col unchanged          return X_col


raise ValueError('QuantileTransformer only accepts'                                  ' non-negative sparse matrices.')         # check the output PDF        # check the output distribution         if self.output_distribution not in ('normal', 'uniform'):             raise ValueError("'output_distribution' has to be either 'normal'"                              " or 'uniform'. Got '{}' instead.".format(


else:             n_samples = proba[0].shape[0]            predictions = np.zeros((n_samples, self.n_outputs_))            # all dtypes should be the same, so just take the first            class_type = self.classes_[0].dtype            predictions = np.empty((n_samples, self.n_outputs_),                                   dtype=class_type)              for k in range(self.n_outputs_):                 predictions[:, k] = self.classes_[k].take(np.argmax(proba[k],


raise ValueError("Logistic Regression supports only solvers in %s, got"                          " %s." % (all_solvers, solver))     all_penalties = ['l1', 'l2', 'elasticnet']    all_penalties = ['l1', 'l2', 'elasticnet', 'none']     if penalty not in all_penalties:         raise ValueError("Logistic Regression supports only penalties in %s,"                          " got %s." % (all_penalties, penalty))     if solver not in ['liblinear', 'saga'] and penalty != 'l2':        raise ValueError("Solver %s supports only l2 penalties, "    if solver not in ['liblinear', 'saga'] and penalty not in ('l2', 'none'):        raise ValueError("Solver %s supports only 'l2' or 'none' penalties, "                          "got %s penalty." % (solver, penalty))     if solver != 'liblinear' and dual:         raise ValueError("Solver %s supports only "


if penalty == 'elasticnet' and solver != 'saga':         raise ValueError("Only 'saga' solver supports elasticnet penalty,"                          " got solver={}.".format(solver))<ins>    if solver == 'liblinear' and penalty == 'none':        raise ValueError(            "penalty='none' is not supported for the liblinear solver"        )</ins>     return solver


'sag', 'saga' and 'newton-cg' solvers.)      This class implements regularized logistic regression using the    'liblinear' library, 'newton-cg', 'sag', 'saga' and 'lbfgs' solvers. It can    handle both dense and sparse input. Use C-ordered arrays or CSR matrices    containing 64-bit floats for optimal performance; any other input format    will be converted (and copied).    'liblinear' library, 'newton-cg', 'sag', 'saga' and 'lbfgs' solvers. **Note    that regularization is applied by default**. It can handle both dense    and sparse input. Use C-ordered arrays or CSR matrices containing 64-bit    floats for optimal performance; any other input format will be converted    (and copied).      The 'newton-cg', 'sag', and 'lbfgs' solvers support only L2 regularization    with primal formulation. The 'liblinear' solver supports both L1 and L2    regularization, with a dual formulation only for the L2 penalty. The    Elastic-Net regularization is only supported by the 'saga' solver.    with primal formulation, or no regularization. The 'liblinear' solver    supports both L1 and L2 regularization, with a dual formulation only for    the L2 penalty. The Elastic-Net regularization is only supported by the    'saga' solver.      Read more in the :ref:`User Guide <logistic_regression>`.      Parameters     ----------    penalty : str, 'l1', 'l2', or 'elasticnet', optional (default='l2')    penalty : str, 'l1', 'l2', 'elasticnet' or 'none', optional (default='l2')         Used to specify the norm used in the penalization. The 'newton-cg',         'sag' and 'lbfgs' solvers support only l2 penalties. 'elasticnet' is        only supported by the 'saga' solver.        only supported by the 'saga' solver. If 'none' (not supported by the        liblinear solver), no regularization is applied.          .. versionadded:: 0.19            l1 penalty with SAGA solver (allowing 'multinomial' + L1)


- For multiclass problems, only 'newton-cg', 'sag', 'saga' and 'lbfgs'           handle multinomial loss; 'liblinear' is limited to one-versus-rest           schemes.        - 'newton-cg', 'lbfgs' and 'sag' only handle L2 penalty, whereas          'liblinear' and 'saga' handle L1 penalty.        - 'newton-cg', 'lbfgs', 'sag' and 'saga' handle L2 or no penalty        - 'liblinear' and 'saga' also handle L1 penalty        - 'saga' also supports 'elasticnet' penalty        - 'liblinear' does not handle no penalty          Note that 'sag' and 'saga' fast convergence is only guaranteed on         features with approximately the same scale. You can


warnings.warn("l1_ratio parameter is only used when penalty is "                           "'elasticnet'. Got "                           "(penalty={})".format(self.penalty))<ins>        if self.penalty == 'none':            if self.C != 1.0:  # default values                warnings.warn(                    "Setting penalty='none' will ignore the C and l1_ratio "                    "parameters"                )                # Note that check for l1_ratio is done right above            C_ = np.inf            penalty = 'l2'        else:            C_ = self.C            penalty = self.penalty</ins>         if not isinstance(self.max_iter, numbers.Number) or self.max_iter < 0:             raise ValueError("Maximum number of iteration must be positive;"                              " got (max_iter=%r)" % self.max_iter)


prefer = 'processes'         fold_coefs_ = Parallel(n_jobs=self.n_jobs, verbose=self.verbose,                                **_joblib_parallel_args(prefer=prefer))(            path_func(X, y, pos_class=class_, Cs=[self.C],            path_func(X, y, pos_class=class_, Cs=[C_],                       l1_ratio=self.l1_ratio, fit_intercept=self.fit_intercept,                       tol=self.tol, verbose=self.verbose, solver=solver,                       multi_class=multi_class, max_iter=self.max_iter,                       class_weight=self.class_weight, check_input=False,                       random_state=self.random_state, coef=warm_start_coef_,                      penalty=self.penalty, max_squared_sum=max_squared_sum,                      penalty=penalty, max_squared_sum=max_squared_sum,                       sample_weight=sample_weight)             for class_, warm_start_coef_ in zip(classes_, warm_start_coef))


l1_ratios_ = [None] <ins>        if self.penalty == 'none':            raise ValueError(                "penalty='none' is not useful and not supported by "                "LogisticRegressionCV."            )</ins>         X, y = check_X_y(X, y, accept_sparse='csr', dtype=np.float64,                          order="C",                          accept_large_sparse=solver != 'liblinear')


self._format(v, stream, indent + len(rep) + len(middle), allowance,                      context, level)     _dispatch = pprint.PrettyPrinter._dispatch    # Note: need to copy _dispatch to prevent instances of the builtin    # PrettyPrinter class to call methods of _EstimatorPrettyPrinter (see issue    # 12906)    _dispatch = pprint.PrettyPrinter._dispatch.copy()     _dispatch[BaseEstimator.__repr__] = _pprint_estimator     _dispatch[KeyValTuple.__repr__] = _pprint_key_val_tuple


in product(candidate_params,                                           cv.split(X, y, groups))) <ins>                if len(out) < 1:                    raise ValueError('No fits were performed. '                                     'Was the CV iterator empty? '                                     'Were there no candidates?')                elif len(out) != n_candidates * n_splits:                    raise ValueError('cv.split and cv.get_n_splits returned '                                     'inconsistent results. Expected {} '                                     'splits, got {}'                                     .format(n_splits,                                             len(out) // n_candidates))</ins>                 all_candidate_params.extend(candidate_params)                 all_out.extend(out)


self.eps = eps         self.fit_path = True     def fit(self, X, y, copy_X=True):    def fit(self, X, y, copy_X=None):         """Fit the model using X, y as training data.          Parameters


y : array-like, shape (n_samples,)             target values. Will be cast to X's dtype if necessary         copy_X : boolean, optional, default True        copy_X : boolean, optional, default None            If provided, this parameter will override the choice            of copy_X made at instance creation.             If ``True``, X will be copied; else, it may be overwritten.          Returns


self : object             returns an instance of self.         """        if copy_X is None:            copy_X = self.copy_X         X, y = check_X_y(X, y, y_numeric=True)          X, y, Xmean, ymean, Xstd = LinearModel._preprocess_data(            X, y, self.fit_intercept, self.normalize, self.copy_X)            X, y, self.fit_intercept, self.normalize, copy_X)         max_iter = self.max_iter          Gram = self.precompute


init :  None | 'random' | 'nndsvd' | 'nndsvda' | 'nndsvdar'         Method used to initialize the procedure.        Default: 'nndsvd' if n_components < n_features, otherwise 'random'.        Default: None.         Valid options:         - None: 'nndsvd' if n_components < n_features, otherwise 'random'.         - 'random': non-negative random matrices, scaled with:             sqrt(X.mean() / n_components)


def non_negative_factorization(X, W=None, H=None, n_components=None,                               init='random', update_H=True, solver='cd',                               init='warn', update_H=True, solver='cd',                                beta_loss='frobenius', tol=1e-4,                                max_iter=200, alpha=0., l1_ratio=0.,                                regularization=None, random_state=None,


Number of components, if n_components is not set all features         are kept.     init :  None | 'random' | 'nndsvd' | 'nndsvda' | 'nndsvdar' | 'custom'    init : None | 'random' | 'nndsvd' | 'nndsvda' | 'nndsvdar' | 'custom'         Method used to initialize the procedure.         Default: 'random'.        The default value will change from 'random' to None in version 0.23        to make it consistent with decomposition.NMF.         Valid options:         - None: 'nndsvd' if n_components < n_features, otherwise 'random'.         - 'random': non-negative random matrices, scaled with:             sqrt(X.mean() / n_components)


raise ValueError("Tolerance for stopping criteria must be "                          "positive; got (tol=%r)" % tol) <ins>    if init == "warn":        if n_components < n_features:            warnings.warn("The default value of init will change from "                          "random to None in 0.23 to make it consistent "                          "with decomposition.NMF.", FutureWarning)        init = "random"</ins>     # check W and H, or initialize them     if init == 'custom' and update_H:         _check_init(H, (n_components, n_features), "NMF (input H)")


Number of components, if n_components is not set all features         are kept.     init :  'random' | 'nndsvd' |  'nndsvda' | 'nndsvdar' | 'custom'    init : None | 'random' | 'nndsvd' |  'nndsvda' | 'nndsvdar' | 'custom'         Method used to initialize the procedure.        Default: 'nndsvd' if n_components < n_features, otherwise random.        Default: None.         Valid options:         - None: 'nndsvd' if n_components < n_features, otherwise random.         - 'random': non-negative random matrices, scaled with:             sqrt(X.mean() / n_components)


return X  <ins># Use at least float64 for the accumulating functions to avoid precision issue# see https://github.com/numpy/numpy/issues/9393. The float64 is also retained# as it is in case the float overflowsdef _safe_accumulator_op(op, x, *args, **kwargs):    """    This function provides numpy accumulator functions with a float64 dtype    when used on a floating point input. This prevents accumulator overflow on    smaller floating point dtypes.    Parameters    ----------    op : function        A numpy accumulator function such as np.mean or np.sum    x : numpy array        A numpy array to apply the accumulator function    *args : positional arguments        Positional arguments passed to the accumulator function after the        input x    **kwargs : keyword arguments        Keyword arguments passed to the accumulator function    Returns    -------    result : The output of the accumulator function passed to this function    """    if np.issubdtype(x.dtype, np.floating) and x.dtype.itemsize < 8:        result = op(x, *args, **kwargs, dtype=np.float64)    else:        result = op(x, *args, **kwargs)    return result</ins> def _incremental_mean_and_var(X, last_mean, last_variance, last_sample_count):     """Calculate mean update and a Youngs and Cramer variance update.


# new = the current increment     # updated = the aggregated stats     last_sum = last_mean * last_sample_count    if np.issubdtype(X.dtype, np.floating) and X.dtype.itemsize < 8:        # Use at least float64 for the accumulator to avoid precision issues;        # see https://github.com/numpy/numpy/issues/9393        new_sum = np.nansum(X, axis=0, dtype=np.float64).astype(X.dtype)    else:        new_sum = np.nansum(X, axis=0)    new_sum = _safe_accumulator_op(np.nansum, X, axis=0)      new_sample_count = np.sum(~np.isnan(X), axis=0)     updated_sample_count = last_sample_count + new_sample_count


if last_variance is None:         updated_variance = None     else:        new_unnormalized_variance = np.nanvar(X, axis=0) * new_sample_count        new_unnormalized_variance = (            _safe_accumulator_op(np.nanvar, X, axis=0) * new_sample_count)         last_unnormalized_variance = last_variance * last_sample_count          with np.errstate(divide='ignore', invalid='ignore'):diff --git a/sklearn/utils/validation.py b/sklearn/utils/validation.py-- a/sklearn/utils/validation.py++ b/sklearn/utils/validation.py


def _assert_all_finite(X, allow_nan=False):     """Like assert_all_finite, but only for ndarray."""    # validation is also imported in extmath    from .extmath import _safe_accumulator_op     if _get_config()['assume_finite']:         return     X = np.asanyarray(X)     # First try an O(n) time, O(1) space solution for the common case that     # everything is finite; fall back to O(n) space np.isfinite to prevent    # false positives from overflow in sum method.    # false positives from overflow in sum method. The sum is also calculated    # safely to reduce dtype induced overflows.     is_float = X.dtype.kind in 'fc'    if is_float and np.isfinite(X.sum()):    if is_float and (np.isfinite(_safe_accumulator_op(np.sum, X))):         pass     elif is_float:         msg_err = "Input contains {} or a value too large for {!r}."


"""     n_columns = X.shape[1]     if _check_key_type(key, int):        if isinstance(key, int):            return [key]        elif isinstance(key, slice):            return list(range(n_columns)[key])        else:            return list(key)    if (_check_key_type(key, int)            or hasattr(key, 'dtype') and np.issubdtype(key.dtype, np.bool_)):        # Convert key into positive indexes        idx = np.arange(n_columns)[key]        return np.atleast_1d(idx).tolist()     elif _check_key_type(key, str):         try:             all_columns = list(X.columns)


columns = list(key)          return [all_columns.index(col) for col in columns]<del>    elif hasattr(key, 'dtype') and np.issubdtype(key.dtype, np.bool_):        # boolean mask        return list(np.arange(n_columns)[key])</del>     else:         raise ValueError("No valid specification of the columns. Only a "                          "scalar, list or slice of all integers or all "