Question: returnintercept==True in ridgeregression raises an exception <!-- 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--<!-- Example: No error is thrown. Please paste or describe the expected results.--(the values can differ, but at least no exception should be raised) <!-- Please paste or specifically describe the actual output or traceback. --<!-- 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) --<!-- Thanks for contributing! --

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


Question: crossvalpredict returns bad prediction when evaluated on a dataset with very few samples returns bad prediction when evaluated on a dataset with very few samples on 1 class, causing class being ignored on some CV splits. Verified on the scikit latest dev version.

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


Question: Confusing pretty print repr for nested Pipeline Taking the examples from the docs (https://scikit-) that involves some nested pipelines in columntransformer in pipeline The repr that you get for this pipeline: which I found very confusing: the outer pipeline seems to have only 1 step (the 'preprocessor', as the 'classifier' disappeared in the ). It's probably certainly not easy to get a good repr in all cases, and for sure the old behaviour was even worse (it would show the first 'imputer' step of the pipeline inside the column transformer as if it was the second step of the outer pipeline ..). But just opening this issue as a data point for possible improvements. Without knowing how the current repr is determined: ideally I would expect that, if the full repr is too long, we first try to trim it step per step of the outer pipeline, so that the structure of that outer pipeline is still visible. But that is easier to write than to code .. :) cc

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


Question: Confusing pretty print repr for nested Pipeline Taking the examples from the docs (https://scikit-) that involves some nested pipelines in columntransformer in pipeline The repr that you get for this pipeline: which I found very confusing: the outer pipeline seems to have only 1 step (the 'preprocessor', as the 'classifier' disappeared in the ). It's probably certainly not easy to get a good repr in all cases, and for sure the old behaviour was even worse (it would show the first 'imputer' step of the pipeline inside the column transformer as if it was the second step of the outer pipeline ..). But just opening this issue as a data point for possible improvements. Without knowing how the current repr is determined: ideally I would expect that, if the full repr is too long, we first try to trim it step per step of the outer pipeline, so that the structure of that outer pipeline is still visible. But that is easier to write than to code .. :) cc

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


Question: Confusing pretty print repr for nested Pipeline Taking the examples from the docs (https://scikit-) that involves some nested pipelines in columntransformer in pipeline The repr that you get for this pipeline: which I found very confusing: the outer pipeline seems to have only 1 step (the 'preprocessor', as the 'classifier' disappeared in the ). It's probably certainly not easy to get a good repr in all cases, and for sure the old behaviour was even worse (it would show the first 'imputer' step of the pipeline inside the column transformer as if it was the second step of the outer pipeline ..). But just opening this issue as a data point for possible improvements. Without knowing how the current repr is determined: ideally I would expect that, if the full repr is too long, we first try to trim it step per step of the outer pipeline, so that the structure of that outer pipeline is still visible. But that is easier to write than to code .. :) cc

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


Question: labelrankingaverageprecisionscore: sampleweighting isn't applied to items with zero true labels labelrankingaverageprecisionscore offers a sampleweighting argument to allow nonuniform contribution of individual samples to the reported metric. Separately, individual samples whose labels are the same for all classes (all true or all false) are treated as a special case (precision == 1, ). However, this special case bypasses the application of sampleweight (). So, in the case where there is both non-default sampleweighting and samples with, for instance, zero labels, the reported metric is wrong. <!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--See example in Average of AP of first and second samples = 0.625 Sum of AP of all three samples, divided by sum of weighting vector = 2.25/2 = 1.125 System: python: 3.6.7 (default, Oct 22 2018, 11:32:17) [GCC 8.2.0] executable: /usr/bin/python3 machine: Linux-4.14.79+-x8664-with-Ubuntu-18.04-bionic BLAS: macros: SCIPYMKLH=None, HAVECBLAS=None libdirs: /usr/local/lib cblaslibs: mklrt, pthread Python deps: pip: 19.0.3 setuptools: 40.8.0 sklearn: 0.20.3 numpy: 1.14.6 scipy: 1.1.0 Cython: 0.29.6 pandas: 0.22.0 <!-- Thanks for contributing! --

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


Question: Confusing error message in OrdinalEncoder when passing single list of categories Small example: The error message is still using the old , which makes it very confusing. (another issue is that we might be able to actually detect this case)

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


Question: Implement RMSE (root-mean-square error) metric and scorer RMSE seems to be a popular metric but now one has to calculate it through `. Wiki page:

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


Question: Implement RMSE (root-mean-square error) metric and scorer RMSE seems to be a popular metric but now one has to calculate it through `. Wiki page:

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


Question: Implement RMSE (root-mean-square error) metric and scorer RMSE seems to be a popular metric but now one has to calculate it through `. Wiki page:

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


Question: Implement RMSE (root-mean-square error) metric and scorer RMSE seems to be a popular metric but now one has to calculate it through `. Wiki page:

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


Question: Implement RMSE (root-mean-square error) metric and scorer RMSE seems to be a popular metric but now one has to calculate it through `. Wiki page:

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


Question: Implement RMSE (root-mean-square error) metric and scorer RMSE seems to be a popular metric but now one has to calculate it through `. Wiki page:

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


Question: GradientBoostingRegressor initial estimator does not play together with Pipeline Using a pipeline as the initial estimator of GradientBoostingRegressor doesn't work due to incompatible signatures. The signature of is which cannot be called with three positional arguments as above. So I guess line 1421 in should read instead and the issue is solved. Right?

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


Question: Be more tolerant in checkarray for CalibratedClassifierCV For our package , the function is very convenient for Weakly Supervised Learners, as it can make PairsClassifier estimators return a probability for a pair of points to be labeled as similar or dissimilar, when those return a decision function. However, we currently cannot use it because our inputs can be 3D (example: ), and uses with default parameters that does not allow 3D inputs. However, other meta-estimators like do not call , so we can use them easily in metric-learn. Is the in really useful or could we do without it ? If we could, I'd be happy to provide a PR to do so

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


Question: Expose warmstart in Isolation forest It seems to me that supports incremental addition of new trees with the parameter of its parent class, . Even though this parameter is not exposed in , it gets inherited from and one can use it by changing it to after initialization. To make it work, you have to also increment on every iteration. It took me a while to notice that it actually works, and I had to inspect the source code of both and . Also, it looks to me that the behavior is in-line with that is behind e.g. . To make it more easier to use, I'd suggest to: expose in , default ; document it in the same way as it is documented for , i.e. say: add a test to make sure it works properly; possibly also mention in the "IsolationForest example" documentation entry;

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


Question: Expose warmstart in Isolation forest It seems to me that supports incremental addition of new trees with the parameter of its parent class, . Even though this parameter is not exposed in , it gets inherited from and one can use it by changing it to after initialization. To make it work, you have to also increment on every iteration. It took me a while to notice that it actually works, and I had to inspect the source code of both and . Also, it looks to me that the behavior is in-line with that is behind e.g. . To make it more easier to use, I'd suggest to: expose in , default ; document it in the same way as it is documented for , i.e. say: add a test to make sure it works properly; possibly also mention in the "IsolationForest example" documentation entry;

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


Question: Expose warmstart in Isolation forest It seems to me that supports incremental addition of new trees with the parameter of its parent class, . Even though this parameter is not exposed in , it gets inherited from and one can use it by changing it to after initialization. To make it work, you have to also increment on every iteration. It took me a while to notice that it actually works, and I had to inspect the source code of both and . Also, it looks to me that the behavior is in-line with that is behind e.g. . To make it more easier to use, I'd suggest to: expose in , default ; document it in the same way as it is documented for , i.e. say: add a test to make sure it works properly; possibly also mention in the "IsolationForest example" documentation entry;

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


Question: Comparing string to array in estimatemi In ` but discrete features can be an array of indices or a boolean mask. This will error in future versions of numpy. Also this means we never test this function with discrete features != 'auto', it seems?

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


Question: Comparing string to array in estimatemi In ` but discrete features can be an array of indices or a boolean mask. This will error in future versions of numpy. Also this means we never test this function with discrete features != 'auto', it seems?

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


Question: improve error message when passing sampleweight to Pipeline Many estimators take a parameter named . does not, since it wants its parameters to be prefixed by the step name with a delimiter: This error message is not friendly enough. It should explicitly describe the correct format for passing to a step in a Pipeline.

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


Question: improve error message when passing sampleweight to Pipeline Many estimators take a parameter named . does not, since it wants its parameters to be prefixed by the step name with a delimiter: This error message is not friendly enough. It should explicitly describe the correct format for passing to a step in a Pipeline.

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


Question: Stratified subsampler utility? I have some data and that I want to subsample (i.e. only keep a subset of the samples) in a stratified way. Using something like is almost what I need. But that will error if: I happen to want exactly samples () I want something close to which is not enough to have a stratified test or train set () Basically what I need is a option to , that's probably the most appropriate place to introduce this.

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


Question: Stratified subsampler utility? I have some data and that I want to subsample (i.e. only keep a subset of the samples) in a stratified way. Using something like is almost what I need. But that will error if: I happen to want exactly samples () I want something close to which is not enough to have a stratified test or train set () Basically what I need is a option to , that's probably the most appropriate place to introduce this.

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


Question: Stratified subsampler utility? I have some data and that I want to subsample (i.e. only keep a subset of the samples) in a stratified way. Using something like is almost what I need. But that will error if: I happen to want exactly samples () I want something close to which is not enough to have a stratified test or train set () Basically what I need is a option to , that's probably the most appropriate place to introduce this.

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


Question: Stratified subsampler utility? I have some data and that I want to subsample (i.e. only keep a subset of the samples) in a stratified way. Using something like is almost what I need. But that will error if: I happen to want exactly samples () I want something close to which is not enough to have a stratified test or train set () Basically what I need is a option to , that's probably the most appropriate place to introduce this.

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


Question: Stratified subsampler utility? I have some data and that I want to subsample (i.e. only keep a subset of the samples) in a stratified way. Using something like is almost what I need. But that will error if: I happen to want exactly samples () I want something close to which is not enough to have a stratified test or train set () Basically what I need is a option to , that's probably the most appropriate place to introduce this.

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


Question: Stratified subsampler utility? I have some data and that I want to subsample (i.e. only keep a subset of the samples) in a stratified way. Using something like is almost what I need. But that will error if: I happen to want exactly samples () I want something close to which is not enough to have a stratified test or train set () Basically what I need is a option to , that's probably the most appropriate place to introduce this.

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


Question: Numerical precision of euclideandistances with float32 <!-- Instructions For Filing a Bug: --I noticed that sklearn.metrics.pairwise.pairwisedistances function agrees with when using np.float64 arrays, but disagrees when using np.float32 arrays. See the code snippet below. I expect that the results from sklearn.metrics.pairwise.pairwisedistances would agree with for both 64-bit and 32-bit. In other words, I expect the following output: The code snippet above produces the following output for me: [WIP] Stable and fast float32 implementation of euclideandistances Superseds PR These commits implement a block-wise casting to float64 and uses the older code to compute the euclidean distance matrix on the blocks. This is done useing only a fixed amount of additional (temporary) memory. This code implements several optimizations: since the distance matrix is symmetric when , copy the blocks of the upper triangle to the lower triangle; compute the optimal block size that would use most of the allowed additional memory; cast blocks of to float64; precompute blocks of if not given so it gets reused through the iterations over ; swap and when is given, but not . Note that all the optimizations listed here have proven useful in a benchmark. The hardcoded amount of additional memory of 10MB is also derived from a benchmark. As a side bonus, this implementation should also support float16 out of the box, should scikit-learn support it at some point. Add a test for numeric precision (see ) Surprisingly bad precision, isn't it? Note that the traditional computation sqrt(sum((x-y)*2)) gets the results exact. <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: --<!-- Example: See also . Please use keywords (e.g., Fixes) to create link to the issues or pull requests you resolved, so that they will automatically be closed when your pull request is merged. See --<!-- 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! --

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


Question: Numerical precision of euclideandistances with float32 <!-- Instructions For Filing a Bug: --I noticed that sklearn.metrics.pairwise.pairwisedistances function agrees with when using np.float64 arrays, but disagrees when using np.float32 arrays. See the code snippet below. I expect that the results from sklearn.metrics.pairwise.pairwisedistances would agree with for both 64-bit and 32-bit. In other words, I expect the following output: The code snippet above produces the following output for me: [WIP] Stable and fast float32 implementation of euclideandistances Superseds PR These commits implement a block-wise casting to float64 and uses the older code to compute the euclidean distance matrix on the blocks. This is done useing only a fixed amount of additional (temporary) memory. This code implements several optimizations: since the distance matrix is symmetric when , copy the blocks of the upper triangle to the lower triangle; compute the optimal block size that would use most of the allowed additional memory; cast blocks of to float64; precompute blocks of if not given so it gets reused through the iterations over ; swap and when is given, but not . Note that all the optimizations listed here have proven useful in a benchmark. The hardcoded amount of additional memory of 10MB is also derived from a benchmark. As a side bonus, this implementation should also support float16 out of the box, should scikit-learn support it at some point. Add a test for numeric precision (see ) Surprisingly bad precision, isn't it? Note that the traditional computation sqrt(sum((x-y)*2)) gets the results exact. <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: --<!-- Example: See also . Please use keywords (e.g., Fixes) to create link to the issues or pull requests you resolved, so that they will automatically be closed when your pull request is merged. See --<!-- 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! --

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


Question: Numerical precision of euclideandistances with float32 <!-- Instructions For Filing a Bug: --I noticed that sklearn.metrics.pairwise.pairwisedistances function agrees with when using np.float64 arrays, but disagrees when using np.float32 arrays. See the code snippet below. I expect that the results from sklearn.metrics.pairwise.pairwisedistances would agree with for both 64-bit and 32-bit. In other words, I expect the following output: The code snippet above produces the following output for me: [WIP] Stable and fast float32 implementation of euclideandistances Superseds PR These commits implement a block-wise casting to float64 and uses the older code to compute the euclidean distance matrix on the blocks. This is done useing only a fixed amount of additional (temporary) memory. This code implements several optimizations: since the distance matrix is symmetric when , copy the blocks of the upper triangle to the lower triangle; compute the optimal block size that would use most of the allowed additional memory; cast blocks of to float64; precompute blocks of if not given so it gets reused through the iterations over ; swap and when is given, but not . Note that all the optimizations listed here have proven useful in a benchmark. The hardcoded amount of additional memory of 10MB is also derived from a benchmark. As a side bonus, this implementation should also support float16 out of the box, should scikit-learn support it at some point. Add a test for numeric precision (see ) Surprisingly bad precision, isn't it? Note that the traditional computation sqrt(sum((x-y)*2)) gets the results exact. <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: --<!-- Example: See also . Please use keywords (e.g., Fixes) to create link to the issues or pull requests you resolved, so that they will automatically be closed when your pull request is merged. See --<!-- 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! --

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


Question: Numerical precision of euclideandistances with float32 <!-- Instructions For Filing a Bug: --I noticed that sklearn.metrics.pairwise.pairwisedistances function agrees with when using np.float64 arrays, but disagrees when using np.float32 arrays. See the code snippet below. I expect that the results from sklearn.metrics.pairwise.pairwisedistances would agree with for both 64-bit and 32-bit. In other words, I expect the following output: The code snippet above produces the following output for me: [WIP] Stable and fast float32 implementation of euclideandistances Superseds PR These commits implement a block-wise casting to float64 and uses the older code to compute the euclidean distance matrix on the blocks. This is done useing only a fixed amount of additional (temporary) memory. This code implements several optimizations: since the distance matrix is symmetric when , copy the blocks of the upper triangle to the lower triangle; compute the optimal block size that would use most of the allowed additional memory; cast blocks of to float64; precompute blocks of if not given so it gets reused through the iterations over ; swap and when is given, but not . Note that all the optimizations listed here have proven useful in a benchmark. The hardcoded amount of additional memory of 10MB is also derived from a benchmark. As a side bonus, this implementation should also support float16 out of the box, should scikit-learn support it at some point. Add a test for numeric precision (see ) Surprisingly bad precision, isn't it? Note that the traditional computation sqrt(sum((x-y)*2)) gets the results exact. <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: --<!-- Example: See also . Please use keywords (e.g., Fixes) to create link to the issues or pull requests you resolved, so that they will automatically be closed when your pull request is merged. See --<!-- 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! --

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


Question: Numerical precision of euclideandistances with float32 <!-- Instructions For Filing a Bug: --I noticed that sklearn.metrics.pairwise.pairwisedistances function agrees with when using np.float64 arrays, but disagrees when using np.float32 arrays. See the code snippet below. I expect that the results from sklearn.metrics.pairwise.pairwisedistances would agree with for both 64-bit and 32-bit. In other words, I expect the following output: The code snippet above produces the following output for me: [WIP] Stable and fast float32 implementation of euclideandistances Superseds PR These commits implement a block-wise casting to float64 and uses the older code to compute the euclidean distance matrix on the blocks. This is done useing only a fixed amount of additional (temporary) memory. This code implements several optimizations: since the distance matrix is symmetric when , copy the blocks of the upper triangle to the lower triangle; compute the optimal block size that would use most of the allowed additional memory; cast blocks of to float64; precompute blocks of if not given so it gets reused through the iterations over ; swap and when is given, but not . Note that all the optimizations listed here have proven useful in a benchmark. The hardcoded amount of additional memory of 10MB is also derived from a benchmark. As a side bonus, this implementation should also support float16 out of the box, should scikit-learn support it at some point. Add a test for numeric precision (see ) Surprisingly bad precision, isn't it? Note that the traditional computation sqrt(sum((x-y)*2)) gets the results exact. <!-- Thanks for contributing a pull request! Please ensure you have taken a look at the contribution guidelines: --<!-- Example: See also . Please use keywords (e.g., Fixes) to create link to the issues or pull requests you resolved, so that they will automatically be closed when your pull request is merged. See --<!-- 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! --

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


Question: Allow setting of initial hyperparameters of BayesianRidge <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--I propose to be able to set initial values of the hyperparameters (alpha, lambda) in BayesianRidge().fit. I tried to fit a sinusoidal curve with polynomials by Bayesian ridge regression, but the default initial values did not work well (left figure). So, I corrected the fit method of the BayesianRidge class so that I could set the initial value, and the regression worked well (right figure). ! <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --The code I wrote is Here. <!-- Example: No error is thrown. Please paste or describe the expected results.--The right figure <!-- Please paste or specifically describe the actual output or traceback. --The left figure <!-- 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) --System: python: 3.6.6 (default, Mar 8 2019, 18:24:30) [GCC 7.3.0] executable: /home/*/.pyenv/versions/3.6.6/bin/python machine: Linux-4.15.0-47-generic-x8664-with-debian-buster-sid BLAS: macros: NOATLASINFO=1, HAVECBLAS=None libdirs: /usr/lib/x8664-linux-gnu cblaslibs: cblas Python deps: pip: 19.0.3 setuptools: 41.0.0 sklearn: 0.20.3 numpy: 1.16.2 scipy: 1.2.1 Cython: 0.29.6 pandas: 0.24.2 <!-- Thanks for contributing! --

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


Question: Allow setting of initial hyperparameters of BayesianRidge <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--I propose to be able to set initial values of the hyperparameters (alpha, lambda) in BayesianRidge().fit. I tried to fit a sinusoidal curve with polynomials by Bayesian ridge regression, but the default initial values did not work well (left figure). So, I corrected the fit method of the BayesianRidge class so that I could set the initial value, and the regression worked well (right figure). ! <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --The code I wrote is Here. <!-- Example: No error is thrown. Please paste or describe the expected results.--The right figure <!-- Please paste or specifically describe the actual output or traceback. --The left figure <!-- 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) --System: python: 3.6.6 (default, Mar 8 2019, 18:24:30) [GCC 7.3.0] executable: /home/*/.pyenv/versions/3.6.6/bin/python machine: Linux-4.15.0-47-generic-x8664-with-debian-buster-sid BLAS: macros: NOATLASINFO=1, HAVECBLAS=None libdirs: /usr/lib/x8664-linux-gnu cblaslibs: cblas Python deps: pip: 19.0.3 setuptools: 41.0.0 sklearn: 0.20.3 numpy: 1.16.2 scipy: 1.2.1 Cython: 0.29.6 pandas: 0.24.2 <!-- Thanks for contributing! --

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


Question: Allow setting of initial hyperparameters of BayesianRidge <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--I propose to be able to set initial values of the hyperparameters (alpha, lambda) in BayesianRidge().fit. I tried to fit a sinusoidal curve with polynomials by Bayesian ridge regression, but the default initial values did not work well (left figure). So, I corrected the fit method of the BayesianRidge class so that I could set the initial value, and the regression worked well (right figure). ! <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --The code I wrote is Here. <!-- Example: No error is thrown. Please paste or describe the expected results.--The right figure <!-- Please paste or specifically describe the actual output or traceback. --The left figure <!-- 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) --System: python: 3.6.6 (default, Mar 8 2019, 18:24:30) [GCC 7.3.0] executable: /home/*/.pyenv/versions/3.6.6/bin/python machine: Linux-4.15.0-47-generic-x8664-with-debian-buster-sid BLAS: macros: NOATLASINFO=1, HAVECBLAS=None libdirs: /usr/lib/x8664-linux-gnu cblaslibs: cblas Python deps: pip: 19.0.3 setuptools: 41.0.0 sklearn: 0.20.3 numpy: 1.16.2 scipy: 1.2.1 Cython: 0.29.6 pandas: 0.24.2 <!-- Thanks for contributing! --

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


Question: Allow setting of initial hyperparameters of BayesianRidge <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--I propose to be able to set initial values of the hyperparameters (alpha, lambda) in BayesianRidge().fit. I tried to fit a sinusoidal curve with polynomials by Bayesian ridge regression, but the default initial values did not work well (left figure). So, I corrected the fit method of the BayesianRidge class so that I could set the initial value, and the regression worked well (right figure). ! <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --The code I wrote is Here. <!-- Example: No error is thrown. Please paste or describe the expected results.--The right figure <!-- Please paste or specifically describe the actual output or traceback. --The left figure <!-- 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) --System: python: 3.6.6 (default, Mar 8 2019, 18:24:30) [GCC 7.3.0] executable: /home/*/.pyenv/versions/3.6.6/bin/python machine: Linux-4.15.0-47-generic-x8664-with-debian-buster-sid BLAS: macros: NOATLASINFO=1, HAVECBLAS=None libdirs: /usr/lib/x8664-linux-gnu cblaslibs: cblas Python deps: pip: 19.0.3 setuptools: 41.0.0 sklearn: 0.20.3 numpy: 1.16.2 scipy: 1.2.1 Cython: 0.29.6 pandas: 0.24.2 <!-- Thanks for contributing! --

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


Question: Allow setting of initial hyperparameters of BayesianRidge <!-- If your issue is a usage question, submit it here instead: StackOverflow with the scikit-learn tag: Mailing List: For more information, see User Questions: http://scikit- --<!-- Instructions For Filing a Bug: --<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluateevery 0--I propose to be able to set initial values of the hyperparameters (alpha, lambda) in BayesianRidge().fit. I tried to fit a sinusoidal curve with polynomials by Bayesian ridge regression, but the default initial values did not work well (left figure). So, I corrected the fit method of the BayesianRidge class so that I could set the initial value, and the regression worked well (right figure). ! <!-- Example: If the code is too long, feel free to put it in a public gist and link it in the issue: --The code I wrote is Here. <!-- Example: No error is thrown. Please paste or describe the expected results.--The right figure <!-- Please paste or specifically describe the actual output or traceback. --The left figure <!-- 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) --System: python: 3.6.6 (default, Mar 8 2019, 18:24:30) [GCC 7.3.0] executable: /home/*/.pyenv/versions/3.6.6/bin/python machine: Linux-4.15.0-47-generic-x8664-with-debian-buster-sid BLAS: macros: NOATLASINFO=1, HAVECBLAS=None libdirs: /usr/lib/x8664-linux-gnu cblaslibs: cblas Python deps: pip: 19.0.3 setuptools: 41.0.0 sklearn: 0.20.3 numpy: 1.16.2 scipy: 1.2.1 Cython: 0.29.6 pandas: 0.24.2 <!-- Thanks for contributing! --

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


Question: Bug in Gradient Boosting: Feature Importances do not sum to 1 I found conditions when Feature Importance values do not add up to 1 in ensemble tree methods, like Gradient Boosting Trees or AdaBoost Trees. This error occurs once the ensemble reaches a large number of estimators. The exact conditions depend variously. For example, the error shows up sooner with a smaller amount of training samples. Or, if the depth of the tree is large. When this error appears, the predicted value seems to have converged. But it’s unclear if the error is causing the predicted value not to change with more estimators. In fact, the feature importance sum goes lower and lower with more estimators thereafter. Consequently, it's questionable if the tree ensemble code is functioning as expected. Here's sample code to reproduce this: Output: In fact, if we examine the tree at each staged prediction, we'll see that the feature importance goes to 0 after we hit a certain number of estimators. (For the code above, it's 712.) Here's code to describe what I mean: Output: I wonder if we’re hitting some floating point calculation error. BTW, I've posted this issue on the mailing list . There aren't a lot of discussion, but others seem to think there's a bug here too. Hope we can get this fixed or clarified. Thank you! -Doug Windows-7;'Python', '2.7.9 ;'NumPy', '1.9.2';'SciPy', '0.15.1';'Scikit-Learn', '0.16.1'

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


Question: brierscoreloss error Hello. I think I found a mistake in brierscoreloss. When you have a target = 1 and a prediction = 1 too, brierscoreloss should be 0 (best result), but it gives 1. Why is it happening? Because checkbinaryprobabilisticpredictions gets target with only one class and convert it to 0. And metric calculates for target = 0 and prediction = 1. The same problem for target = 1 and prediction = 0. brierscoreloss is 0 (the best result), but it should be 1. Examples: Approx = [0, 0, 0, 0] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 0 Approx = [1, 1, 1, 1] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 1 Maybe we should fix it? Thank you.

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


Question: brierscoreloss error Hello. I think I found a mistake in brierscoreloss. When you have a target = 1 and a prediction = 1 too, brierscoreloss should be 0 (best result), but it gives 1. Why is it happening? Because checkbinaryprobabilisticpredictions gets target with only one class and convert it to 0. And metric calculates for target = 0 and prediction = 1. The same problem for target = 1 and prediction = 0. brierscoreloss is 0 (the best result), but it should be 1. Examples: Approx = [0, 0, 0, 0] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 0 Approx = [1, 1, 1, 1] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 1 Maybe we should fix it? Thank you.

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


Question: brierscoreloss error Hello. I think I found a mistake in brierscoreloss. When you have a target = 1 and a prediction = 1 too, brierscoreloss should be 0 (best result), but it gives 1. Why is it happening? Because checkbinaryprobabilisticpredictions gets target with only one class and convert it to 0. And metric calculates for target = 0 and prediction = 1. The same problem for target = 1 and prediction = 0. brierscoreloss is 0 (the best result), but it should be 1. Examples: Approx = [0, 0, 0, 0] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 0 Approx = [1, 1, 1, 1] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 1 Maybe we should fix it? Thank you.

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


Question: brierscoreloss error Hello. I think I found a mistake in brierscoreloss. When you have a target = 1 and a prediction = 1 too, brierscoreloss should be 0 (best result), but it gives 1. Why is it happening? Because checkbinaryprobabilisticpredictions gets target with only one class and convert it to 0. And metric calculates for target = 0 and prediction = 1. The same problem for target = 1 and prediction = 0. brierscoreloss is 0 (the best result), but it should be 1. Examples: Approx = [0, 0, 0, 0] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 0 Approx = [1, 1, 1, 1] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 1 Maybe we should fix it? Thank you.

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


Question: brierscoreloss error Hello. I think I found a mistake in brierscoreloss. When you have a target = 1 and a prediction = 1 too, brierscoreloss should be 0 (best result), but it gives 1. Why is it happening? Because checkbinaryprobabilisticpredictions gets target with only one class and convert it to 0. And metric calculates for target = 0 and prediction = 1. The same problem for target = 1 and prediction = 0. brierscoreloss is 0 (the best result), but it should be 1. Examples: Approx = [0, 0, 0, 0] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 0 Approx = [1, 1, 1, 1] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 1 Maybe we should fix it? Thank you.

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


Question: brierscoreloss error Hello. I think I found a mistake in brierscoreloss. When you have a target = 1 and a prediction = 1 too, brierscoreloss should be 0 (best result), but it gives 1. Why is it happening? Because checkbinaryprobabilisticpredictions gets target with only one class and convert it to 0. And metric calculates for target = 0 and prediction = 1. The same problem for target = 1 and prediction = 0. brierscoreloss is 0 (the best result), but it should be 1. Examples: Approx = [0, 0, 0, 0] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 0 Approx = [1, 1, 1, 1] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 1 Maybe we should fix it? Thank you.

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


Question: brierscoreloss error Hello. I think I found a mistake in brierscoreloss. When you have a target = 1 and a prediction = 1 too, brierscoreloss should be 0 (best result), but it gives 1. Why is it happening? Because checkbinaryprobabilisticpredictions gets target with only one class and convert it to 0. And metric calculates for target = 0 and prediction = 1. The same problem for target = 1 and prediction = 0. brierscoreloss is 0 (the best result), but it should be 1. Examples: Approx = [0, 0, 0, 0] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 0 Approx = [1, 1, 1, 1] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 1 Maybe we should fix it? Thank you.

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


Question: brierscoreloss error Hello. I think I found a mistake in brierscoreloss. When you have a target = 1 and a prediction = 1 too, brierscoreloss should be 0 (best result), but it gives 1. Why is it happening? Because checkbinaryprobabilisticpredictions gets target with only one class and convert it to 0. And metric calculates for target = 0 and prediction = 1. The same problem for target = 1 and prediction = 0. brierscoreloss is 0 (the best result), but it should be 1. Examples: Approx = [0, 0, 0, 0] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 0 Approx = [1, 1, 1, 1] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 1 Maybe we should fix it? Thank you.

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


Question: brierscoreloss error Hello. I think I found a mistake in brierscoreloss. When you have a target = 1 and a prediction = 1 too, brierscoreloss should be 0 (best result), but it gives 1. Why is it happening? Because checkbinaryprobabilisticpredictions gets target with only one class and convert it to 0. And metric calculates for target = 0 and prediction = 1. The same problem for target = 1 and prediction = 0. brierscoreloss is 0 (the best result), but it should be 1. Examples: Approx = [0, 0, 0, 0] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 0 Approx = [1, 1, 1, 1] Target = [1, 1, 1, 1] Weight = [1, 1, 1, 1] brierscoreloss(Target, Approx, sampleweight=Weight) result is 1 Maybe we should fix it? Thank you.

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


Question: CountVectorizer with custom analyzer ignores input argument Example: Same for . Not sure if this should be fixed or just documented; I don't like changing the behavior of the vectorizers yet again...

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


Question: CountVectorizer with custom analyzer ignores input argument Example: Same for . Not sure if this should be fixed or just documented; I don't like changing the behavior of the vectorizers yet again...

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


Question: CountVectorizer with custom analyzer ignores input argument Example: Same for . Not sure if this should be fixed or just documented; I don't like changing the behavior of the vectorizers yet again...

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


Question: CountVectorizer with custom analyzer ignores input argument Example: Same for . Not sure if this should be fixed or just documented; I don't like changing the behavior of the vectorizers yet again...

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


Question: CountVectorizer with custom analyzer ignores input argument Example: Same for . Not sure if this should be fixed or just documented; I don't like changing the behavior of the vectorizers yet again...

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


Question: VarianceThreshold doesn't remove feature with zero variance When calling VarianceThreshold().fittransform() on certain inputs, it fails to remove a column that has only one unique value. The Variance threshold should produce This issue arose when I was using VarianceThreshold on a real dataset (of which this is a subset). It appears to work correctly in other situations (for instance I can't reproduce this behaviour if I replace the first column with 1's). System python: 3.5.6 (default, Aug 26 2018, 16:30:03) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE401/final)] machine: Darwin-18.2.0-x8664-i386-64bit executable: /anaconda3/envs/tensorflow/bin/python3 BLAS macros: NOATLASINFO=3, HAVECBLAS=None libdirs: cblaslibs: cblas Python deps setuptools: 40.2.0 numpy: 1.15.4 sklearn: 0.20.0 Cython: None scipy: 1.1.0 pandas: 0.24.0 pip: 19.0.1

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


Question: VarianceThreshold doesn't remove feature with zero variance When calling VarianceThreshold().fittransform() on certain inputs, it fails to remove a column that has only one unique value. The Variance threshold should produce This issue arose when I was using VarianceThreshold on a real dataset (of which this is a subset). It appears to work correctly in other situations (for instance I can't reproduce this behaviour if I replace the first column with 1's). System python: 3.5.6 (default, Aug 26 2018, 16:30:03) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE401/final)] machine: Darwin-18.2.0-x8664-i386-64bit executable: /anaconda3/envs/tensorflow/bin/python3 BLAS macros: NOATLASINFO=3, HAVECBLAS=None libdirs: cblaslibs: cblas Python deps setuptools: 40.2.0 numpy: 1.15.4 sklearn: 0.20.0 Cython: None scipy: 1.1.0 pandas: 0.24.0 pip: 19.0.1

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


Question: ncomponents kwarg missing in SpectralClustering The kwarg defined in the function allow the user to choose how many eigenvalues/eigenvectors should be used in the classification. However this kwarg cannot be accessed/modified when using class, and is set to default ( = ). Since the class calls the spectralclustering function, I guess the user should be able to access this kwarg ?

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


Question: ncomponents kwarg missing in SpectralClustering The kwarg defined in the function allow the user to choose how many eigenvalues/eigenvectors should be used in the classification. However this kwarg cannot be accessed/modified when using class, and is set to default ( = ). Since the class calls the spectralclustering function, I guess the user should be able to access this kwarg ?

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


Question: ncomponents kwarg missing in SpectralClustering The kwarg defined in the function allow the user to choose how many eigenvalues/eigenvectors should be used in the classification. However this kwarg cannot be accessed/modified when using class, and is set to default ( = ). Since the class calls the spectralclustering function, I guess the user should be able to access this kwarg ?

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


Question: ncomponents kwarg missing in SpectralClustering The kwarg defined in the function allow the user to choose how many eigenvalues/eigenvectors should be used in the classification. However this kwarg cannot be accessed/modified when using class, and is set to default ( = ). Since the class calls the spectralclustering function, I guess the user should be able to access this kwarg ?

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


Question: Voting estimator will fail at fit if weights are passed and an estimator is None Because we don't check for an estimator to be in support, is failing`.

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


Question: Handle 'drop' together with None to drop estimator in VotingClassifier/VotingRegressor As mentioned in the following , the and should accept to drop an estimator from the ensemble is the same way that is doing now.

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


Question: Handle 'drop' together with None to drop estimator in VotingClassifier/VotingRegressor As mentioned in the following , the and should accept to drop an estimator from the ensemble is the same way that is doing now.

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


Question: Handle 'drop' together with None to drop estimator in VotingClassifier/VotingRegressor As mentioned in the following , the and should accept to drop an estimator from the ensemble is the same way that is doing now.

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


Question: Handle 'drop' together with None to drop estimator in VotingClassifier/VotingRegressor As mentioned in the following , the and should accept to drop an estimator from the ensemble is the same way that is doing now.

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


Question: Handle 'drop' together with None to drop estimator in VotingClassifier/VotingRegressor As mentioned in the following , the and should accept to drop an estimator from the ensemble is the same way that is doing now.

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