From de68f03426b88086b2ad4602edb133e4a104d389 Mon Sep 17 00:00:00 2001 From: marijavlajic Date: Sat, 25 Jan 2020 11:13:08 +0100 Subject: [PATCH 1/2] Replaced in-fuction checks with_check_sample_weight for IsotonicRegression. --- sklearn/isotonic.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/sklearn/isotonic.py b/sklearn/isotonic.py index 173a747b927c2..053c2041e8ca7 100644 --- a/sklearn/isotonic.py +++ b/sklearn/isotonic.py @@ -121,10 +121,7 @@ def isotonic_regression(y, sample_weight=None, y_min=None, y_max=None, order = np.s_[:] if increasing else np.s_[::-1] y = check_array(y, ensure_2d=False, dtype=[np.float64, np.float32]) y = np.array(y[order], dtype=y.dtype) - if sample_weight is None: - sample_weight = np.ones(len(y), dtype=y.dtype) - else: - sample_weight = np.array(sample_weight[order], dtype=y.dtype) + sample_weight = _check_sample_weight(sample_weight, y, dtype=y.dtype) _inplace_contiguous_isotonic_regression(y, sample_weight) if y_min is not None or y_max is not None: @@ -261,13 +258,9 @@ def _build_y(self, X, y, sample_weight, trim_duplicates=True): # If sample_weights is passed, removed zero-weight values and clean # order - if sample_weight is not None: - sample_weight = check_array(sample_weight, ensure_2d=False, - dtype=X.dtype) - mask = sample_weight > 0 - X, y, sample_weight = X[mask], y[mask], sample_weight[mask] - else: - sample_weight = np.ones(len(y), dtype=X.dtype) + sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype) + mask = sample_weight > 0 + X, y, sample_weight = X[mask], y[mask], sample_weight[mask] order = np.lexsort((y, X)) X, y, sample_weight = [array[order] for array in [X, y, sample_weight]] From 2090462bebcbc0d8b2da4fe971d8169eed728595 Mon Sep 17 00:00:00 2001 From: marijavlajic Date: Sat, 25 Jan 2020 11:15:56 +0100 Subject: [PATCH 2/2] Added import for check_sample_weight. --- sklearn/isotonic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sklearn/isotonic.py b/sklearn/isotonic.py index 053c2041e8ca7..14527148cfc52 100644 --- a/sklearn/isotonic.py +++ b/sklearn/isotonic.py @@ -8,6 +8,7 @@ from scipy.stats import spearmanr from .base import BaseEstimator, TransformerMixin, RegressorMixin from .utils import check_array, check_consistent_length +from .utils.validation import _check_sample_weight from ._isotonic import _inplace_contiguous_isotonic_regression, _make_unique import warnings import math