MNT added validation for sample weight in DummyRegressor
* added validation for sample weight in DummyRegressor
* Fix issue with earlier commit dummy.py
add check_consistent_length(X, y, sample_weight) to check for X y input
* fix flake8 flag for white space indent
@@ -13,7 +13,7 @@ from .utils import check_random_state
from .utils.validation import _num_samples
from .utils.validation import check_array
from .utils.validation import check_consistent_length
-from .utils.validation import check_is_fitted
+from .utils.validation import check_is_fitted, _check_sample_weight
from .utils.random import _random_choice_csc
from .utils.stats import _weighted_percentile
from .utils.multiclass import class_distribution
@@ -145,6 +145,9 @@ class DummyClassifier(MultiOutputMixin, ClassifierMixin, BaseEstimator):
check_consistent_length(X, y, sample_weight)
+ if sample_weight is not None:
+ sample_weight = _check_sample_weight(sample_weight, X)
+
if self.strategy == "constant":
if self.constant is None:
raise ValueError("Constant target value has to be specified "
@@ -475,8 +478,9 @@ class DummyRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
self.n_outputs_ = y.shape[1]
check_consistent_length(X, y, sample_weight)
+
if sample_weight is not None:
- sample_weight = np.asarray(sample_weight)
+ sample_weight = _check_sample_weight(sample_weight, X)
if self.strategy == "mean":
self.constant_ = np.average(y, axis=0, weights=sample_weight)
