Question: Deprecate Imputer with axis=1 After having tried to deal with a few issues related to extending behaviour, I believe we should be removing the parameter from . It seems a strange feature to support in a machine learning context, except perhaps where the features represent something like a time series. It is not stateful and can be performed with a FunctionTransformer. (We could even provide a function, if we felt it necessary, which would roughly be defined as .) It complicates the implementation, which already has a bunch of weird edge-cases (to handle sparse data with missing indicated by 0 which is an inefficient use of a sparse data structure; and to handle non-NaN missingness indicators), unnecessarily. It is often nonsensical to extend further features to the case. Do others agree? [MRG+1] Deprecate ` argument Deprecated the argument on the class.

" got strategy={1}".format(allowed_strategies,                                                         self.strategy))         if self.axis not in [0, 1]:        if self.axis is None:            self._axis = 0        else:            warnings.warn("Parameter 'axis' has been deprecated in 0.20 and "                          "will be removed in 0.22. Future (and default) "                          "behavior is equivalent to 'axis=0' (impute along "                          "columns). Row-wise imputation can be performed "                          "with FunctionTransformer.", DeprecationWarning)            self._axis = self.axis        if self._axis not in [0, 1]:             raise ValueError("Can only impute missing values on axis 0 and 1, "                             " got axis={0}".format(self.axis))                             " got axis={0}".format(self._axis))          # Since two different arrays can be provided in fit(X) and         # transform(X), the imputation data will be computed in transform()         # when the imputation is done per sample (i.e., when axis=1).        if self.axis == 0:        if self._axis == 0:             X = check_array(X, accept_sparse='csc', dtype=np.float64,                             force_all_finite=False)


Question: Deprecate Imputer with axis=1 After having tried to deal with a few issues related to extending behaviour, I believe we should be removing the parameter from . It seems a strange feature to support in a machine learning context, except perhaps where the features represent something like a time series. It is not stateful and can be performed with a FunctionTransformer. (We could even provide a function, if we felt it necessary, which would roughly be defined as .) It complicates the implementation, which already has a bunch of weird edge-cases (to handle sparse data with missing indicated by 0 which is an inefficient use of a sparse data structure; and to handle non-NaN missingness indicators), unnecessarily. It is often nonsensical to extend further features to the case. Do others agree? [MRG+1] Deprecate ` argument Deprecated the argument on the class.

self.statistics_ = self._sparse_fit(X,                                                     self.strategy,                                                     self.missing_values,                                                    self.axis)                                                    self._axis)             else:                 self.statistics_ = self._dense_fit(X,                                                    self.strategy,                                                    self.missing_values,                                                   self.axis)                                                   self._axis)          return self


Question: Deprecate Imputer with axis=1 After having tried to deal with a few issues related to extending behaviour, I believe we should be removing the parameter from . It seems a strange feature to support in a machine learning context, except perhaps where the features represent something like a time series. It is not stateful and can be performed with a FunctionTransformer. (We could even provide a function, if we felt it necessary, which would roughly be defined as .) It complicates the implementation, which already has a bunch of weird edge-cases (to handle sparse data with missing indicated by 0 which is an inefficient use of a sparse data structure; and to handle non-NaN missingness indicators), unnecessarily. It is often nonsensical to extend further features to the case. Do others agree? [MRG+1] Deprecate ` argument Deprecated the argument on the class.

X : {array-like, sparse matrix}, shape = [n_samples, n_features]             The input data to complete.         """        if self.axis == 0:        if self._axis == 0:             check_is_fitted(self, 'statistics_')             X = check_array(X, accept_sparse='csc', dtype=FLOAT_DTYPES,                             force_all_finite=False, copy=self.copy)


Question: Deprecate Imputer with axis=1 After having tried to deal with a few issues related to extending behaviour, I believe we should be removing the parameter from . It seems a strange feature to support in a machine learning context, except perhaps where the features represent something like a time series. It is not stateful and can be performed with a FunctionTransformer. (We could even provide a function, if we felt it necessary, which would roughly be defined as .) It complicates the implementation, which already has a bunch of weird edge-cases (to handle sparse data with missing indicated by 0 which is an inefficient use of a sparse data structure; and to handle non-NaN missingness indicators), unnecessarily. It is often nonsensical to extend further features to the case. Do others agree? [MRG+1] Deprecate ` argument Deprecated the argument on the class.

statistics = self._sparse_fit(X,                                               self.strategy,                                               self.missing_values,                                              self.axis)                                              self._axis)              else:                 statistics = self._dense_fit(X,                                              self.strategy,                                              self.missing_values,                                             self.axis)                                             self._axis)          # Delete the invalid rows/columns         invalid_mask = np.isnan(statistics)         valid_mask = np.logical_not(invalid_mask)         valid_statistics = statistics[valid_mask]         valid_statistics_indexes = np.where(valid_mask)[0]        missing = np.arange(X.shape[not self.axis])[invalid_mask]        missing = np.arange(X.shape[not self._axis])[invalid_mask]         if self.axis == 0 and invalid_mask.any():        if self._axis == 0 and invalid_mask.any():             if self.verbose:                 warnings.warn("Deleting features without "                               "observed values: %s" % missing)             X = X[:, valid_statistics_indexes]        elif self.axis == 1 and invalid_mask.any():        elif self._axis == 1 and invalid_mask.any():             raise ValueError("Some rows only contain "                              "missing values: %s" % missing)


Question: Deprecate Imputer with axis=1 After having tried to deal with a few issues related to extending behaviour, I believe we should be removing the parameter from . It seems a strange feature to support in a machine learning context, except perhaps where the features represent something like a time series. It is not stateful and can be performed with a FunctionTransformer. (We could even provide a function, if we felt it necessary, which would roughly be defined as .) It complicates the implementation, which already has a bunch of weird edge-cases (to handle sparse data with missing indicated by 0 which is an inefficient use of a sparse data structure; and to handle non-NaN missingness indicators), unnecessarily. It is often nonsensical to extend further features to the case. Do others agree? [MRG+1] Deprecate ` argument Deprecated the argument on the class.

X = X.toarray()              mask = _get_mask(X, self.missing_values)            n_missing = np.sum(mask, axis=self.axis)            n_missing = np.sum(mask, axis=self._axis)             values = np.repeat(valid_statistics, n_missing)             if self.axis == 0:            if self._axis == 0:                 coordinates = np.where(mask.transpose())[::-1]             else:                 coordinates = mask


Question: Allow nsamples to be a tuple in makeblobs I'd like makeblobs to accept lists or tuples for nsamples to generate imbalanced classes. Could be used here for example: http://scikit-

import numpy as np import matplotlib.pyplot as plt from sklearn import svmfrom sklearn.datasets import make_blobs # we create clusters with 1000 and 100 pointsrng = np.random.RandomState(0)# we create two clusters of random points n_samples_1 = 1000 n_samples_2 = 100X = np.r_[1.5 * rng.randn(n_samples_1, 2),          0.5 * rng.randn(n_samples_2, 2) + [2, 2]]y = [0] * (n_samples_1) + [1] * (n_samples_2)centers = [[0.0, 0.0], [2.0, 2.0]]clusters_std = [1.5, 0.5]X, y = make_blobs(n_samples=[n_samples_1, n_samples_2],                  centers=centers,                  cluster_std=clusters_std,                  random_state=0, shuffle=False)  # fit the model and get the separating hyperplane clf = svm.SVC(kernel='linear', C=1.0)diff --git a/sklearn/datasets/samples_generator.py b/sklearn/datasets/samples_generator.py-- a/sklearn/datasets/samples_generator.py++ b/sklearn/datasets/samples_generator.py


Question: Allow nsamples to be a tuple in makeblobs I'd like makeblobs to accept lists or tuples for nsamples to generate imbalanced classes. Could be used here for example: http://scikit-

import numpy as np from scipy import linalg import scipy.sparse as sp<ins>from collections import Iterable</ins>  from ..preprocessing import MultiLabelBinarizer from ..utils import check_array, check_random_state


Question: Allow nsamples to be a tuple in makeblobs I'd like makeblobs to accept lists or tuples for nsamples to generate imbalanced classes. Could be used here for example: http://scikit-

return X, y  def make_blobs(n_samples=100, n_features=2, centers=3, cluster_std=1.0,def make_blobs(n_samples=100, n_features=2, centers=None, cluster_std=1.0,                center_box=(-10.0, 10.0), shuffle=True, random_state=None):     """Generate isotropic Gaussian blobs for clustering.


Question: Allow nsamples to be a tuple in makeblobs I'd like makeblobs to accept lists or tuples for nsamples to generate imbalanced classes. Could be used here for example: http://scikit-

Parameters     ----------    n_samples : int, optional (default=100)        The total number of points equally divided among clusters.    n_samples : int or array-like, optional (default=100)        If int, it is the the total number of points equally divided among        clusters.        If array-like, each element of the sequence indicates        the number of samples per cluster.      n_features : int, optional (default=2)         The number of features for each sample.      centers : int or array of shape [n_centers, n_features], optional        (default=3)        (default=None)         The number of centers to generate, or the fixed center locations.        If n_samples is an int and centers is None, 3 centers are generated.        If n_samples is array-like, centers must be        either None or an array of length equal to the length of n_samples.      cluster_std : float or sequence of floats, optional (default=1.0)         The standard deviation of the clusters.


Question: Allow nsamples to be a tuple in makeblobs I'd like makeblobs to accept lists or tuples for nsamples to generate imbalanced classes. Could be used here for example: http://scikit-

(10, 2)     >>> y     array([0, 0, 1, 0, 2, 2, 2, 1, 1, 0])<ins>    >>> X, y = make_blobs(n_samples=[3, 3, 4], centers=None, n_features=2,    ...                   random_state=0)    >>> print(X.shape)    (10, 2)    >>> y    array([0, 1, 2, 0, 2, 2, 2, 1, 1, 0])</ins>      See also     --------


Question: Allow nsamples to be a tuple in makeblobs I'd like makeblobs to accept lists or tuples for nsamples to generate imbalanced classes. Could be used here for example: http://scikit-

"""     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


Question: Allow nsamples to be a tuple in makeblobs I'd like makeblobs to accept lists or tuples for nsamples to generate imbalanced classes. Could be used here for example: http://scikit-

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]


Question: ElasticNet overwrites X even with copyX=True The function of an , called with , overwrites X, even when : ElasticNet overwrites X even with copyX=True The function of an , called with , overwrites X, even when : [MRG] FIX ElasticNet overwrites X even with copy_X=True Made changes as suggested by please review and suggest changes

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:


Question: Shape of wrong for linearmodel.Lasso when using <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --Shape of wrong for linearmodel.Lasso when using Example: the second snippet should not raise, but it does. The first snippet is ok. I pasted it as a reference Linux-3.2.0-4-amd64-x8664-with-debian-7.11 ('Python', '2.7.3 (default, Mar 13 2014, 11:03:55) \n[GCC 4.7.2]') ('NumPy', '1.13.3') ('SciPy', '0.19.1') ('Scikit-Learn', '0.18.2') <!-- Thanks for contributing! --[MRG] Shape of wrong for linearmodel.Lasso when using <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: --

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


Question: no error on CountVectorizer(ngramrange=(2, 1)) I think if ngramrange[0] is greater than ngram_range[1] we should throw an error. Not sure what the current behavior is.

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


Question: no error on CountVectorizer(ngramrange=(2, 1)) I think if ngramrange[0] is greater than ngram_range[1] we should throw an error. Not sure what the current behavior is.

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


Question: no error on CountVectorizer(ngramrange=(2, 1)) I think if ngramrange[0] is greater than ngram_range[1] we should throw an error. Not sure what the current behavior is.

"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:


Question: no error on CountVectorizer(ngramrange=(2, 1)) I think if ngramrange[0] is greater than ngram_range[1] we should throw an error. Not sure what the current behavior is.

"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


Question: weighted KDE Not sure this is the correct place, but I would very much appreciate the ability to pass a weight for each sample in kde density estimation. There exits a adapted version of : weighted KDE Not sure this is the correct place, but I would very much appreciate the ability to pass a weight for each sample in kde density estimation. There exits a adapted version of :

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


Question: weighted KDE Not sure this is the correct place, but I would very much appreciate the ability to pass a weight for each sample in kde density estimation. There exits a adapted version of : weighted KDE Not sure this is the correct place, but I would very much appreciate the ability to pass a weight for each sample in kde density estimation. There exits a adapted version of :

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


Question: weighted KDE Not sure this is the correct place, but I would very much appreciate the ability to pass a weight for each sample in kde density estimation. There exits a adapted version of : weighted KDE Not sure this is the correct place, but I would very much appreciate the ability to pass a weight for each sample in kde density estimation. There exits a adapted version of :

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


Question: weighted KDE Not sure this is the correct place, but I would very much appreciate the ability to pass a weight for each sample in kde density estimation. There exits a adapted version of : weighted KDE Not sure this is the correct place, but I would very much appreciate the ability to pass a weight for each sample in kde density estimation. There exits a adapted version of :

# 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,


Question: weighted KDE Not sure this is the correct place, but I would very much appreciate the ability to pass a weight for each sample in kde density estimation. There exits a adapted version of : weighted KDE Not sure this is the correct place, but I would very much appreciate the ability to pass a weight for each sample in kde density estimation. There exits a adapted version of :

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))


Question: fowlkesmallowsscore returns RuntimeWarning when variables get too big <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--sklearn\metrics\cluster\ return tk / (pk qk) if tk != 0. else 0. This line produces RuntimeWarning: overflow encountered in intscalars when (pk qk) is bigger than 2*32, thus bypassing the int32 limit. Any code when pk and qk gets too big. <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --<!-- Example: No error is thrown. Please paste or describe the expected results.--Be able to calculate tk / (pk qk) and return a float. <!-- Please paste or specifically describe the actual output or traceback. --it returns 'nan' instead. I propose to use (tk / pk) * (tk / qk) instead, which gives same result and ensuring not bypassing int32 <!-- Please run the following snippet and paste the output below. import platform; print(platform.platform()) import sys; print("Python", sys.version) import numpy; print("NumPy", numpy.version) import scipy; print("SciPy", scipy.version) import sklearn; print("Scikit-Learn", sklearn.version) --18.1 <!-- Thanks for contributing! --

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):


Question: In Gaussian mixtures, when ninit 1, the lowerbound is not always the max In Gaussian mixtures, when is set to any value greater than 1, the is not the max lower bound across all initializations, but just the lower bound of the last initialization. The bug can be fixed by adding the following line just before in : The test that should have caught this bug is in , but it just does a single test, so it had a 50% chance of missing the issue. It should be updated to try many random states. No error. In Gaussian mixtures, when ninit 1, the lowerbound is not always the max In Gaussian mixtures, when is set to any value greater than 1, the is not the max lower bound across all initializations, but just the lower bound of the last initialization. The bug can be fixed by adding the following line just before in : The test that should have caught this bug is in , but it just does a single test, so it had a 50% chance of missing the issue. It should be updated to try many random states. No error.

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         ----------


Question: In Gaussian mixtures, when ninit 1, the lowerbound is not always the max In Gaussian mixtures, when is set to any value greater than 1, the is not the max lower bound across all initializations, but just the lower bound of the last initialization. The bug can be fixed by adding the following line just before in : The test that should have caught this bug is in , but it just does a single test, so it had a 50% chance of missing the issue. It should be updated to try many random states. No error. In Gaussian mixtures, when ninit 1, the lowerbound is not always the max In Gaussian mixtures, when is set to any value greater than 1, the is not the max lower bound across all initializations, but just the lower bound of the last initialization. The bug can be fixed by adding the following line just before in : The test that should have caught this bug is in , but it just does a single test, so it had a 50% chance of missing the issue. It should be updated to try many random states. No error.

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


Question: In Gaussian mixtures, when ninit 1, the lowerbound is not always the max In Gaussian mixtures, when is set to any value greater than 1, the is not the max lower bound across all initializations, but just the lower bound of the last initialization. The bug can be fixed by adding the following line just before in : The test that should have caught this bug is in , but it just does a single test, so it had a 50% chance of missing the issue. It should be updated to try many random states. No error. In Gaussian mixtures, when ninit 1, the lowerbound is not always the max In Gaussian mixtures, when is set to any value greater than 1, the is not the max lower bound across all initializations, but just the lower bound of the last initialization. The bug can be fixed by adding the following line just before in : The test that should have caught this bug is in , but it just does a single test, so it had a 50% chance of missing the issue. It should be updated to try many random states. No error.

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


Question: In Gaussian mixtures, when ninit 1, the lowerbound is not always the max In Gaussian mixtures, when is set to any value greater than 1, the is not the max lower bound across all initializations, but just the lower bound of the last initialization. The bug can be fixed by adding the following line just before in : The test that should have caught this bug is in , but it just does a single test, so it had a 50% chance of missing the issue. It should be updated to try many random states. No error. In Gaussian mixtures, when ninit 1, the lowerbound is not always the max In Gaussian mixtures, when is set to any value greater than 1, the is not the max lower bound across all initializations, but just the lower bound of the last initialization. The bug can be fixed by adding the following line just before in : The test that should have caught this bug is in , but it just does a single test, so it had a 50% chance of missing the issue. It should be updated to try many random states. No error.

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.


Question: In Gaussian mixtures, when ninit 1, the lowerbound is not always the max In Gaussian mixtures, when is set to any value greater than 1, the is not the max lower bound across all initializations, but just the lower bound of the last initialization. The bug can be fixed by adding the following line just before in : The test that should have caught this bug is in , but it just does a single test, so it had a 50% chance of missing the issue. It should be updated to try many random states. No error. In Gaussian mixtures, when ninit 1, the lowerbound is not always the max In Gaussian mixtures, when is set to any value greater than 1, the is not the max lower bound across all initializations, but just the lower bound of the last initialization. The bug can be fixed by adding the following line just before in : The test that should have caught this bug is in , but it just does a single test, so it had a 50% chance of missing the issue. It should be updated to try many random states. No error.

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     --------


Question: No warning when LogisticRegression does not converge <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--I've run LogisticRegressionCV on the Wisconsin Breast Cancer data, and the output of was 100 for all but 1 of the variables. The default of 100 iterations was probably not sufficient in this case. Should there not be some kind of warning? I have done some tests and ~3000 iterations was probably a better choice for maxiter... <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --<!-- Example: No error is thrown. Please paste or describe the expected results.--Some kind of error to be shown. E.g: "result did not converge, try increasing the maximum number of iterations (maxiter)" <!-- Please run the following snippet and paste the output below. import platform; print(platform.platform()) import sys; print("Python", sys.version) import numpy; print("NumPy", numpy.version) import scipy; print("SciPy", scipy.version) import sklearn; print("Scikit-Learn", sklearn.version) --import platform; print(platform.platform()) Darwin-16.7.0-x8664-i386-64bit import sys; print("Python", sys.version) ('Python', '2.7.14 (default, Oct 5 2017, 02:28:52) \n[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]') import numpy; print("NumPy", numpy.version) ('NumPy', '1.13.3') import scipy; print("SciPy", scipy.version) ('SciPy', '1.0.0') import sklearn; print("Scikit-Learn", sklearn.version) ('Scikit-Learn', '0.19.1') <!-- Thanks for contributing! --

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


Question: No warning when LogisticRegression does not converge <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--I've run LogisticRegressionCV on the Wisconsin Breast Cancer data, and the output of was 100 for all but 1 of the variables. The default of 100 iterations was probably not sufficient in this case. Should there not be some kind of warning? I have done some tests and ~3000 iterations was probably a better choice for maxiter... <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --<!-- Example: No error is thrown. Please paste or describe the expected results.--Some kind of error to be shown. E.g: "result did not converge, try increasing the maximum number of iterations (maxiter)" <!-- Please run the following snippet and paste the output below. import platform; print(platform.platform()) import sys; print("Python", sys.version) import numpy; print("NumPy", numpy.version) import scipy; print("SciPy", scipy.version) import sklearn; print("Scikit-Learn", sklearn.version) --import platform; print(platform.platform()) Darwin-16.7.0-x8664-i386-64bit import sys; print("Python", sys.version) ('Python', '2.7.14 (default, Oct 5 2017, 02:28:52) \n[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]') import numpy; print("NumPy", numpy.version) ('NumPy', '1.13.3') import scipy; print("SciPy", scipy.version) ('SciPy', '1.0.0') import sklearn; print("Scikit-Learn", sklearn.version) ('Scikit-Learn', '0.19.1') <!-- Thanks for contributing! --

# 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)


Question: Setting idf is impossible <!-- Instructions For Filing a Bug: --Rather than a bug i guess that would go as a sort of "enhancement proposition" ? I'm currently trying to persist a by basically saving its parameters in a mongoDB database and then rebuilding it alike. This technique works for but simply blocks for as there is no way to set . Is there any actual architectural reason why setting this attributes raise an error ? if yes, do you have an idea for a workaround ? I obviously want to avoid keeping the matrix on which it has been fitted as it would completely mess up the architecture (i believe that the saving/loading process should be separated from the whole treatment/learning process and trying to keep both would mean having to propagate a dirty return) functioning example on CountVectorizer This might not seem very impressive, but dictionnaries can be stored inside of mongoDB databases, which means that you can basically restore the or at least an identical copy of it by simply storing and the output of . Now the incriminated piece of code I would expect that at least one would work. However, both return an error. In the first case, it seems logical, as there is no idf/idf_ parameter In the second case, i suppose that encapsulation forbids the direct setting I think that being able to reproduce a fitted object (even if it is only for non-classifier objects) without having to recompute it at each launch would benefit a lot of applications. I'm currently developping a RestAPI that has to do heavy computations on data before feeding it to the vectorizer, having to relearn the whole model with each computing is very slow, and means i have to currently wait up to half an hour for modifications that are sometimes about 1 line of code. Windows-10-10.0. ('Python', '2.7.11 (default, Feb 16 2016, 09:58:36) [MSC v.1500 64 bit (AMD64)]') ('NumPy', '1.11.0') ('SciPy', '0.17.1') ('Scikit-Learn', '0.17.1') <!-- Thanks for contributing! --

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     ----------


Question: Setting idf is impossible <!-- Instructions For Filing a Bug: --Rather than a bug i guess that would go as a sort of "enhancement proposition" ? I'm currently trying to persist a by basically saving its parameters in a mongoDB database and then rebuilding it alike. This technique works for but simply blocks for as there is no way to set . Is there any actual architectural reason why setting this attributes raise an error ? if yes, do you have an idea for a workaround ? I obviously want to avoid keeping the matrix on which it has been fitted as it would completely mess up the architecture (i believe that the saving/loading process should be separated from the whole treatment/learning process and trying to keep both would mean having to propagate a dirty return) functioning example on CountVectorizer This might not seem very impressive, but dictionnaries can be stored inside of mongoDB databases, which means that you can basically restore the or at least an identical copy of it by simply storing and the output of . Now the incriminated piece of code I would expect that at least one would work. However, both return an error. In the first case, it seems logical, as there is no idf/idf_ parameter In the second case, i suppose that encapsulation forbids the direct setting I think that being able to reproduce a fitted object (even if it is only for non-classifier objects) without having to recompute it at each launch would benefit a lot of applications. I'm currently developping a RestAPI that has to do heavy computations on data before feeding it to the vectorizer, having to relearn the whole model with each computing is very slow, and means i have to currently wait up to half an hour for modifications that are sometimes about 1 line of code. Windows-10-10.0. ('Python', '2.7.11 (default, Feb 16 2016, 09:58:36) [MSC v.1500 64 bit (AMD64)]') ('NumPy', '1.11.0') ('SciPy', '0.17.1') ('Scikit-Learn', '0.17.1') <!-- Thanks for contributing! --

# 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.


Question: Setting idf is impossible <!-- Instructions For Filing a Bug: --Rather than a bug i guess that would go as a sort of "enhancement proposition" ? I'm currently trying to persist a by basically saving its parameters in a mongoDB database and then rebuilding it alike. This technique works for but simply blocks for as there is no way to set . Is there any actual architectural reason why setting this attributes raise an error ? if yes, do you have an idea for a workaround ? I obviously want to avoid keeping the matrix on which it has been fitted as it would completely mess up the architecture (i believe that the saving/loading process should be separated from the whole treatment/learning process and trying to keep both would mean having to propagate a dirty return) functioning example on CountVectorizer This might not seem very impressive, but dictionnaries can be stored inside of mongoDB databases, which means that you can basically restore the or at least an identical copy of it by simply storing and the output of . Now the incriminated piece of code I would expect that at least one would work. However, both return an error. In the first case, it seems logical, as there is no idf/idf_ parameter In the second case, i suppose that encapsulation forbids the direct setting I think that being able to reproduce a fitted object (even if it is only for non-classifier objects) without having to recompute it at each launch would benefit a lot of applications. I'm currently developping a RestAPI that has to do heavy computations on data before feeding it to the vectorizer, having to relearn the whole model with each computing is very slow, and means i have to currently wait up to half an hour for modifications that are sometimes about 1 line of code. Windows-10-10.0. ('Python', '2.7.11 (default, Feb 16 2016, 09:58:36) [MSC v.1500 64 bit (AMD64)]') ('NumPy', '1.11.0') ('SciPy', '0.17.1') ('Scikit-Learn', '0.17.1') <!-- Thanks for contributing! --

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:


Question: Setting idf is impossible <!-- Instructions For Filing a Bug: --Rather than a bug i guess that would go as a sort of "enhancement proposition" ? I'm currently trying to persist a by basically saving its parameters in a mongoDB database and then rebuilding it alike. This technique works for but simply blocks for as there is no way to set . Is there any actual architectural reason why setting this attributes raise an error ? if yes, do you have an idea for a workaround ? I obviously want to avoid keeping the matrix on which it has been fitted as it would completely mess up the architecture (i believe that the saving/loading process should be separated from the whole treatment/learning process and trying to keep both would mean having to propagate a dirty return) functioning example on CountVectorizer This might not seem very impressive, but dictionnaries can be stored inside of mongoDB databases, which means that you can basically restore the or at least an identical copy of it by simply storing and the output of . Now the incriminated piece of code I would expect that at least one would work. However, both return an error. In the first case, it seems logical, as there is no idf/idf_ parameter In the second case, i suppose that encapsulation forbids the direct setting I think that being able to reproduce a fitted object (even if it is only for non-classifier objects) without having to recompute it at each launch would benefit a lot of applications. I'm currently developping a RestAPI that has to do heavy computations on data before feeding it to the vectorizer, having to relearn the whole model with each computing is very slow, and means i have to currently wait up to half an hour for modifications that are sometimes about 1 line of code. Windows-10-10.0. ('Python', '2.7.11 (default, Feb 16 2016, 09:58:36) [MSC v.1500 64 bit (AMD64)]') ('NumPy', '1.11.0') ('SciPy', '0.17.1') ('Scikit-Learn', '0.17.1') <!-- Thanks for contributing! --

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.


Question: CountVectorizer's getfeaturenames raise not NotFittedError when the vocabulary parameter is provided If you initialize a and try to perform a transformation without training you will get a exception. On the other hand if you provide the at the initialization of the vectorizer you could transform a corpus without a prior training, right? The 's calls method which sets the instance variable. In the same manner I believe that the method should not raise if the vocabulary parameter is provided but the vectorizer has not been trained.

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_),


Question: MultiLabelBinarizer breaks when seeing unseen there be an option to handle this instead? <!-- Instructions For Filing a Bug: --I am not sure if it's intended for MultiLabelBinarizer to fit and transform only seen data or not. However, there are many times that it is not possible/not in our interest to know all of the classes that we're fitting at training time. For convenience, I am wondering if there should be another parameter that allows us to ignore the unseen classes by just setting them to 0? Example: Result: array([[1, 0, 0], [0, 1, 0], [0, 0, 0]]) (the current version 0.19.0 would say ) I can open a PR for this if this is a desired behavior. Others also have similar issue:

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


Question: MultiLabelBinarizer breaks when seeing unseen there be an option to handle this instead? <!-- Instructions For Filing a Bug: --I am not sure if it's intended for MultiLabelBinarizer to fit and transform only seen data or not. However, there are many times that it is not possible/not in our interest to know all of the classes that we're fitting at training time. For convenience, I am wondering if there should be another parameter that allows us to ignore the unseen classes by just setting them to 0? Example: Result: array([[1, 0, 0], [0, 1, 0], [0, 0, 0]]) (the current version 0.19.0 would say ) I can open a PR for this if this is a desired behavior. Others also have similar issue:

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


Question: MultiLabelBinarizer breaks when seeing unseen there be an option to handle this instead? <!-- Instructions For Filing a Bug: --I am not sure if it's intended for MultiLabelBinarizer to fit and transform only seen data or not. However, there are many times that it is not possible/not in our interest to know all of the classes that we're fitting at training time. For convenience, I am wondering if there should be another parameter that allows us to ignore the unseen classes by just setting them to 0? Example: Result: array([[1, 0, 0], [0, 1, 0], [0, 0, 0]]) (the current version 0.19.0 would say ) I can open a PR for this if this is a desired behavior. Others also have similar issue:

"""         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),


Question: warnondtype with DataFrame No warning is thrown Linux-4.4.0-116-generic-x8664-with-debian-stretch-sid Python 3.6.3 (default, Nov 3 2017, 19:19:16) [GCC 7.2.0] NumPy 1.13.1 SciPy 0.19.1 Scikit-Learn 0.20.dev0 Pandas 0.21.0 warnondtype with DataFrame No warning is thrown Linux-4.4.0-116-generic-x8664-with-debian-stretch-sid Python 3.6.3 (default, Nov 3 2017, 19:19:16) [GCC 7.2.0] NumPy 1.13.1 SciPy 0.19.1 Scikit-Learn 0.20.dev0 Pandas 0.21.0

# 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.


Question: warnondtype with DataFrame No warning is thrown Linux-4.4.0-116-generic-x8664-with-debian-stretch-sid Python 3.6.3 (default, Nov 3 2017, 19:19:16) [GCC 7.2.0] NumPy 1.13.1 SciPy 0.19.1 Scikit-Learn 0.20.dev0 Pandas 0.21.0 warnondtype with DataFrame No warning is thrown Linux-4.4.0-116-generic-x8664-with-debian-stretch-sid Python 3.6.3 (default, Nov 3 2017, 19:19:16) [GCC 7.2.0] NumPy 1.13.1 SciPy 0.19.1 Scikit-Learn 0.20.dev0 Pandas 0.21.0

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


Question: [RandomizedSearchCV] Do not enforce that niter is less than or equal to size of search space Instantiating with greater than the size of (i.e. the product of the length of each distribution/array in the grid) will fail with an exception at . This is a bit annoying for me because I have an app where I'm letting the user specify the number of iterations to run from the command line, also I've been fiddling around with the param grid so keeps changing. I don't want to have to work out the exact grid size when it goes below, say, 50; if I specify that should be interpreted as an upper bound on the number of iterations. Would it be possible to add an option (off by default) to the constructor specifying whether to throw in such cases? e.g. By passing (the option would default to )

# 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]


Question: Warm start bug when fitting a LogisticRegression model on binary outcomes with . <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --Bug when fitting a LogisticRegression model on binary outcomes with multiclass='multinomial' when using warm start. Note that it is similar to the issue here i.e. only using a 1D object on binary outcomes even when using as opposed to a 2D object. <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --from sklearn.linearmodel import LogisticRegression import sklearn.metrics import numpy as np # Set up a logistic regression object lr = LogisticRegression(C=, multiclass='multinomial', solver='sag', tol=0.0001, warmstart=True, verbose=0) # Set independent variable values Z = ([ [ 0. , 0. ], [ 1., 0. ], [ 1., -0.], [-0., -0.], [ 1., 1.], [-0., -1.], [-1., -0.], [ 2. , -0.], [-0., -1.], [ 2., -0.], [-1., 2.], [-1., 2. ], [ 2., -1.], [ 0., -0.], [ 1., 0.], [ 1., -0.], [ 0., 1.], [-0., -0.], [-1., -0.], [-1. , 0.]]) # Set dependant variable values Y = ([1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1], dtype=np.int32) # First fit model normally (Z, Y) p = lr.predictproba(Z) print(sklearn.metrics.logloss(Y, p)) # ... print(lr.intercept) print() # Now fit model after a warm start (Z, Y) p = lr.predictproba(Z) print(sklearn.metrics.logloss(Y, p)) # ... print(lr.intercept) print() The predictions should be the same as the model converged the first time it was run. The predictions are different. In fact the more times you re-run the fit the worse it gets. This is actually the only reason I was able to catch the bug. It is caused by the line here w0[:, [1]] = coef As is , but is , this causes the value to be broadcast into the . This some sort of singularity issue when training resulting in worse performance. Note that had it not done exactly this i.e. was simply initialised by some random values, this bug would be very hard to catch because of course each time the model would converge just not as fast as one would hope when warm starting. The fix I believe is very easy, just need to swap the previous line to if nclasses == 1: w0[0, [1]] = -coef # Be careful to get these the right way around w0[1, [1]] = coef else: w0[:, [1]] = coef <!-- Please run the following snippet and paste the output below. import platform; print(platform.platform()) import sys; print("Python", sys.version) import numpy; print("NumPy", numpy.version) import scipy; print("SciPy", scipy.version) import sklearn; print("Scikit-Learn", sklearn.version) --Linux-4.13.0-37-generic-x86_64-with-Ubuntu-16.04-xenial Python 3.5.2 (default, Nov 23 2017, 16:37:01) NumPy 1.14.2 SciPy 1.0.0 Scikit-Learn 0.20.dev0 (built from latest master) <!-- Thanks for contributing! --

'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.


Question: Missing parameter validation in Neighbors estimator for float n_neighbors This should be caught earlier and a more helpful error message should be raised (or we could be lenient and cast to integer, but I think a better error might be better). We need to make sure that also works.

"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


Question: Missing parameter validation in Neighbors estimator for float n_neighbors This should be caught earlier and a more helpful error message should be raised (or we could be lenient and cast to integer, but I think a better error might be better). We need to make sure that also works.

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


Question: OneHotEncoder does not output scipy sparse matrix of given dtype OneHotEncoder ignores the specified dtype in the construction of the sparse array when mixed input data are passed, i.e with both categorical and real data type Platform: Linux-4.13.0-38-generic-x86_64-with-debian-stretch-sid Python: 3.6.3 (default, Oct 13 2017, 12:02:49) [GCC 7.2.0] NumPy: NumPy SciPy: SciPy 1.0.1 Scikit-Learn: Scikit-Learn 0.19.1

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


Question: OneHotEncoder does not output scipy sparse matrix of given dtype OneHotEncoder ignores the specified dtype in the construction of the sparse array when mixed input data are passed, i.e with both categorical and real data type Platform: Linux-4.13.0-38-generic-x86_64-with-debian-stretch-sid Python: 3.6.3 (default, Oct 13 2017, 12:02:49) [GCC 7.2.0] NumPy: NumPy SciPy: SciPy 1.0.1 Scikit-Learn: Scikit-Learn 0.19.1

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.


Question: OneHotEncoder does not output scipy sparse matrix of given dtype OneHotEncoder ignores the specified dtype in the construction of the sparse array when mixed input data are passed, i.e with both categorical and real data type Platform: Linux-4.13.0-38-generic-x86_64-with-debian-stretch-sid Python: 3.6.3 (default, Oct 13 2017, 12:02:49) [GCC 7.2.0] NumPy: NumPy SciPy: SciPy 1.0.1 Scikit-Learn: Scikit-Learn 0.19.1

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))


Question: OneHotEncoder does not output scipy sparse matrix of given dtype OneHotEncoder ignores the specified dtype in the construction of the sparse array when mixed input data are passed, i.e with both categorical and real data type Platform: Linux-4.13.0-38-generic-x86_64-with-debian-stretch-sid Python: 3.6.3 (default, Oct 13 2017, 12:02:49) [GCC 7.2.0] NumPy: NumPy SciPy: SciPy 1.0.1 Scikit-Learn: Scikit-Learn 0.19.1

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):


Question: OneHotEncoder does not output scipy sparse matrix of given dtype OneHotEncoder ignores the specified dtype in the construction of the sparse array when mixed input data are passed, i.e with both categorical and real data type Platform: Linux-4.13.0-38-generic-x86_64-with-debian-stretch-sid Python: 3.6.3 (default, Oct 13 2017, 12:02:49) [GCC 7.2.0] NumPy: NumPy SciPy: SciPy 1.0.1 Scikit-Learn: Scikit-Learn 0.19.1

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)


Question: FunctionTransformer should not convert DataFrames to arrays by default I would expect a common use of FunctionTransformer is to apply some function to a Pandas DataFrame, ideally using its own methods or accessors. As noted in , it can be easy for users to miss that they need to set validate=False to pass through a DataFrame without converting it to a NumPy array. I think it would be more user-friendly to have by default, which would pass through DataFrames to the function, but otherwise convert its input to a 2d array. For strict backwards compatibility, the default should be changed through a deprecation cycle, warning whenever using the default validation means a DataFrame is currently converted to an array. Do others agree?

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


Question: FunctionTransformer should not convert DataFrames to arrays by default I would expect a common use of FunctionTransformer is to apply some function to a Pandas DataFrame, ideally using its own methods or accessors. As noted in , it can be easy for users to miss that they need to set validate=False to pass through a DataFrame without converting it to a NumPy array. I think it would be more user-friendly to have by default, which would pass through DataFrames to the function, but otherwise convert its input to a 2d array. For strict backwards compatibility, the default should be changed through a deprecation cycle, warning whenever using the default validation means a DataFrame is currently converted to an array. Do others agree?

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


Question: FunctionTransformer should not convert DataFrames to arrays by default I would expect a common use of FunctionTransformer is to apply some function to a Pandas DataFrame, ideally using its own methods or accessors. As noted in , it can be easy for users to miss that they need to set validate=False to pass through a DataFrame without converting it to a NumPy array. I think it would be more user-friendly to have by default, which would pass through DataFrames to the function, but otherwise convert its input to a 2d array. For strict backwards compatibility, the default should be changed through a deprecation cycle, warning whenever using the default validation means a DataFrame is currently converted to an array. Do others agree?

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))


Question: FunctionTransformer should not convert DataFrames to arrays by default I would expect a common use of FunctionTransformer is to apply some function to a Pandas DataFrame, ideally using its own methods or accessors. As noted in , it can be easy for users to miss that they need to set validate=False to pass through a DataFrame without converting it to a NumPy array. I think it would be more user-friendly to have by default, which would pass through DataFrames to the function, but otherwise convert its input to a 2d array. For strict backwards compatibility, the default should be changed through a deprecation cycle, warning whenever using the default validation means a DataFrame is currently converted to an array. Do others agree?

-------         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)


Question: FunctionTransformer should not convert DataFrames to arrays by default I would expect a common use of FunctionTransformer is to apply some function to a Pandas DataFrame, ideally using its own methods or accessors. As noted in , it can be easy for users to miss that they need to set validate=False to pass through a DataFrame without converting it to a NumPy array. I think it would be more user-friendly to have by default, which would pass through DataFrames to the function, but otherwise convert its input to a 2d array. For strict backwards compatibility, the default should be changed through a deprecation cycle, warning whenever using the default validation means a DataFrame is currently converted to an array. Do others agree?

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


Question: catch more warnings in common tests Right now the output of travis is too large to render, partially because a lot of deprecation warnings and partially because of warnings from the common tests. The common tests should catch all the deprecation warnings and probably also convergence warnings or numerical warnings (we decrease the number of iterations for faster testing).

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):


Question: catch more warnings in common tests Right now the output of travis is too large to render, partially because a lot of deprecation warnings and partially because of warnings from the common tests. The common tests should catch all the deprecation warnings and probably also convergence warnings or numerical warnings (we decrease the number of iterations for faster testing).

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


Question: catch more warnings in common tests Right now the output of travis is too large to render, partially because a lot of deprecation warnings and partially because of warnings from the common tests. The common tests should catch all the deprecation warnings and probably also convergence warnings or numerical warnings (we decrease the number of iterations for faster testing).

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.


Question: catch more warnings in common tests Right now the output of travis is too large to render, partially because a lot of deprecation warnings and partially because of warnings from the common tests. The common tests should catch all the deprecation warnings and probably also convergence warnings or numerical warnings (we decrease the number of iterations for faster testing).

"""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)


Question: catch more warnings in common tests Right now the output of travis is too large to render, partially because a lot of deprecation warnings and partially because of warnings from the common tests. The common tests should catch all the deprecation warnings and probably also convergence warnings or numerical warnings (we decrease the number of iterations for faster testing).

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:


Question: catch more warnings in common tests Right now the output of travis is too large to render, partially because a lot of deprecation warnings and partially because of warnings from the common tests. The common tests should catch all the deprecation warnings and probably also convergence warnings or numerical warnings (we decrease the number of iterations for faster testing).

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


Question: catch more warnings in common tests Right now the output of travis is too large to render, partially because a lot of deprecation warnings and partially because of warnings from the common tests. The common tests should catch all the deprecation warnings and probably also convergence warnings or numerical warnings (we decrease the number of iterations for faster testing).

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:


Question: output options? Is it possible to add output options to http://scikit- It would be really useful to have a output or output. Right now it outputs as a string that must be printed but it's difficult to use the results. I can make a quick helper script if that could be useful? [MRG] Classification report Dict-of-Dicts output <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: --<!-- Example: -- This PR adds an option of returning the classification report in the form of a Dictionary of Dictionaries. Will add tests for the code, if the code is approved. <!-- Please be aware that we are a loose team of volunteers so patience is necessary; assistance handling other issues is very welcome. We value all user contributions, no matter how minor they are. If we are slow to review, either the pull request needs some benchmarking, tinkering, convincing, etc. or more likely the reviewers are simply busy. In either case, we ask for your understanding during the review process. For more information, see our FAQ on this topic: http://scikit- Thanks for contributing! --

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>`.


Question: output options? Is it possible to add output options to http://scikit- It would be really useful to have a output or output. Right now it outputs as a string that must be printed but it's difficult to use the results. I can make a quick helper script if that could be useful? [MRG] Classification report Dict-of-Dicts output <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: --<!-- Example: -- This PR adds an option of returning the classification report in the form of a Dictionary of Dictionaries. Will add tests for the code, if the code is approved. <!-- Please be aware that we are a loose team of volunteers so patience is necessary; assistance handling other issues is very welcome. We value all user contributions, no matter how minor they are. If we are slow to review, either the pull request needs some benchmarking, tinkering, convincing, etc. or more likely the reviewers are simply busy. In either case, we ask for your understanding during the review process. For more information, see our FAQ on this topic: http://scikit- Thanks for contributing! --

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


Question: output options? Is it possible to add output options to http://scikit- It would be really useful to have a output or output. Right now it outputs as a string that must be printed but it's difficult to use the results. I can make a quick helper script if that could be useful? [MRG] Classification report Dict-of-Dicts output <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: --<!-- Example: -- This PR adds an option of returning the classification report in the form of a Dictionary of Dictionaries. Will add tests for the code, if the code is approved. <!-- Please be aware that we are a loose team of volunteers so patience is necessary; assistance handling other issues is very welcome. We value all user contributions, no matter how minor they are. If we are slow to review, either the pull request needs some benchmarking, tinkering, convincing, etc. or more likely the reviewers are simply busy. In either case, we ask for your understanding during the review process. For more information, see our FAQ on this topic: http://scikit- Thanks for contributing! --

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


Question: Consistency issue in StandardScaler There is an issue of consistency with with and between the sparse and dense case. it make sense to support this case. It will return the identity matrix which is not the use case for the . If we wish a transformer to do so, one should use the I assume. we consider this behaviour normal, we need to: In the dense case, force to be after each iteration of . In the sparse case, compute the non-NaNs values and update which is not computed. It leads currently to an error if calling twice (i.e. will fail). IMO, we should make a checking at raise an error. WDYT?

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_'):


Question: Consistency issue in StandardScaler There is an issue of consistency with with and between the sparse and dense case. it make sense to support this case. It will return the identity matrix which is not the use case for the . If we wish a transformer to do so, one should use the I assume. we consider this behaviour normal, we need to: In the dense case, force to be after each iteration of . In the sparse case, compute the non-NaNs values and update which is not computed. It leads currently to an error if calling twice (i.e. will fail). IMO, we should make a checking at raise an error. WDYT?

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_))


Question: minmaxscale does not ignore NaNs The class ignore NaNs. Its counterpart function does not. The needs to add the option . implement the tests and this fix. However, it should be done in another proper PR.

# 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:


Question: randomizedsvd is slow for dokmatrix and lilmatrix (and its object-oriented interface, ) is extremely slow for certain types of sparse matrix. Either all sparse matrices should be processed in roughly the same amount of time, or a warning should be printed. silently takes up to 50x longer than necessary. Windows-10-10.0.-SP0 Python 3.6.0 (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] NumPy 1.14.4 SciPy 1.1.0 Scikit-Learn 0.19.1 Also tested on: Linux-4.16.11-1-ARCH-x8664-with-arch-Arch-Linux Python 3.6.5 (default, May 11 2018, 04:00:52) [GCC 8.1.0] NumPy 1.14.5 SciPy 1.1.0 Scikit-Learn 0.19.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


Question: randomizedsvd is slow for dokmatrix and lilmatrix (and its object-oriented interface, ) is extremely slow for certain types of sparse matrix. Either all sparse matrices should be processed in roughly the same amount of time, or a warning should be printed. silently takes up to 50x longer than necessary. Windows-10-10.0.-SP0 Python 3.6.0 (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] NumPy 1.14.4 SciPy 1.1.0 Scikit-Learn 0.19.1 Also tested on: Linux-4.16.11-1-ARCH-x8664-with-arch-Arch-Linux Python 3.6.5 (default, May 11 2018, 04:00:52) [GCC 8.1.0] NumPy 1.14.5 SciPy 1.1.0 Scikit-Learn 0.19.1

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)


Question: randomizedsvd is slow for dokmatrix and lilmatrix (and its object-oriented interface, ) is extremely slow for certain types of sparse matrix. Either all sparse matrices should be processed in roughly the same amount of time, or a warning should be printed. silently takes up to 50x longer than necessary. Windows-10-10.0.-SP0 Python 3.6.0 (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] NumPy 1.14.4 SciPy 1.1.0 Scikit-Learn 0.19.1 Also tested on: Linux-4.16.11-1-ARCH-x8664-with-arch-Arch-Linux Python 3.6.5 (default, May 11 2018, 04:00:52) [GCC 8.1.0] NumPy 1.14.5 SciPy 1.1.0 Scikit-Learn 0.19.1

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()


Question: randomizedsvd is slow for dokmatrix and lilmatrix (and its object-oriented interface, ) is extremely slow for certain types of sparse matrix. Either all sparse matrices should be processed in roughly the same amount of time, or a warning should be printed. silently takes up to 50x longer than necessary. Windows-10-10.0.-SP0 Python 3.6.0 (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] NumPy 1.14.4 SciPy 1.1.0 Scikit-Learn 0.19.1 Also tested on: Linux-4.16.11-1-ARCH-x8664-with-arch-Arch-Linux Python 3.6.5 (default, May 11 2018, 04:00:52) [GCC 8.1.0] NumPy 1.14.5 SciPy 1.1.0 Scikit-Learn 0.19.1

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


Question: randomizedsvd is slow for dokmatrix and lilmatrix (and its object-oriented interface, ) is extremely slow for certain types of sparse matrix. Either all sparse matrices should be processed in roughly the same amount of time, or a warning should be printed. silently takes up to 50x longer than necessary. Windows-10-10.0.-SP0 Python 3.6.0 (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] NumPy 1.14.4 SciPy 1.1.0 Scikit-Learn 0.19.1 Also tested on: Linux-4.16.11-1-ARCH-x8664-with-arch-Arch-Linux Python 3.6.5 (default, May 11 2018, 04:00:52) [GCC 8.1.0] NumPy 1.14.5 SciPy 1.1.0 Scikit-Learn 0.19.1

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()


Question: randomizedsvd is slow for dokmatrix and lilmatrix (and its object-oriented interface, ) is extremely slow for certain types of sparse matrix. Either all sparse matrices should be processed in roughly the same amount of time, or a warning should be printed. silently takes up to 50x longer than necessary. Windows-10-10.0.-SP0 Python 3.6.0 (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] NumPy 1.14.4 SciPy 1.1.0 Scikit-Learn 0.19.1 Also tested on: Linux-4.16.11-1-ARCH-x8664-with-arch-Arch-Linux Python 3.6.5 (default, May 11 2018, 04:00:52) [GCC 8.1.0] NumPy 1.14.5 SciPy 1.1.0 Scikit-Learn 0.19.1

"""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"


Question: Should mixture models have a clusterer-compatible interface Mixture models are currently a bit different. They are basically clusterers, except they are probabilistic, and are applied to inductive problems unlike many clusterers. But they are unlike clusterers in API: they have an parameter, with identical purpose to they do not store the of the training data they do not have a method And they are almost entirely documented separately. Should we make the MMs more like clusterers?

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


Question: Should mixture models have a clusterer-compatible interface Mixture models are currently a bit different. They are basically clusterers, except they are probabilistic, and are applied to inductive problems unlike many clusterers. But they are unlike clusterers in API: they have an parameter, with identical purpose to they do not store the of the training data they do not have a method And they are almost entirely documented separately. Should we make the MMs more like clusterers?

-------         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)


Question: Should mixture models have a clusterer-compatible interface Mixture models are currently a bit different. They are basically clusterers, except they are probabilistic, and are applied to inductive problems unlike many clusterers. But they are unlike clusterers in API: they have an parameter, with identical purpose to they do not store the of the training data they do not have a method And they are almost entirely documented separately. Should we make the MMs more like clusterers?

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.


Question: Retrieving time to refit the estimator in BaseSearchCV Basically, I'm trying to figure out how much time it takes to refit the best model on the full data after doing grid/random search. What I can so far do is retrieve the time it takes to fit and score each model: In case I run this on a single core, I could time the whole search procedure and subtract the time it took to fit the single folds during hyperparameter optimization. Nevertheless, this isn't possible any more when setting . Thus, it would be great to have an attribute which is simply the time it took to refit the best model. Usecase: for we want to support uploading the results of hyperparameter optimization, including the time it takes to do the hyperparameter optimization.

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


Question: Retrieving time to refit the estimator in BaseSearchCV Basically, I'm trying to figure out how much time it takes to refit the best model on the full data after doing grid/random search. What I can so far do is retrieve the time it takes to fit and score each model: In case I run this on a single core, I could time the whole search procedure and subtract the time it took to fit the single folds during hyperparameter optimization. Nevertheless, this isn't possible any more when setting . Thus, it would be great to have an attribute which is simply the time it took to refit the best model. Usecase: for we want to support uploading the results of hyperparameter optimization, including the time it takes to do the hyperparameter optimization.

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']


Question: Retrieving time to refit the estimator in BaseSearchCV Basically, I'm trying to figure out how much time it takes to refit the best model on the full data after doing grid/random search. What I can so far do is retrieve the time it takes to fit and score each model: In case I run this on a single core, I could time the whole search procedure and subtract the time it took to fit the single folds during hyperparameter optimization. Nevertheless, this isn't possible any more when setting . Thus, it would be great to have an attribute which is simply the time it took to refit the best model. Usecase: for we want to support uploading the results of hyperparameter optimization, including the time it takes to do the hyperparameter optimization.

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