Question: import array from collections import defaultdict from collections.abc import Mapping<ins>from functools import partial</ins> import numbers from operator import itemgetter import re

Pickling Tokenizers fails due to use of lambdas Cannot pickle a using the builtin python module, likely due to the use of lambdas in Example: Program runs without error Traceback: Instead of the builtin , use , which can capture the expression. <!-- Please run the following snippet and paste the output below. For scikit-learn = 0.20: import sklearn; sklearn.showversions() For scikit-learn < 0.20: 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) --Version information: I think this is similar to issues: (looking at the stackoverflow thread at , it suggests using which also seems to work for the toy example) Naively, I would make one of the two changes below, but I am not familiar with the scikit-learn codebase, so they might not be appropriate: the FAQ to direct people to other serialization libraries (perhaps I missed this recommendation?), e.g. at or the use of the lambdas in the vectorizer and replace them with locally def'd functions. I suspect that this solution is flawed because it doesn't account for other uses of lambdas elsewhere in the codebase, and the only complete solution would be to stop using lambdas, but these are a useful language feature.


Question: 'strip_tags']  <ins>def _preprocess(doc, accent_function=None, lower=False):    """Chain together an optional series of text preprocessing steps to    apply to a document.    Parameters    ----------    doc: str        The string to preprocess    accent_function: callable        Function for handling accented characters. Common strategies include        normalizing and removing.    lower: bool        Whether to use str.lower to lowercase all fo the text    Returns    -------    doc: str        preprocessed string    """    if lower:        doc = doc.lower()    if accent_function is not None:        doc = accent_function(doc)    return docdef _analyze(doc, analyzer=None, tokenizer=None, ngrams=None,             preprocessor=None, decoder=None, stop_words=None):    """Chain together an optional series of text processing steps to go from    a single document to ngrams, with or without tokenizing or preprocessing.    If analyzer is used, only the decoder argument is used, as the analyzer is    intended to replace the preprocessor, tokenizer, and ngrams steps.    Parameters    ----------    analyzer: callable    tokenizer: callable    ngrams: callable    preprocessor: callable    decoder: callable    stop_words: list    Returns    -------    ngrams: list        A sequence of tokens, possibly with pairs, triples, etc.    """    if decoder is not None:        doc = decoder(doc)    if analyzer is not None:        doc = analyzer(doc)    else:        if preprocessor is not None:            doc = preprocessor(doc)        if tokenizer is not None:            doc = tokenizer(doc)        if ngrams is not None:            if stop_words is not None:                doc = ngrams(doc, stop_words)            else:                doc = ngrams(doc)    return doc</ins> def strip_accents_unicode(s):     """Transform accentuated unicode symbols into their simple counterpart


Question: if self.preprocessor is not None:             return self.preprocessor         # unfortunately python functools package does not have an efficient        # `compose` function that would have allowed us to chain a dynamic        # number of functions. However the cost of a lambda call is a few        # hundreds of nanoseconds which is negligible when compared to the        # cost of tokenizing a string of 1000 chars for instance.        noop = lambda x: x         # accent stripping         if not self.strip_accents:            strip_accents = noop            strip_accents = None         elif callable(self.strip_accents):             strip_accents = self.strip_accents         elif self.strip_accents == 'ascii':


Question: raise ValueError('Invalid value for "strip_accents": %s' %                              self.strip_accents)         if self.lowercase:            return lambda x: strip_accents(x.lower())        else:            return strip_accents        return partial(            _preprocess, accent_function=strip_accents, lower=self.lowercase        )      def build_tokenizer(self):         """Return a function that splits a string into a sequence of tokens"""         if self.tokenizer is not None:             return self.tokenizer         token_pattern = re.compile(self.token_pattern)        return lambda doc: token_pattern.findall(doc)        return token_pattern.findall      def get_stop_words(self):         """Build or fetch the effective stop words list"""


Question: if callable(self.analyzer):             if self.input in ['file', 'filename']:                 self._validate_custom_analyzer()            return lambda doc: self.analyzer(self.decode(doc))            return partial(                _analyze, analyzer=self.analyzer, decoder=self.decode            )          preprocess = self.build_preprocessor()          if self.analyzer == 'char':            return lambda doc: self._char_ngrams(preprocess(self.decode(doc)))            return partial(_analyze, ngrams=self._char_ngrams,                           preprocessor=preprocess, decoder=self.decode)          elif self.analyzer == 'char_wb':            return lambda doc: self._char_wb_ngrams(                preprocess(self.decode(doc)))            return partial(_analyze, ngrams=self._char_wb_ngrams,                           preprocessor=preprocess, decoder=self.decode)          elif self.analyzer == 'word':             stop_words = self.get_stop_words()             tokenize = self.build_tokenizer()             self._check_stop_words_consistency(stop_words, preprocess,                                                tokenize)            return lambda doc: self._word_ngrams(                tokenize(preprocess(self.decode(doc))), stop_words)            return partial(_analyze, ngrams=self._word_ngrams,                           tokenizer=tokenize, preprocessor=preprocess,                           decoder=self.decode, stop_words=stop_words)          else:             raise ValueError('%s is not a valid tokenization scheme/analyzer' %


Question: similar to the Power method for determining the eigenvectors and     eigenvalues of a X'Y.     """    y_score = Y[:, [0]]    for col in Y.T:        if np.any(np.abs(col) > np.finfo(np.double).eps):            y_score = col.reshape(len(col), 1)            break     x_weights_old = 0     ite = 1     X_pinv = Y_pinv = None

PLS reports "array must not contain nan" if a feature is constant Originally reported at by Reproduce with: The obscure error message is due to the presence of a column containing only 0.


Question: seed=seed)         intercept_decay = SPARSE_INTERCEPT_DECAY     else:        X = np.ascontiguousarray(X)         dataset = ArrayData(X, y, sample_weight, seed=seed)         intercept_decay = 1.0 diff --git a/sklearn/linear_model/ridge.py b/sklearn/linear_model/ridge.py-- a/sklearn/linear_model/ridge.py++ b/sklearn/linear_model/ridge.py

Need for conversion with SAG Running the following code snippet will lead to an error: I am wondering if we are not to strict here, and we should include a since that will expect a C-contiguous numpy array.


Question: _accept_sparse = _get_valid_accept_sparse(sparse.issparse(X), solver)         X = check_array(X, accept_sparse=_accept_sparse, dtype=_dtype,                         order="C")        y = check_array(y, dtype=X.dtype, ensure_2d=False, order="C")        y = check_array(y, dtype=X.dtype, ensure_2d=False, order=None)     check_consistent_length(X, y)      n_samples, n_features = X.shape


Question: """         out = dict()         for key in self._get_param_names():            value = getattr(self, key, None)            try:                value = getattr(self, key)            except AttributeError:                warnings.warn('From version 0.24, get_params will raise an '                              'AttributeError if a parameter cannot be '                              'retrieved as an instance attribute. Previously '                              'it would return None.',                              FutureWarning)                value = None             if deep and hasattr(value, 'get_params'):                 deep_items = value.get_params().items()                 out.update((key + '__' + k, val) for k, val in deep_items)diff --git a/sklearn/gaussian_process/kernels.py b/sklearn/gaussian_process/kernels.py-- a/sklearn/gaussian_process/kernels.py++ b/sklearn/gaussian_process/kernels.py

Cloning custom transform replaces values in init dictionary <!-- 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--Let us say we have a custom transform that has some arguments. When the is instantiated, these arguments are set in the init. When we clone (as happens in , for example), the arguments get copied successfully. However, if the arguments are sent to a structure such as a dictionary, the clone replaces them with None. In cases where None does not cause errors, this creates a silent error, as the cloned version of will run, producing different results from its original version (which is how I ran into this problem in the first place). Fully replicable example follows. <!-- Thanks for contributing! --


Question: from collections import namedtuple import math from inspect import signature<ins>import warnings</ins>  import numpy as np from scipy.special import kv, gamma


Question: " %s doesn't follow this convention."                                % (cls, ))         for arg in args:            params[arg] = getattr(self, arg, None)            try:                value = getattr(self, arg)            except AttributeError:                warnings.warn('From version 0.24, get_params will raise an '                              'AttributeError if a parameter cannot be '                              'retrieved as an instance attribute. Previously '                              'it would return None.',                              FutureWarning)                value = None            params[arg] = value         return params      def set_params(self, **params):diff --git a/sklearn/pipeline.py b/sklearn/pipeline.py-- a/sklearn/pipeline.py++ b/sklearn/pipeline.py


Question: def __init__(self, steps, memory=None, verbose=False):         self.steps = steps        self._validate_steps()         self.memory = memory         self.verbose = verbose        self._validate_steps()      def get_params(self, deep=True):         """Get parameters for this estimator.


Question: Parameters     ----------    min_samples : int > 1 or float between 0 and 1 (default=None)    min_samples : int > 1 or float between 0 and 1 (default=5)         The number of samples in a neighborhood for a point to be considered as         a core point. Also, up and down steep regions can't have more then         ``min_samples`` consecutive non-steep points. Expressed as an absolute

[BUG] Optics float minsamples NN instantiation None yet. When passing minsamples as a float to optics l439 & 440 execute to bring it into integer ranges, but don't convert to int: When instantiating the NearestNeighbours class with a float it raises due to the float (l448). Error message: Fix: the int(...) is for backwards compatibbility to Python 2 where with T Number, while Python3 <!-- 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! --


Question: A feature array, or array of distances between samples if         metric='precomputed'     min_samples : int (default=5)    min_samples : int > 1 or float between 0 and 1         The number of samples in a neighborhood for a point to be considered         as a core point. Expressed as an absolute number or a fraction of the         number of samples (rounded to be at least 2).


Question: n_samples = X.shape[0]     _validate_size(min_samples, n_samples, 'min_samples')     if min_samples <= 1:        min_samples = max(2, min_samples * n_samples)        min_samples = max(2, int(min_samples * n_samples))      # Start all points as 'unprocessed' ##     reachability_ = np.empty(n_samples)


Question: ordering : array, shape (n_samples,)         OPTICS ordered point indices (`ordering_`)     min_samples : int > 1 or float between 0 and 1 (default=None)    min_samples : int > 1 or float between 0 and 1         The same as the min_samples given to OPTICS. Up and down steep regions         can't have more then ``min_samples`` consecutive non-steep points.         Expressed as an absolute number or a fraction of the number of samples


Question: n_samples = len(reachability)     _validate_size(min_samples, n_samples, 'min_samples')     if min_samples <= 1:        min_samples = max(2, min_samples * n_samples)        min_samples = max(2, int(min_samples * n_samples))     if min_cluster_size is None:         min_cluster_size = min_samples     _validate_size(min_cluster_size, n_samples, 'min_cluster_size')     if min_cluster_size <= 1:        min_cluster_size = max(2, min_cluster_size * n_samples)        min_cluster_size = max(2, int(min_cluster_size * n_samples))      clusters = _xi_cluster(reachability[ordering], predecessor[ordering],                            ordering, xi,


Question: reachability plot is defined by the ratio from one point to its         successor being at most 1-xi.     min_samples : int > 1 or float between 0 and 1 (default=None)    min_samples : int > 1         The same as the min_samples given to OPTICS. Up and down steep regions         can't have more then ``min_samples`` consecutive non-steep points.        Expressed as an absolute number or a fraction of the number of samples        (rounded to be at least 2).     min_cluster_size : int > 1 or float between 0 and 1        Minimum number of samples in an OPTICS cluster, expressed as an        absolute number or a fraction of the number of samples (rounded        to be at least 2).    min_cluster_size : int > 1        Minimum number of samples in an OPTICS cluster.      predecessor_correction : bool         Correct clusters based on the calculated predecessors.


Question: # we set copy to False         return self._tfidf.transform(X, copy=False)     def transform(self, raw_documents, copy=True):    def transform(self, raw_documents, copy="deprecated"):         """Transform documents to document-term matrix.          Uses the vocabulary and document frequencies (df) learned by fit (or

Copy param ignored in TfidfVectorizer I was playing with vectorizers and I found this: However that parameter is not used later in the method. Here is used: Is there anything I am missing?


Question: Whether to copy X and operate on the copy or perform in-place             operations. <ins>            .. deprecated:: 0.22               The `copy` parameter is unused and was deprecated in version               0.22 and will be removed in 0.24. This parameter will be               ignored.</ins>         Returns         -------         X : sparse matrix, [n_samples, n_features]


Question: """         check_is_fitted(self, '_tfidf', 'The tfidf vector is not fitted') <ins>        # FIXME Remove copy parameter support in 0.24        if copy != "deprecated":            msg = ("'copy' param is unused and has been deprecated since "                   "version 0.22. Backward compatibility for 'copy' will "                   "be removed in 0.24.")            warnings.warn(msg, DeprecationWarning)</ins>         X = super().transform(raw_documents)         return self._tfidf.transform(X, copy=False)


Question: # Author: Andreas Mueller #         Joris Van den Bossche # License: BSDimport warnings from itertools import chain import numbers import numpy as np from scipy import sparse from joblib import Parallel, delayed

RFC ColumnTransformer input validation and requirements There have been some issues around ColumnTransformer input requirements that I think we might want to discuss more explicitly. Examples are an actual bug when changing columns: and how to define number of input features . Related is also the idea of checking for column name consistency: Mainly I'm asking whether it makes sense to have the same requirements for ColumnTransformer as for other estimators. ColumnTransformer is the only estimator that addresses columns by name, and so reordering columns doesn't impact the model and actually everything works fine. Should we still aim for checking for reordering of columns? Right now, , which makes sense, since it only cares about the columns it is using. Should we allow that going forward as long as remainder is not used? (if remainder is used, the result of would have a different shape and downstream estimators would break, so I think we shouldn't support it in this case). In either case, what's ` or the number of columns actually used? Does it even make sense to define it if we allow adding other columns that are ignored?


Question: "The output of the '{0}' transformer should be 2D (scipy "                     "matrix, array, or pandas DataFrame).".format(name)) <ins>    def _validate_features(self, n_features, feature_names):        """Ensures feature counts and names are the same during fit and        transform.        TODO: It should raise an error from v0.24        """        if ((self._feature_names_in is None or feature_names is None)                and self._n_features == n_features):            return        neg_col_present = np.any([_is_negative_indexing(col)                                  for col in self._columns])        if neg_col_present and self._n_features != n_features:            raise RuntimeError("At least one negative column was used to "                               "indicate columns, and the new data's number "                               "of columns does not match the data given "                               "during fit. "                               "Please make sure the data during fit and "                               "transform have the same number of columns.")        if (self._n_features != n_features or                np.any(self._feature_names_in != np.asarray(feature_names))):            warnings.warn("Given feature/column names or counts do not match "                          "the ones for the data given during fit. This will "                          "fail from v0.24.",                          DeprecationWarning)</ins>     def _log_message(self, name, idx, total):         if not self.verbose:             return None


Question: sparse matrices.          """<ins>        # TODO: this should be `feature_names_in_` when we start having it        if hasattr(X, "columns"):            self._feature_names_in = np.asarray(X.columns)        else:            self._feature_names_in = None</ins>         X = _check_X(X)         self._validate_transformers()         self._validate_column_callables(X)


Question: """         check_is_fitted(self, 'transformers_')         X = _check_X(X)<ins>        if hasattr(X, "columns"):            X_feature_names = np.asarray(X.columns)        else:            X_feature_names = None</ins>          if self._n_features > X.shape[1]:             raise ValueError('Number of features of the input must be equal '


Question: .format(self._n_features, X.shape[1]))          # No column reordering allowed for named cols combined with remainder<ins>        # TODO: remove this mechanism in 0.24, once we enforce strict column        # name order and count. See #14237 for details.</ins>         if (self._remainder[2] is not None and                 hasattr(self, '_df_columns') and                 hasattr(X, 'columns')):


Question: 'and for transform when using the '                                  'remainder keyword') <ins>        self._validate_features(X.shape[1], X_feature_names)</ins>         Xs = self._fit_transform(X, None, _transform_one, fitted=True)         self._validate_output(Xs)


Question: remainder=remainder,                              sparse_threshold=sparse_threshold,                              verbose=verbose)<ins>def _is_negative_indexing(key):    # TODO: remove in v0.24    def is_neg(x): return isinstance(x, numbers.Integral) and x < 0    if isinstance(key, slice):        return is_neg(key.start) or is_neg(key.stop)    elif _check_key_type(key, int):        return np.any(np.asarray(key) < 0)    return False</ins>


Question: model.alpha = best_alpha         model.l1_ratio = best_l1_ratio         model.copy_X = copy_X        model.precompute = False        precompute = getattr(self, "precompute", None)        if isinstance(precompute, str) and precompute == "auto":            model.precompute = False         model.fit(X, y)         if not hasattr(self, 'l1_ratio'):             del self.l1_ratio_

LassoCV always sets precompute to False before fitting the chosen alpha value I'm using a very large data-set. After fitting 100 x 3-fold cross-validated LASSOs at lightning speed (a few seconds total), LassoCV stalls at the final hurdle: fitting a LASSO with the chosen alpha value to the whole data-set (waiting over half an hour - it should only take approximately 50% longer than a single fold...). After a lot of head-scratching I found the reason why. In 's () just before calling the final () (line 1223 in Python2.7/sklearn0.19.0), there is the rather inconspicuous line So even if you've specified precompute as True when calling LassoCV, it is ignored. Why is this? It's making the computation impractically slow (should it even be this slow without precompute?) - literally just commenting the line out makes the fit instantaneous. Am I missing something here mathematically - I can't see anything wrong with using a precomputed Gram matrix for the final fit when it was used for all of the cross-validation fits? The implementation seems to imply it should be used for performance whenever numsamples num_features. Why hard set it to False?


Question: def __init__(self, estimator, n_jobs=None):         super().__init__(estimator, n_jobs) <ins>    def fit(self, X, Y, sample_weight=None):        """Fit the model to data matrix X and targets Y.        Parameters        ----------        X : {array-like, sparse matrix} of shape (n_samples, n_features)            The input data.        Y : array-like of shape (n_samples, n_classes)            The target values.        sample_weight : array-like of shape (n_samples,) or None            Sample weights. If None, then samples are equally weighted.            Only supported if the underlying classifier supports sample            weights.        Returns        -------        self : object        """        super().fit(X, Y, sample_weight)        self.classes_ = [estimator.classes_ for estimator in self.estimators_]        return self</ins>     def predict_proba(self, X):         """Probability estimates.         Returns prediction probabilities for each class of each output.

AttributeError with crossvalpredict(method='predictproba') when using MultiOuputClassifier I believe there is a bug when using with a . I think the problem is in the use of here: To obtain the attribute of a , you need instead. If core team members have any idea of how to address this, I am happy to submit a patch. Array with prediction probabilities. System: python: 3.6.8 (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)] executable: C:\Users\nak142\Miniconda3\envs\myo\ machine: Windows-10-10.0.-SP0 BLAS: macros: libdirs: cblas_libs: cblas Python deps: pip: 19.1.1 setuptools: 41.0.1 sklearn: 0.21.2 numpy: 1.16.4 scipy: 1.2.1 Cython: 0.29.12 pandas: 0.24.2


Question: if self.order_ == 'random':                 self.order_ = random_state.permutation(Y.shape[1])         elif sorted(self.order_) != list(range(Y.shape[1])):                raise ValueError("invalid order")            raise ValueError("invalid order")          self.estimators_ = [clone(self.base_estimator)                             for _ in range(Y.shape[1])]


Question: Notes     -----    Train and test sizes may be different in each fold, with a difference of at    most ``n_classes``.    The implementation is designed to:    * Generate test sets such that all contain the same distribution of      classes, or as close as possible.    * Be invariant to class label: relabelling ``y = ["Happy", "Sad"]`` to      ``y = [1, 0]`` should not change the indices generated.    * Preserve order dependencies in the dataset ordering, when      ``shuffle=False``: all samples from class k in some test set were      contiguous in y, or separated in y by samples from classes other than k.    * Generate test sets where the smallest and largest differ by at most one      sample.    .. versionchanged:: 0.22        The previous implementation did not follow the last constraint.      See also     --------

StratifiedKFold makes fold-sizes very unequal I found this when trying to write tests for . Right now, `: We could achieve something like but our rounding doesn't let us :-/


Question: allowed_target_types, type_of_target_y))          y = column_or_1d(y)        n_samples = y.shape[0]        unique_y, y_inversed = np.unique(y, return_inverse=True)        y_counts = np.bincount(y_inversed)        _, y_idx, y_inv = np.unique(y, return_index=True, return_inverse=True)        # y_inv encodes y according to lexicographic order. We invert y_idx to        # map the classes so that they are encoded by order of appearance:        # 0 represents the first label appearing in y, 1 the second, etc.        _, class_perm = np.unique(y_idx, return_inverse=True)        y_encoded = class_perm[y_inv]        n_classes = len(y_idx)        y_counts = np.bincount(y_encoded)         min_groups = np.min(y_counts)         if np.all(self.n_splits > y_counts):             raise ValueError("n_splits=%d cannot be greater than the"


Question: % (self.n_splits))         if self.n_splits > min_groups:             warnings.warn(("The least populated class in y has only %d"                           " members, which is too few. The minimum"                           " number of members in any class cannot"                           " be less than n_splits=%d."                           % (min_groups, self.n_splits)), Warning)        # pre-assign each sample to a test fold index using individual KFold        # splitting strategies for each class so as to respect the balance of        # classes        # NOTE: Passing the data corresponding to ith class say X[y==class_i]        # will break when the data is not 100% stratifiable for all classes.        # So we pass np.zeroes(max(c, n_splits)) as data to the KFold        per_cls_cvs = [            KFold(self.n_splits, shuffle=self.shuffle,                  random_state=rng).split(np.zeros(max(count, self.n_splits)))            for count in y_counts]        test_folds = np.zeros(n_samples, dtype=np.int)        for test_fold_indices, per_cls_splits in enumerate(zip(*per_cls_cvs)):            for cls, (_, test_split) in zip(unique_y, per_cls_splits):                cls_test_folds = test_folds[y == cls]                # the test split can be too big because we used                # KFold(...).split(X[:max(c, n_splits)]) when data is not 100%                # stratifiable for all the classes                # (we use a warning instead of raising an exception)                # If this is the case, let's trim it:                test_split = test_split[test_split < len(cls_test_folds)]                cls_test_folds[test_split] = test_fold_indices                test_folds[y == cls] = cls_test_folds                           " members, which is less than n_splits=%d."                           % (min_groups, self.n_splits)), UserWarning)        # Determine the optimal number of samples from each class in each fold,        # using round robin over the sorted y. (This can be done direct from        # counts, but that code is unreadable.)        y_order = np.sort(y_encoded)        allocation = np.asarray(            [np.bincount(y_order[i::self.n_splits], minlength=n_classes)             for i in range(self.n_splits)])        # To maintain the data order dependencies as best as possible within        # the stratification constraint, we assign samples from each class in        # blocks (and then mess that up when shuffle=True).        test_folds = np.empty(len(y), dtype='i')        for k in range(n_classes):            # since the kth column of allocation stores the number of samples            # of class k in each test set, this generates blocks of fold            # indices corresponding to the allocation for class k.            folds_for_class = np.arange(self.n_splits).repeat(allocation[:, k])            if self.shuffle:                rng.shuffle(folds_for_class)            test_folds[y_encoded == k] = folds_for_class         return test_folds      def _iter_test_masks(self, X, y=None, groups=None):


Question: sklearn.metrics.pairwise.kernel_metrics : List of built-in kernels.     """<ins></ins>     def __init__(self, kernel="rbf", gamma=None, coef0=None, degree=None,                  kernel_params=None, n_components=100, random_state=None):         self.kernel = kernel

kernelapproximation.Nystroem does not support precomputed kernel The documentation says that precomputed kernels are supported in Nystroem, but in reality it does not seem to be the case: https://scikit- Example code: Leads to


Question: params = self.kernel_params         if params is None:             params = {}        if not callable(self.kernel):        if not callable(self.kernel) and self.kernel != 'precomputed':             for param in (KERNEL_PARAMS[self.kernel]):                 if getattr(self, param) is not None:                     params[param] = getattr(self, param)


Question: self.coef0 is not None or                     self.degree is not None):                 raise ValueError("Don't pass gamma, coef0 or degree to "                                 "Nystroem if using a callable kernel.")                                 "Nystroem if using a callable "                                 "or precomputed kernel")          return params


Question: Scores are computed on validation data or on training data.         """        if is_classifier(self):            y_small_train = self.classes_[y_small_train.astype(int)]         self.train_score_.append(             self.scorer_(self, X_binned_small_train, y_small_train)         )          if self._use_validation_data:            if is_classifier(self):                y_val = self.classes_[y_val.astype(int)]             self.validation_score_.append(                 self.scorer_(self, X_binned_val, y_val)             )

HistGradientBoostingClassifier does not work with string target when early stopping turned on <!-- 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--The scorer used under the hood during early stopping is provided with being integer while are original classes (i.e. string). We need to encode each time that we want to compute the score. <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --No error is thrown <!-- Please paste or specifically describe the actual output or traceback. --Maybe one solution would be to do:


Question: sample_weight, multioutput)  def median_absolute_error(y_true, y_pred):def median_absolute_error(y_true, y_pred, multioutput='uniform_average'):     """Median absolute error regression loss     Read more in the :ref:`User Guide <median_absolute_error>`.    Median absolute error output is non-negative floating point. The best value    is 0.0. Read more in the :ref:`User Guide <median_absolute_error>`.      Parameters     ----------    y_true : array-like of shape (n_samples,)    y_true : array-like of shape = (n_samples) or (n_samples, n_outputs)         Ground truth (correct) target values.     y_pred : array-like of shape (n_samples,)    y_pred : array-like of shape = (n_samples) or (n_samples, n_outputs)         Estimated target values.     multioutput : {'raw_values', 'uniform_average'} or array-like of shape        (n_outputs,)        Defines aggregating of multiple output values. Array-like value defines        weights used to average errors.        'raw_values' :            Returns a full set of errors in case of multioutput input.        'uniform_average' :            Errors of all outputs are averaged with uniform weight.     Returns     -------    loss : float        A positive floating point value (the best value is 0.0).    loss : float or ndarray of floats        If multioutput is 'raw_values', then mean absolute error is returned        for each output separately.        If multioutput is 'uniform_average' or an ndarray of weights, then the        weighted average of all output errors is returned.      Examples     --------

medianabsoluteerror multioutput Multioutput is not currently supported in . Is this a design choice or has it just not been implemented yet? In case of the latter, I am happy to submit a PR.


Question: >>> y_pred = [2.5, 0.0, 2, 8]     >>> median_absolute_error(y_true, y_pred)     0.5    >>> y_true = [[0.5, 1], [-1, 1], [7, -6]]    >>> y_pred = [[0, 2], [-1, 2], [8, -5]]    >>> median_absolute_error(y_true, y_pred)    0.75    >>> median_absolute_error(y_true, y_pred, multioutput='raw_values')    array([0.5, 1. ])    >>> median_absolute_error(y_true, y_pred, multioutput=[0.3, 0.7])    0.85      """    y_type, y_true, y_pred, _ = _check_reg_targets(y_true, y_pred, None)    if y_type == 'continuous-multioutput':        raise ValueError("Multioutput not supported in median_absolute_error")    return np.median(np.abs(y_pred - y_true))    y_type, y_true, y_pred, multioutput = _check_reg_targets(        y_true, y_pred, multioutput)    output_errors = np.median(np.abs(y_pred - y_true), axis=0)    if isinstance(multioutput, str):        if multioutput == 'raw_values':            return output_errors        elif multioutput == 'uniform_average':            # pass None as weights to np.average: uniform mean            multioutput = None    return np.average(output_errors, weights=multioutput)   def explained_variance_score(y_true, y_pred,


Question: n_clusters_per_class : int, optional (default=2)         The number of clusters per class.     weights : list of floats or None (default=None)    weights : array-like of shape (n_classes,) or (n_classes - 1,),\              (default=None)         The proportions of samples assigned to each class. If None, then         classes are balanced. Note that if ``len(weights) == n_classes - 1``,         then the last class weight is automatically inferred.

datasets :: makeclassification() weights parameter should be a sequence (not just a list). If there is a pertinent reason that must be a list, while all other iterable parameters are arrays, then it should be mentioned in the docstring. Otherwise, the docstring should be amended as in , e.g. "weights : list of floats or None (default=None)" -"weights : sequence of floats or None (default=None)", along with amended lines 165 and 171 (see Corrections). Should not fail: as valid as a list: #wimlds [MRG] Added an example to the …or class <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: --<!-- Contributes to . --I an example to the () <!-- 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! --


Question: " features")     # Use log2 to avoid overflow errors     if n_informative < np.log2(n_classes * n_clusters_per_class):        raise ValueError("n_classes * n_clusters_per_class must"                         " be smaller or equal 2 ** n_informative")    if weights and len(weights) not in [n_classes, n_classes - 1]:        raise ValueError("Weights specified but incompatible with number "                         "of classes.")        msg = "n_classes({}) * n_clusters_per_class({}) must be"        msg += " smaller or equal 2**n_informative({})={}"        raise ValueError(msg.format(n_classes, n_clusters_per_class,                                    n_informative, 2**n_informative))    if weights is not None:        if len(weights) not in [n_classes, n_classes - 1]:            raise ValueError("Weights specified but incompatible with number "                             "of classes.")        if len(weights) == n_classes - 1:            if isinstance(weights, list):                weights = weights + [1.0 - sum(weights)]            else:                weights = np.resize(weights, n_classes)                weights[-1] = 1.0 - sum(weights[:-1])    else:        weights = [1.0 / n_classes] * n_classes      n_useless = n_features - n_informative - n_redundant - n_repeated     n_clusters = n_classes * n_clusters_per_class     if weights and len(weights) == (n_classes - 1):        weights = weights + [1.0 - sum(weights)]    if weights is None:        weights = [1.0 / n_classes] * n_classes        weights[-1] = 1.0 - sum(weights[:-1])     # Distribute samples among clusters by weight     n_samples_per_cluster = [         int(n_samples * weights[k % n_classes] / n_clusters_per_class)


Question: "random"             A random order for each round. <ins>    skip_complete : boolean, optional (default=False)        If ``True`` then features with missing values during ``transform``        which did not have any missing values during ``fit`` will be imputed        with the initial imputation method only. Set to ``True`` if you have        many features with no missing values at both ``fit`` and ``transform``        time to save compute.</ins>     min_value : float, optional (default=None)         Minimum possible imputed value. Default of ``None`` will set minimum         to negative infinity.

IterativeImputer behaviour on missing nan's in fit data Why is this behaviour forced: Features with missing values during transform which did not have any missing values during fit will be imputed with the initial imputation method only. This means by default it will return the mean of that feature. I would prefer just fit one iteration of the chosen estimator and use that fitted estimator to impute missing values. Actual behaviour: Example - The second feature missing --mean imputation Example adjusted - Second feature has values --iterative imputation with estimator Maybe line 679 to 683 should be optional with a parameter like force-iterimpute.


Question: Indicator used to add binary indicators for missing values.         ``None`` if add_indicator is False. <ins>    random_state_ : RandomState instance        RandomState instance that is generated either from a seed, the random        number generator or by `np.random`.</ins>     See also     --------     SimpleImputer : Univariate imputation of missing values.


Question: Features which contain all missing values at ``fit`` are discarded upon     ``transform``. <del>    Features with missing values during ``transform`` which did not have any    missing values during ``fit`` will be imputed with the initial imputation    method only.</del>     References     ----------     .. [1] `Stef van Buuren, Karin Groothuis-Oudshoorn (2011). "mice:


Question: n_nearest_features=None,                  initial_strategy="mean",                  imputation_order='ascending',<ins>                 skip_complete=False,</ins>                  min_value=None,                  max_value=None,                  verbose=0,


Question: self.n_nearest_features = n_nearest_features         self.initial_strategy = initial_strategy         self.imputation_order = imputation_order<ins>        self.skip_complete = skip_complete</ins>         self.min_value = min_value         self.max_value = max_value         self.verbose = verbose


Question: The fitted estimator used to impute             ``X_filled[missing_row_mask, feat_idx]``.         """<del>        # if nothing is missing, just return the default        # (should not happen at fit time because feat_ids would be excluded)        missing_row_mask = mask_missing_values[:, feat_idx]        if not np.any(missing_row_mask):            return X_filled, estimator</del>         if estimator is None and fit_mode is False:             raise ValueError("If fit_mode is False, then an already-fitted "                              "estimator should be passed in.")


Question: if estimator is None:             estimator = clone(self._estimator) <ins>        missing_row_mask = mask_missing_values[:, feat_idx]</ins>         if fit_mode:             X_train = safe_indexing(X_filled[:, neighbor_feat_idx],                                     ~missing_row_mask)


Question: ~missing_row_mask)             estimator.fit(X_train, y_train)         # get posterior samples        # if no missing values, don't predict        if np.sum(missing_row_mask) == 0:            return X_filled, estimator        # get posterior samples if there is at least one missing value         X_test = safe_indexing(X_filled[:, neighbor_feat_idx],                                missing_row_mask)         if self.sample_posterior:             mus, sigmas = estimator.predict(X_test, return_std=True)             imputed_values = np.zeros(mus.shape, dtype=X_filled.dtype)            # two types of problems: (1) non-positive sigmas, (2) mus outside            # legal range of min_value and max_value (results in inf sample)            # two types of problems: (1) non-positive sigmas            # (2) mus outside legal range of min_value and max_value            # (results in inf sample)             positive_sigmas = sigmas > 0             imputed_values[~positive_sigmas] = mus[~positive_sigmas]             mus_too_low = mus < self._min_value


Question: The order in which to impute the features.         """         frac_of_missing_values = mask_missing_values.mean(axis=0)        missing_values_idx = np.nonzero(frac_of_missing_values)[0]        if self.skip_complete:            missing_values_idx = np.flatnonzero(frac_of_missing_values)        else:            missing_values_idx = np.arange(np.shape(frac_of_missing_values)[0])         if self.imputation_order == 'roman':             ordered_idx = missing_values_idx         elif self.imputation_order == 'arabic':


Question: self.initial_imputer_ = None         X, Xt, mask_missing_values = self._initial_imputation(X)         if self.max_iter == 0 or np.all(mask_missing_values):             self.n_iter_ = 0             return Xt         # Edge case: a single feature. We return the initial ...        if Xt.shape[1] == 1:            self.n_iter_ = 0            return Xt         # order in which to impute         # note this is probably too slow for large feature data (d > 100000)         # and a better way would be good.


Question: return encoded_y      def _get_loss(self):<ins>        if (self.loss == 'categorical_crossentropy' and                self.n_trees_per_iteration_ == 1):            raise ValueError("'categorical_crossentropy' is not suitable for "                             "a binary classification problem. Please use "                             "'auto' or 'binary_crossentropy' instead.")</ins>         if self.loss == 'auto':             if self.n_trees_per_iteration_ == 1:                 return _LOSSES['binary_crossentropy']()

HGBC with categoricalcrossentropy fails silently on binary classification gives: And works fine. should either generalize or raise an error on binary classification. Ping


Question: " you are sure you want to proceed regardless"                               ", set 'check_inverse=False'", UserWarning)     def fit(self, X, y, sample_weight=None):    def fit(self, X, y, **fit_params):         """Fit the model according to the given training data.          Parameters

Fitting TransformedTargetRegressor with sampleweight in Pipeline Can't fit a using . May be link to ? Example: ! Fitting with <!-- Thanks for contributing! --


Question: y : array-like, shape (n_samples,)             Target values.         sample_weight : array-like, shape (n_samples,) optional            Array of weights that are assigned to individual samples.            If not provided, then each sample is given unit weight.        **fit_params : dict of string -> object            Parameters passed to the ``fit`` method of the underlying            regressor.          Returns         -------


Question: else:             self.regressor_ = clone(self.regressor)         if sample_weight is None:            self.regressor_.fit(X, y_trans)        else:            self.regressor_.fit(X, y_trans, sample_weight=sample_weight)        self.regressor_.fit(X, y_trans, **fit_params)          return self


Question: n_SV = self.support_vectors_.shape[0]          dual_coef_indices = np.tile(np.arange(n_SV), n_class)        dual_coef_indptr = np.arange(0, dual_coef_indices.size + 1,                                     dual_coef_indices.size / n_class)        self.dual_coef_ = sp.csr_matrix(            (dual_coef_data, dual_coef_indices, dual_coef_indptr),            (n_class, n_SV))        if not n_SV:            self.dual_coef_ = sp.csr_matrix([])        else:            dual_coef_indptr = np.arange(0, dual_coef_indices.size + 1,                                         dual_coef_indices.size / n_class)            self.dual_coef_ = sp.csr_matrix(                (dual_coef_data, dual_coef_indices, dual_coef_indptr),                (n_class, n_SV))      def predict(self, X):         """Perform regression on samples in X.

ZeroDivisionError in sparsefit for SVM with empty supportvectors When using sparse data, in the case where the supportvectors attribute is be empty, fitsparse gives a ZeroDivisionError No error is thrown and


Question: raise ValueError("y_prob contains values less than 0.")      # if pos_label=None, when y_true is in {-1, 1} or {0, 1},    # pos_labe is set to 1 (consistent with precision_recall_curve/roc_curve),    # pos_label is set to 1 (consistent with precision_recall_curve/roc_curve),     # otherwise pos_label is set to the greater label     # (different from precision_recall_curve/roc_curve,     # the purpose is to keep backward compatibility).diff --git a/sklearn/metrics/scorer.py b/sklearn/metrics/scorer.py-- a/sklearn/metrics/scorer.py++ b/sklearn/metrics/scorer.py

Documentation section 3.3.1.1 has incorrect description of brierscoreloss In the documentation, section 3.3.1.1. "Common cases: predefined values" includes the remark As far as I can tell, this is true for all of the listed metrics, except the . In the case of , a lower loss value is better. This is because measures the mean-square difference between a predicted probability and a categorical outcome; the Brier score is minimized at 0.0 because all summands are either or when the model is making perfect predictions. On the other hand, the Brier score is maximized at 1.0 when all predictions are opposite the correct label, as all summands are either or . Therefore, the definition of the is not consistent with the quotation from section 3.3.1.1. I suggest making 2 changes to relieve this confusion. a function which simply negates the value of ; this is a direct analogy to what is done in the case of . A better model has a lower value of log-loss (categorical cross-entropy loss), therefore a larger value of the negative log-loss implies a better model. Naturally, the same is true for Brier score, where it is also the case that a better model is assigned a lower loss. reference to from section 3.3.1.1. Brier score is useful in lots of ways; however, because it does not have the property that a larger value implies a better model, it seems confusing to mention it in the context of section 3.3.1.1. References to can be replaced with , which has the property that better models have large values, just like accuracy, ROC AUC and the rest of the listed metrics.


Question: from collections.abc import Iterable from functools import partial from collections import Counter<ins>import warnings</ins>  import numpy as np


Question: self._kwargs = kwargs         self._score_func = score_func         self._sign = sign<ins>        # XXX After removing the deprecated scorers (v0.24) remove the        # XXX deprecation_msg property again and remove __call__'s body again        self._deprecation_msg = None</ins>      def __repr__(self):         kwargs_string = "".join([", %s=%s" % (str(k), str(v))


Question: score : float             Score function applied to prediction of estimator on X.         """<ins>        if self._deprecation_msg is not None:            warnings.warn(self._deprecation_msg,                          category=DeprecationWarning,                          stacklevel=2)</ins>         return self._score(partial(_cached_call, None), estimator, X, y_true,                            sample_weight=sample_weight)


Question: score : float             Score function applied to prediction of estimator on X.         """<ins></ins>         y_pred = method_caller(estimator, "predict", X)         if sample_weight is not None:             return self._sign * self._score_func(y_true, y_pred,


Question: score : float             Score function applied to prediction of estimator on X.         """<ins></ins>         y_type = type_of_target(y)         y_pred = method_caller(clf, "predict_proba", X)         if y_type == "binary":


Question: score : float             Score function applied to prediction of estimator on X.         """<ins></ins>         y_type = type_of_target(y)         if y_type not in ("binary", "multilabel-indicator"):             raise ValueError("{0} format is not supported".format(y_type))


Question: """     if isinstance(scoring, str):         try:            scorer = SCORERS[scoring]            if scoring == 'brier_score_loss':                # deprecated                scorer = brier_score_loss_scorer            else:                scorer = SCORERS[scoring]         except KeyError:             raise ValueError('%r is not a valid scoring value. '                              'Use sorted(sklearn.metrics.SCORERS.keys()) '                             'to get valid options.' % (scoring))                             'to get valid options.' % scoring)     else:         scorer = scoring     return scorer


Question: # Score function for probabilistic classification neg_log_loss_scorer = make_scorer(log_loss, greater_is_better=False,                                   needs_proba=True)neg_brier_score_scorer = make_scorer(brier_score_loss,                                     greater_is_better=False,                                     needs_proba=True) brier_score_loss_scorer = make_scorer(brier_score_loss,                                       greater_is_better=False,                                       needs_proba=True)deprecation_msg = ('Scoring method brier_score_loss was renamed to '                   'neg_brier_score in version 0.22 and will '                   'be removed in 0.24.')brier_score_loss_scorer._deprecation_msg = deprecation_msg   # Clustering scores


Question: balanced_accuracy=balanced_accuracy_scorer,                average_precision=average_precision_scorer,                neg_log_loss=neg_log_loss_scorer,               brier_score_loss=brier_score_loss_scorer,               neg_brier_score=neg_brier_score_scorer,                # Cluster metrics that use supervised evaluation                adjusted_rand_score=adjusted_rand_scorer,                homogeneity_score=homogeneity_scorer,


Question: self.n_classes_,          self.class_prior_) = class_distribution(y, sample_weight)         if (self.strategy == "constant" and                any(constant[k] not in self.classes_[k]                    for k in range(self.n_outputs_))):            # Checking in case of constant strategy if the constant            # provided by the user is in y.            raise ValueError("The constant target value must be "                             "present in training data")        if self.strategy == "constant":            for k in range(self.n_outputs_):                if not any(constant[k][0] == c for c in self.classes_[k]):                    # Checking in case of constant strategy if the constant                    # provided by the user is in y.                    err_msg = ("The constant target value must be present in "                               "the training data. You provided constant={}. "                               "Possible values are: {}."                               .format(self.constant, list(self.classes_[k])))                    raise ValueError(err_msg)          if self.n_outputs_ == 1 and not self.output_2d_:             self.n_classes_ = self.n_classes_[0]

Error could be improved with DummyClassifier constant strategy when constant value not in training data Error: We could add in the error message what constant value was provided (in this case ) and what the possible values are. This could be something like this (improvement more than welcome): Context: this was seen during the EuroScipy tutorial. The adult census dataset classes has a space in it at the beginning and the provided value did not have the space. Putting what the provided value was and what were the possible values would have helped the user fixing the problem.


Question: **self.cvargs)         return cv.get_n_splits(X, y, groups) * self.n_repeats <ins>    def __repr__(self):        return _build_repr(self)</ins>  class RepeatedKFold(_RepeatedSplits):     """Repeated K-Fold cross validator.

RepeatedKFold and RepeatedStratifiedKFold do not show correct repr string and do not show correct \repr\ string.


Question: try:             with warnings.catch_warnings(record=True) as w:                 value = getattr(self, key, None)<ins>                if value is None and hasattr(self, 'cvargs'):                    value = self.cvargs.get(key, None)</ins>             if len(w) and w[0].category == DeprecationWarning:                 # if the parameter is deprecated, don't show it                 continue


Question: X, y = check_X_y(X, y, dtype=[X_DTYPE], force_all_finite=False)         y = self._encode_y(y)         # The rng state must be preserved if warm_start is True        if (self.warm_start and hasattr(self, '_rng')):            rng = self._rng        else:            rng = check_random_state(self.random_state)            self._rng = rng        rng = check_random_state(self.random_state)        # When warm starting, we want to re-use the same seed that was used        # the first time fit was called (e.g. for subsampling or for the        # train/val split).        if not (self.warm_start and self._is_fitted()):            self._random_seed = rng.randint(np.iinfo(np.uint32).max,                                            dtype='u8')          self._validate_parameters()         self.n_features_ = X.shape[1]  # used for validation in predict()

data leak in GBDT due to warm start (This is about the non-histogram-based version of GBDTs) X is split into train and validation data with . As noted, in a warm starting context, this will produce a leak if If is a instance: some samples that were used for training in a previous might be used for validation now.


Question: # Save the state of the RNG for the training and validation split.             # This is needed in order to have the same split when using             # warm starting.            if not (self._is_fitted() and self.warm_start):                self._train_val_split_seed = rng.randint(1024)              X_train, X_val, y_train, y_val = train_test_split(                 X, y, test_size=self.validation_fraction, stratify=stratify,                random_state=self._train_val_split_seed)                random_state=self._random_seed)         else:             X_train, y_train = X, y             X_val, y_val = None, None


Question: # actual total number of bins. Everywhere in the code, the         # convention is that n_bins == max_bins + 1         n_bins = self.max_bins + 1  # + 1 for missing values        self.bin_mapper_ = _BinMapper(n_bins=n_bins, random_state=rng)        X_binned_train = self._bin_data(X_train, rng, is_training_data=True)        self.bin_mapper_ = _BinMapper(n_bins=n_bins,                                      random_state=self._random_seed)        X_binned_train = self._bin_data(X_train, is_training_data=True)         if X_val is not None:            X_binned_val = self._bin_data(X_val, rng, is_training_data=False)            X_binned_val = self._bin_data(X_val, is_training_data=False)         else:             X_binned_val = None


Question: # the predictions of all the trees. So we use a subset of                     # the training set to compute train scores.                     # Save the seed for the small trainset generator                    self._small_trainset_seed = rng.randint(1024)                     # Compute the subsample set                     (X_binned_small_train,                      y_small_train) = self._get_small_trainset(                        X_binned_train, y_train, self._small_trainset_seed)                        X_binned_train, y_train, self._random_seed)                      self._check_early_stopping_scorer(                         X_binned_small_train, y_small_train,


Question: if self.do_early_stopping_ and self.scoring != 'loss':                 # Compute the subsample set                 X_binned_small_train, y_small_train = self._get_small_trainset(                    X_binned_train, y_train, self._small_trainset_seed)                    X_binned_train, y_train, self._random_seed)              # Initialize the gradients and hessians             gradients, hessians = self.loss_.init_gradients_and_hessians(


Question: def _clear_state(self):         """Clear the state of the gradient boosting model."""        for var in ('train_score_', 'validation_score_', '_rng'):        for var in ('train_score_', 'validation_score_'):             if hasattr(self, var):                 delattr(self, var)


Question: for score in recent_scores]         return not any(recent_improvements)     def _bin_data(self, X, rng, is_training_data):    def _bin_data(self, X, is_training_data):         """Bin data X.          If is_training_data, then set the bin_mapper_ attribute.


Question: import numpy as np  from ..utils.validation import check_is_fitted<ins>from ..base import is_classifier</ins>  from . import _criterion from . import _tree

Deprecate classes attribute in DecisionTreeRegressor This partially relates to issue Currently, if you fit a decision tree regressor, and call the attribute , it will return none. This attribute does not appear on the doc string and shouldn't. This was surfaced from an issue related to mismatch attributes ( ) Reviewed the and worked with on different options including using a decorator on a property but it triggered the deprecation message when calling fit which was bad. In this PR, the was changed to in the parent. And a test was to the


Question: """     check_is_fitted(decision_tree)     tree_ = decision_tree.tree_    class_names = decision_tree.classes_    if is_classifier(decision_tree):        class_names = decision_tree.classes_     right_child_fmt = "{} {} <= {}\n"     left_child_fmt = "{} {} >  {}\n"     truncation_fmt = "{} {}\n"diff --git a/sklearn/tree/tree.py b/sklearn/tree/tree.py-- a/sklearn/tree/tree.py++ b/sklearn/tree/tree.py


Question: expanded_class_weight = compute_sample_weight(                     self.class_weight, y_original)         else:            self.classes_ = [None] * self.n_outputs_            self.n_classes_ = [1] * self.n_outputs_        self.n_classes_ = np.array(self.n_classes_, dtype=np.intp)            self.n_classes_ = np.array(self.n_classes_, dtype=np.intp)          if getattr(y, "dtype", None) != DOUBLE or not y.flags.contiguous:             y = np.ascontiguousarray(y, dtype=DOUBLE)


Question: min_weight_leaf,                                                 random_state)         self.tree_ = Tree(self.n_features_, self.n_classes_, self.n_outputs_)        if is_classifier(self):            self.tree_ = Tree(self.n_features_,                              self.n_classes_, self.n_outputs_)        else:            self.tree_ = Tree(self.n_features_,                              # TODO: tree should't need this in this case                              np.array([1] * self.n_outputs_, dtype=np.intp),                              self.n_outputs_)          # Use BestFirst if max_leaf_nodes given; use DepthFirst otherwise         if max_leaf_nodes < 0:


Question: builder.build(self.tree_, X, y, sample_weight, X_idx_sorted)         if self.n_outputs_ == 1:        if self.n_outputs_ == 1 and is_classifier(self):             self.n_classes_ = self.n_classes_[0]             self.classes_ = self.classes_[0]


Question: if self.ccp_alpha == 0.0:             return         # build pruned treee        n_classes = np.atleast_1d(self.n_classes_)        pruned_tree = Tree(self.n_features_, n_classes, self.n_outputs_)        # build pruned tree        if is_classifier(self):            n_classes = np.atleast_1d(self.n_classes_)            pruned_tree = Tree(self.n_features_, n_classes, self.n_outputs_)        else:            pruned_tree = Tree(self.n_features_,                               # TODO: the tree shouldn't need this param                               np.array([1] * self.n_outputs_, dtype=np.intp),                               self.n_outputs_)         _build_pruned_tree_ccp(pruned_tree, self.tree_, self.ccp_alpha)          self.tree_ = pruned_tree


Question: X_idx_sorted=X_idx_sorted)         return self <ins>    @property    def classes_(self):        # TODO: Remove method in 0.24        msg = ("the classes_ attribute is to be deprecated from version "               "0.22 and will be removed in 0.24.")        warnings.warn(msg, DeprecationWarning)        return np.array([None] * self.n_outputs_)    @property    def n_classes_(self):        # TODO: Remove method in 0.24        msg = ("the n_classes_ attribute is to be deprecated from version "               "0.22 and will be removed in 0.24.")        warnings.warn(msg, DeprecationWarning)        return np.array([1] * self.n_outputs_, dtype=np.intp)</ins>  class ExtraTreeClassifier(DecisionTreeClassifier):     """An extremely randomized tree classifier.


Question: # Let us not impose fortran ordering so far: it is             # not useful for the cross-validation loop and will be done             # by the model fitting itself            X = check_array(X, 'csc', copy=False)            X = check_array(X, 'csc', dtype=[np.float64, np.float32],                            copy=False)             if sparse.isspmatrix(X):                 if (hasattr(reference_to_old_X, "data") and                    not np.may_share_memory(reference_to_old_X.data, X.data)):

MultiTaskLassoCV with fitintercept=True returns wrong results There is something wrong with and binary features. It always returns the same mse for all the alphas and hence chooses a huge regularization zeroing out all coefficients. The same holds for too. However, this doesn't happen with . Moreover it doesn't happen if I set , or if I generate random normal features. I am working on anaconda, windows system, with python 3.7.1 and with scikit-learn v0.21.3, numpy v1.16.2. Consider the following code: It returns On the other hand, if I generate normal features X, then things are good: which returns: Also weirdly if I set , then things are good even with binary features: which returns


Question: dtypes_orig = None     if hasattr(array, "dtypes") and hasattr(array.dtypes, '__array__'):         dtypes_orig = np.array(array.dtypes)<ins>        if all(isinstance(dtype, np.dtype) for dtype in dtypes_orig):            dtype_orig = np.result_type(*array.dtypes)</ins>      if dtype_numeric:         if dtype_orig is not None and dtype_orig.kind == "O":

MaxAbsScaler Upcasts Pandas to float64 <!-- 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: --I am working with the Column transformer, and for memory issues, am trying to produce a float32 sparse matrix. Unfortunately, regardless of pandas input type, the output is always float64. I've identified one of the Pipeline scalers, MaxAbsScaler, as being the culprit. Other preprocessing functions, such as OneHotEncoder, have an optional argument. This argument does not exist in MaxAbsScaler (among others). It appears that the upcasting happens when is executed. Is it possible to specify a dtype? Or is there a commonly accepted practice to do so from the Column Transformer? Thank you! Example: Darwin-18.7.0-x8664-i386-64bit Python 3.6.7 (default, Jul 2 2019, 02:07:37) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] NumPy 1.17.1 SciPy 1.3.1 Scikit-Learn 0.20.3 Pandas 0.25.1


Question: self.best_params_ = results["params"][self.best_index_]          if self.refit:            self.best_estimator_ = clone(base_estimator).set_params(                **self.best_params_)            # we clone again after setting params in case some            # of the params are estimators as well.            self.best_estimator_ = clone(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)diff --git a/sklearn/model_selection/_validation.py b/sklearn/model_selection/_validation.py-- a/sklearn/model_selection/_validation.py++ b/sklearn/model_selection/_validation.py

GridSearchCV saves all fitted estimator in cvresults['params'] when params are estimators I use GridSearchCV to optimize the hyperparameters of a pipeline. I set the param grid by inputing transformers or estimators at different steps of the pipeline, following the Pipeline documentation: I couldn't figure why dumping cvresults would take so much memory on disk. It happens that cvresults['params'] and all cvresults['param*'] objects contains fitted estimators, as much as there are points on my grid. This bug should happen only when njobs = 1 (which is my usecase). I don't think this is intended (else the arguments and attributes refit and best\estimator wouldn't be used). My guess is that during the grid search, those estimator's aren't cloned before use (which could be a problem if using the same grid search several times, because estimators passed in the next grid would be fitted...).


Question: train_scores = {}     if parameters is not None:        estimator.set_params(**parameters)        # clone after setting parameters in case any parameters        # are estimators (like pipeline steps)        # because pipeline doesn't clone steps in fit        cloned_parameters = {}        for k, v in parameters.items():            cloned_parameters[k] = clone(v, safe=False)        estimator = estimator.set_params(**cloned_parameters)      start_time = time.time()


Question: Remove accentuated char for any unicode symbol that has a direct         ASCII equivalent.     """    normalized = unicodedata.normalize('NFKD', s)    if normalized == s:    try:        # If `s` is ASCII-compatible, then it does not contain any accented        # characters and we can avoid an expensive list comprehension        s.encode("ASCII", errors="strict")         return s    else:    except UnicodeEncodeError:        normalized = unicodedata.normalize('NFKD', s)         return ''.join([c for c in normalized if not unicodedata.combining(c)])

stripaccentsunicode fails to strip accents from strings that are already in NFKD form <!-- 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--The feature of and related does not work as expected when it processes strings that contain accents, if those strings are already in NFKD form. and should both be normalized to the same string, . is not changed, because does nothing if the string is already in NFKD form.


Question: trans.get_feature_names()])         return feature_names     def fit(self, X, y=None):    def fit(self, X, y=None, **fit_params):         """Fit all transformers using X.          Parameters

Inconsistent fit + transform and fittransform for FeatureUnion Is there a reason why the method signature accepts but neither nor do? It seems to go against the pattern that is the same as calling ? I see there's been discussion on supporting but it's not clear if this is resolved. My case is I'm trying to migrage code I wrote a while back where I used a Pipeline and each of my transformers adds columns to a dataframe, to a FeatureUnion where each transform only returns the new columns. One of my transforms takes a third data set in addition to X and y which is used as the transform. I guess as a workaround I'll make it a param of the transform rather than a fitarg.


Question: self : FeatureUnion             This estimator         """        transformers = self._parallel_func(X, y, {}, _fit_one)        transformers = self._parallel_func(X, y, fit_params, _fit_one)         if not transformers:             # All transformers are None             return self


Question: # If converged or at max_iter, adds the cluster         if (np.linalg.norm(my_mean - my_old_mean) < stop_thresh or                 completed_iterations == max_iter):            return tuple(my_mean), len(points_within)            break         completed_iterations += 1    return tuple(my_mean), len(points_within), completed_iterations   def mean_shift(X, bandwidth=None, seeds=None, bin_seeding=False,

meanshift and MeanShift don't have the same API I'm trying to make call (related to ) but has a parameter and uses the default, so I cannot preserve backward compatibility without adding to . Should I just do that?


Question: <sphx_glr_auto_examples_cluster_plot_mean_shift.py>`.      """    if bandwidth is None:        bandwidth = estimate_bandwidth(X, n_jobs=n_jobs)    elif bandwidth <= 0:        raise ValueError("bandwidth needs to be greater than zero or None,"                         " got %f" % bandwidth)    if seeds is None:        if bin_seeding:            seeds = get_bin_seeds(X, bandwidth, min_bin_freq)        else:            seeds = X    n_samples, n_features = X.shape    center_intensity_dict = {}    # We use n_jobs=1 because this will be used in nested calls under    # parallel calls to _mean_shift_single_seed so there is no need for    # for further parallelism.    nbrs = NearestNeighbors(radius=bandwidth, n_jobs=1).fit(X)    # execute iterations on all seeds in parallel    all_res = Parallel(n_jobs=n_jobs)(        delayed(_mean_shift_single_seed)        (seed, X, nbrs, max_iter) for seed in seeds)    # copy results in a dictionary    for i in range(len(seeds)):        if all_res[i] is not None:            center_intensity_dict[all_res[i][0]] = all_res[i][1]    if not center_intensity_dict:        # nothing near seeds        raise ValueError("No point was within bandwidth=%f of any seed."                         " Try a different seeding strategy \                         or increase the bandwidth."                         % bandwidth)    # POST PROCESSING: remove near duplicate points    # If the distance between two kernels is less than the bandwidth,    # then we have to remove one because it is a duplicate. Remove the    # one with fewer points.    sorted_by_intensity = sorted(center_intensity_dict.items(),                                 key=lambda tup: (tup[1], tup[0]),                                 reverse=True)    sorted_centers = np.array([tup[0] for tup in sorted_by_intensity])    unique = np.ones(len(sorted_centers), dtype=np.bool)    nbrs = NearestNeighbors(radius=bandwidth,                            n_jobs=n_jobs).fit(sorted_centers)    for i, center in enumerate(sorted_centers):        if unique[i]:            neighbor_idxs = nbrs.radius_neighbors([center],                                                  return_distance=False)[0]            unique[neighbor_idxs] = 0            unique[i] = 1  # leave the current point as unique    cluster_centers = sorted_centers[unique]    # ASSIGN LABELS: a point belongs to the cluster that it is closest to    nbrs = NearestNeighbors(n_neighbors=1, n_jobs=n_jobs).fit(cluster_centers)    labels = np.zeros(n_samples, dtype=np.int)    distances, idxs = nbrs.kneighbors(X)    if cluster_all:        labels = idxs.flatten()    else:        labels.fill(-1)        bool_selector = distances.flatten() <= bandwidth        labels[bool_selector] = idxs.flatten()[bool_selector]    return cluster_centers, labels    model = MeanShift(bandwidth=bandwidth, seeds=seeds,                      min_bin_freq=min_bin_freq,                      bin_seeding=bin_seeding,                      cluster_all=cluster_all, n_jobs=n_jobs,                      max_iter=max_iter).fit(X)    return model.cluster_centers_, model.labels_   def get_bin_seeds(X, bin_size, min_bin_freq=1):


Question: ``-1`` means using all processors. See :term:`Glossary <n_jobs>`         for more details. <ins>    max_iter : int, default=300        Maximum number of iterations, per seed point before the clustering        operation terminates (for that seed point), if has not converged yet.        .. versionadded:: 0.22</ins>     Attributes     ----------     cluster_centers_ : array, [n_clusters, n_features]


Question: labels_ :         Labels of each point. <ins>    n_iter_ : int        Maximum number of iterations performed on each seed.        .. versionadded:: 0.22</ins>     Examples     --------     >>> from sklearn.cluster import MeanShift


Question: """     def __init__(self, bandwidth=None, seeds=None, bin_seeding=False,                 min_bin_freq=1, cluster_all=True, n_jobs=None):                 min_bin_freq=1, cluster_all=True, n_jobs=None, max_iter=300):         self.bandwidth = bandwidth         self.seeds = seeds         self.bin_seeding = bin_seeding         self.cluster_all = cluster_all         self.min_bin_freq = min_bin_freq         self.n_jobs = n_jobs        self.max_iter = max_iter      def fit(self, X, y=None):         """Perform clustering.


Question: """         X = check_array(X)        self.cluster_centers_, self.labels_ = \            mean_shift(X, bandwidth=self.bandwidth, seeds=self.seeds,                       min_bin_freq=self.min_bin_freq,                       bin_seeding=self.bin_seeding,                       cluster_all=self.cluster_all, n_jobs=self.n_jobs)        bandwidth = self.bandwidth        if bandwidth is None:            bandwidth = estimate_bandwidth(X, n_jobs=self.n_jobs)        elif bandwidth <= 0:            raise ValueError("bandwidth needs to be greater than zero or None,"                             " got %f" % bandwidth)        seeds = self.seeds        if seeds is None:            if self.bin_seeding:                seeds = get_bin_seeds(X, bandwidth, self.min_bin_freq)            else:                seeds = X        n_samples, n_features = X.shape        center_intensity_dict = {}        # We use n_jobs=1 because this will be used in nested calls under        # parallel calls to _mean_shift_single_seed so there is no need for        # for further parallelism.        nbrs = NearestNeighbors(radius=bandwidth, n_jobs=1).fit(X)        # execute iterations on all seeds in parallel        all_res = Parallel(n_jobs=self.n_jobs)(            delayed(_mean_shift_single_seed)            (seed, X, nbrs, self.max_iter) for seed in seeds)        # copy results in a dictionary        for i in range(len(seeds)):            if all_res[i][1]:  # i.e. len(points_within) > 0                center_intensity_dict[all_res[i][0]] = all_res[i][1]        self.n_iter_ = max([x[2] for x in all_res])        if not center_intensity_dict:            # nothing near seeds            raise ValueError("No point was within bandwidth=%f of any seed."                             " Try a different seeding strategy \                             or increase the bandwidth."                             % bandwidth)        # POST PROCESSING: remove near duplicate points        # If the distance between two kernels is less than the bandwidth,        # then we have to remove one because it is a duplicate. Remove the        # one with fewer points.        sorted_by_intensity = sorted(center_intensity_dict.items(),                                     key=lambda tup: (tup[1], tup[0]),                                     reverse=True)        sorted_centers = np.array([tup[0] for tup in sorted_by_intensity])        unique = np.ones(len(sorted_centers), dtype=np.bool)        nbrs = NearestNeighbors(radius=bandwidth,                                n_jobs=self.n_jobs).fit(sorted_centers)        for i, center in enumerate(sorted_centers):            if unique[i]:                neighbor_idxs = nbrs.radius_neighbors([center],                                                      return_distance=False)[0]                unique[neighbor_idxs] = 0                unique[i] = 1  # leave the current point as unique        cluster_centers = sorted_centers[unique]        # ASSIGN LABELS: a point belongs to the cluster that it is closest to        nbrs = NearestNeighbors(n_neighbors=1,                                n_jobs=self.n_jobs).fit(cluster_centers)        labels = np.zeros(n_samples, dtype=np.int)        distances, idxs = nbrs.kneighbors(X)        if self.cluster_all:            labels = idxs.flatten()        else:            labels.fill(-1)            bool_selector = distances.flatten() <= bandwidth            labels[bool_selector] = idxs.flatten()[bool_selector]        self.cluster_centers_, self.labels_ = cluster_centers, labels         return self      def predict(self, X):


Question: import numpy as np from joblib import Parallel, delayed<ins>import scipy.sparse as sparse</ins>  from ..base import clone from ..base import ClassifierMixin, RegressorMixin, TransformerMixin

Stacking: add an option to use the original dataset when training finalestimator I think it will be readonable to add an option to use the original dataset when training finalestimator. This seems reasonable and has proved to be useful in some Kaggle competitions. Reference: implementation from mlxtend usefeaturesinsecondary : bool (default: False) If True, the meta-classifier will be trained both on the predictions of the original classifiers and the original dataset. If False, the meta-classifier will be trained only on the predictions of the original classifiers.


Question: @abstractmethod     def __init__(self, estimators, final_estimator=None, cv=None,                 stack_method='auto', n_jobs=None, verbose=0):                 stack_method='auto', n_jobs=None, verbose=0,                 passthrough=False):         super().__init__(estimators=estimators)         self.final_estimator = final_estimator         self.cv = cv         self.stack_method = stack_method         self.n_jobs = n_jobs         self.verbose = verbose        self.passthrough = passthrough      def _clone_final_estimator(self, default):         if self.final_estimator is not None:


Question: else:             self.final_estimator_ = clone(default)     def _concatenate_predictions(self, predictions):        """Concatenate the predictions of each first layer learner.    def _concatenate_predictions(self, X, predictions):        """Concatenate the predictions of each first layer learner and        possibly the input dataset `X`.        If `X` is sparse and `self.passthrough` is False, the output of        `transform` will be dense (the predictions). If `X` is sparse        and `self.passthrough` is True, the output of `transform` will        be sparse.          This helper is in charge of ensuring the preditions are 2D arrays and         it will drop one of the probability column when using probabilities


Question: X_meta.append(preds[:, 1:])                 else:                     X_meta.append(preds)        return np.concatenate(X_meta, axis=1)        if self.passthrough:            X_meta.append(X)            if sparse.issparse(X):                return sparse.hstack(X_meta, format=X.format)        return np.hstack(X_meta)      @staticmethod     def _method_name(name, estimator, method):


Question: if est != 'drop'         ]         X_meta = self._concatenate_predictions(predictions)        X_meta = self._concatenate_predictions(X, predictions)         if sample_weight is not None:             try:                 self.final_estimator_.fit(


Question: for est, meth in zip(self.estimators_, self.stack_method_)             if est != 'drop'         ]        return self._concatenate_predictions(predictions)        return self._concatenate_predictions(X, predictions)      @if_delegate_has_method(delegate='final_estimator_')     def predict(self, X, **predict_params):


Question: `None` means 1 unless in a `joblib.parallel_backend` context. -1 means         using all processors. See Glossary for more details. <ins>    passthrough : bool, default=False        When False, only the predictions of estimators will be used as        training data for `final_estimator`. When True, the        `final_estimator` is trained on the predictions as well as the        original training data.</ins>     Attributes     ----------     estimators_ : list of estimators


Question: """     def __init__(self, estimators, final_estimator=None, cv=None,                 stack_method='auto', n_jobs=None, verbose=0):                 stack_method='auto', n_jobs=None, passthrough=False,                 verbose=0):         super().__init__(             estimators=estimators,             final_estimator=final_estimator,             cv=cv,             stack_method=stack_method,             n_jobs=n_jobs,            passthrough=passthrough,             verbose=verbose         )


Question: `None` means 1 unless in a `joblib.parallel_backend` context. -1 means         using all processors. See Glossary for more details. <ins>    passthrough : bool, default=False        When False, only the predictions of estimators will be used as        training data for `final_estimator`. When True, the        `final_estimator` is trained on the predictions as well as the        original training data.</ins>     Attributes     ----------     estimators_ : list of estimator


Question: """     def __init__(self, estimators, final_estimator=None, cv=None, n_jobs=None,                 verbose=0):                 passthrough=False, verbose=0):         super().__init__(             estimators=estimators,             final_estimator=final_estimator,             cv=cv,             stack_method="predict",             n_jobs=n_jobs,            passthrough=passthrough,             verbose=verbose         )


Question: elif self.imputation_order == 'ascending':             n = len(frac_of_missing_values) - len(missing_values_idx)             ordered_idx = np.argsort(frac_of_missing_values,                                     kind='mergesort')[n:][::-1]                                     kind='mergesort')[n:]         elif self.imputation_order == 'descending':             n = len(frac_of_missing_values) - len(missing_values_idx)             ordered_idx = np.argsort(frac_of_missing_values,                                     kind='mergesort')[n:]                                     kind='mergesort')[n:][::-1]         elif self.imputation_order == 'random':             ordered_idx = missing_values_idx             self.random_state_.shuffle(ordered_idx)

imputationorder "ascending" and "descending" are inverted in IterativeImputer ImputerTriplets in fitted imputationsequence lists are appended according to imputationorder, but order is inverted


Question: from ..utils import Bunch from ..utils import check_array from ..utils import check_random_state<ins>from ..utils.validation import _check_sample_weight</ins> from ..utils import compute_sample_weight from ..utils.multiclass import check_classification_targets from ..utils.validation import check_is_fitted

Use checksampleweight to consistently validate sampleweight We recently introduced which returns a validated array. We should use it consistently throughout the code base, instead of relying on custom and adhoc checks like or (which are now handled by ). Here's a list of the estimators/functions that could make use of it (mostly in or ): [x] CalibratedClassifierCV [x] DBSCAN [x] DummyClassifier [x] DummyRegressor [x] BaseBagging [x] BaseForest [x] BaseGradientBoosting [x] IsotonicRegression [x] KernelRidge [x] GaussianNB [x] BaseDiscreteNB [x] KernelDensity [x] BaseDecisionTree (I left-out the linearmodel module because it seems more involved there) Could be a decent sprint issue ? To know where a given class is defined, use e.g.


Question: "or larger than 1").format(max_leaf_nodes))          if sample_weight is not None:            if (getattr(sample_weight, "dtype", None) != DOUBLE or                    not sample_weight.flags.contiguous):                sample_weight = np.ascontiguousarray(                    sample_weight, dtype=DOUBLE)            if len(sample_weight.shape) > 1:                raise ValueError("Sample weights array has more "                                 "than one dimension: %d" %                                 len(sample_weight.shape))            if len(sample_weight) != n_samples:                raise ValueError("Number of weights=%d does not match "                                 "number of samples=%d" %                                 (len(sample_weight), n_samples))            sample_weight = _check_sample_weight(sample_weight, X, DOUBLE)          if expanded_class_weight is not None:             if sample_weight is not None:


Question: unconverged = (np.sum((se == convergence_iter) + (se == 0))                            != n_samples)             if (not unconverged and (K > 0)) or (it == max_iter):                never_converged = False                 if verbose:                     print("Converged after %d iterations." % it)                 break     else:        never_converged = True         if verbose:             print("Did not converge")      I = np.flatnonzero(E)     K = I.size  # Identify exemplars     if K > 0:    if K > 0 and not never_converged:         c = np.argmax(S[:, I], axis=1)         c[I] = np.arange(K)  # Identify clusters         # Refine the final set of exemplars and clusters and return results

Return values of non converged affinity propagation clustering The affinity propagation Documentation states: "When the algorithm does not converge, it returns an empty array as clustercenterindices and -1 as label for each training sample." Example: I would expect that the clustering here (which does not converge) prints first an empty List and then [-1,-1,-1], however, I get [2] as cluster center and [0,0,0] as cluster labels. The only way I currently know if the clustering fails is if I use the verbose option, however that is very unhandy. A hacky solution is to check if maxiter == niter but it could have converged exactly 15 iterations before maxiter (although unlikely). I am not sure if this is intended behavior and the documentation is wrong? For my use-case within a bigger script, I would prefer to get back -1 values or have a property to check if it has converged, as otherwise, a user might not be aware that the clustering never converged. System: python: 3.6.7 (default, Nov 21 2018, 02:32:25) [GCC 4.8.2 (Red Hat 4.8.2-15)] executable: /home/jenniferh/Programs/anaconda3/envs/TFRDKit119/bin/python machine: Linux-4.15.0-52-generic-x8664-with-debian-stretch-sid BLAS: macros: SCIPYMKLH=None, HAVECBLAS=None libdirs: /home/jenniferh/Programs/anaconda3/envs/TFRDKit119/lib cblaslibs: mkl_rt, pthread Python deps: pip: 18.1 setuptools: 40.6.3 sklearn: 0.20.3 numpy: 1.15.4 scipy: 1.2.0 Cython: 0.29.2 pandas: 0.23.4


Question: Cluster labels.         """         check_is_fitted(self)<ins>        X = check_array(X)</ins>         if not hasattr(self, "cluster_centers_"):             raise ValueError("Predict method is not supported when "                              "affinity='precomputed'.")


Question: def _estimator_type(self):         return self.estimator._estimator_type <ins>    @property    def _pairwise(self):        # allows cross-validation to see 'precomputed' metrics        return getattr(self.estimator, '_pairwise', False)</ins>     def score(self, X, y=None):         """Returns the score on the given data, if the estimator has been refit.

Nested Cross Validation for precomputed KNN A nested cross validation prediction using a knn with precomputed metric raised an error Should return the predictions made by the model as the following code produces: sklearn 0.20.2


Question: The predicted labels.     """     labels_true = check_array(        labels_true, ensure_2d=False, ensure_min_samples=0        labels_true, ensure_2d=False, ensure_min_samples=0, dtype=None,     )     labels_pred = check_array(        labels_pred, ensure_2d=False, ensure_min_samples=0        labels_pred, ensure_2d=False, ensure_min_samples=0, dtype=None,     )      # input checks

regression in input validation of clustering metrics ValueError: could not convert string to float: 'b' while works with a warning? this worked in 0.21.1 without a warning (as I think it should) Edit by I removed the in the second code snippet.


Question: return _weighted_sum(score, sample_weight, normalize)  def confusion_matrix(y_true, y_pred, labels=None, sample_weight=None):    """Compute confusion matrix to evaluate the accuracy of a classificationdef confusion_matrix(y_true, y_pred, labels=None, sample_weight=None,                     normalize=None):    """Compute confusion matrix to evaluate the accuracy of a classification.      By definition a confusion matrix :math:`C` is such that :math:`C_{i, j}`     is equal to the number of observations known to be in group :math:`i` and

ENH: add normalize parameter to metrics.classification.confusionmatrix Allows to get a normalized confusion matrix directly from the function call. I use frequently and find the need to always normalize the matrix manually maybe unnecessary. I am aware of the fact that other functions like already have this exact functionality implemented, so probably the lack of the parameter is intentional and I'm missing the why. But in case its not intentional you might find this contribution useful :).


Question: Parameters     ----------    y_true : array, shape = [n_samples]    y_true : array-like of shape (n_samples,)         Ground truth (correct) target values.     y_pred : array, shape = [n_samples]    y_pred : array-like of shape (n_samples,)         Estimated targets as returned by a classifier.     labels : array, shape = [n_classes], optional    labels : array-like of shape (n_classes), default=None         List of labels to index the matrix. This may be used to reorder         or select a subset of labels.        If none is given, those that appear at least once        If ``None`` is given, those that appear at least once         in ``y_true`` or ``y_pred`` are used in sorted order.      sample_weight : array-like of shape (n_samples,), default=None         Sample weights.     normalize : {'true', 'pred', 'all'}, default=None        Normalizes confusion matrix over the true (rows), predicted (columns)        conditions or all the population. If None, confusion matrix will not be        normalized.     Returns     -------     C : ndarray of shape (n_classes, n_classes)        Confusion matrix        Confusion matrix.      References     ----------


Question: else:         dtype = np.float64     CM = coo_matrix((sample_weight, (y_true, y_pred)),    cm = coo_matrix((sample_weight, (y_true, y_pred)),                     shape=(n_labels, n_labels), dtype=dtype,                     ).toarray()     return CM    with np.errstate(all='ignore'):        if normalize == 'true':            cm = cm / cm.sum(axis=1, keepdims=True)        elif normalize == 'pred':            cm = cm / cm.sum(axis=0, keepdims=True)        elif normalize == 'all':            cm = cm / cm.sum()        cm = np.nan_to_num(cm)    return cm   def multilabel_confusion_matrix(y_true, y_pred, sample_weight=None,diff --git a/sklearn/metrics/_plot/confusion_matrix.py b/sklearn/metrics/_plot/confusion_matrix.py-- a/sklearn/metrics/_plot/confusion_matrix.py++ b/sklearn/metrics/_plot/confusion_matrix.py


Question: Includes values in confusion matrix.      normalize : {'true', 'pred', 'all'}, default=None        Normalizes confusion matrix over the true (rows), predicited (columns)        Normalizes confusion matrix over the true (rows), predicted (columns)         conditions or all the population. If None, confusion matrix will not be         normalized.


Question: y_pred = estimator.predict(X)     cm = confusion_matrix(y_true, y_pred, sample_weight=sample_weight,                          labels=labels)    if normalize == 'true':        cm = cm / cm.sum(axis=1, keepdims=True)    elif normalize == 'pred':        cm = cm / cm.sum(axis=0, keepdims=True)    elif normalize == 'all':        cm = cm / cm.sum()                          labels=labels, normalize=normalize)      if display_labels is None:         if labels is None:


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

LabelPropagation raises TypeError: A sparse matrix was passed LabelPropagation (and LabelSpreading) error out for sparse matrices. Sparse case should work as does the dense one. Changing in line 224 to seems to fix the problem for me (BTW: a similar check accepting sparse matrices is done in BaseLabelPropagations predictproba at line 189). This fix also heals LabelSpreading. FIX LabelPropagation handling of sparce matrices Label propagation and spreading allow to classify using sparse data according to documentation. Tests only covered the dense case. Newly coverage for sparse matrices allows to reproduce the problem in . The proposed fix in works for the extended tests. Supporting scipy's dokmatrix produces the UserWarning "Can't check dok sparse matrix for nan or inf.". So this format seems to be unsuitable? fails for sparse matrices


Question: Returns the instance itself.         """         self._validate_params()        X, y = self._validate_data(X, y)        X, y = self._validate_data(            X,            y,            accept_sparse=["csr", "csc"],            reset=True,        )         self.X_ = X         check_classification_targets(y)


Question: Attributes     ----------    X_ : ndarray of shape (n_samples, n_features)    X_ : {array-like, sparse matrix} of shape (n_samples, n_features)         Input array.      classes_ : ndarray of shape (n_classes,)


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


Question: which might cause predictions to change if the data is modified         externally. <ins>    n_targets : int, default=None        The number of dimensions of the target values. Used to decide the number        of outputs when sampling from the prior distributions (i.e. calling        :meth:`sample_y` before :meth:`fit`). This parameter is ignored once        :meth:`fit` has been called.        .. versionadded:: 1.3</ins>     random_state : int, RandomState instance or None, default=None         Determines random number generation used to initialize the centers.         Pass an int for reproducible results across multiple function calls.

GPR enforce before calling In , sampling in the prior before calling via will assume that is made of a single target. However, this is not necessarily the case. Therefore, the shape of the output of before and after is different. In order to solve this inconsistency, we need to introduce a new parameter . Before calling this parameter should be explicitly set by the user. After , we can use the information of the target seen during without explicitly setting the parameter.


Question: "n_restarts_optimizer": [Interval(Integral, 0, None, closed="left")],         "normalize_y": ["boolean"],         "copy_X_train": ["boolean"],<ins>        "n_targets": [Interval(Integral, 1, None, closed="left"), None],</ins>         "random_state": ["random_state"],     }


Question: n_restarts_optimizer=0,         normalize_y=False,         copy_X_train=True,<ins>        n_targets=None,</ins>         random_state=None,     ):         self.kernel = kernel


Question: self.n_restarts_optimizer = n_restarts_optimizer         self.normalize_y = normalize_y         self.copy_X_train = copy_X_train<ins>        self.n_targets = n_targets</ins>         self.random_state = random_state      def fit(self, X, y):


Question: dtype=dtype,         ) <ins>        n_targets_seen = y.shape[1] if y.ndim > 1 else 1        if self.n_targets is not None and n_targets_seen != self.n_targets:            raise ValueError(                "The number of targets seen in `y` is different from the parameter "                f"`n_targets`. Got {n_targets_seen} != {self.n_targets}."            )</ins>         # Normalize target value         if self.normalize_y:             self._y_train_mean = np.mean(y, axis=0)