|
10 | 10 | from .base import BaseEstimator, ClassifierMixin, RegressorMixin
|
11 | 11 | from .base import MultiOutputMixin
|
12 | 12 | from .utils import check_random_state
|
| 13 | +from .utils import deprecated |
13 | 14 | from .utils.validation import _num_samples
|
14 | 15 | from .utils.validation import check_array
|
15 | 16 | from .utils.validation import check_consistent_length
|
@@ -75,10 +76,12 @@ class DummyClassifier(MultiOutputMixin, ClassifierMixin, BaseEstimator):
|
75 | 76 | n_outputs_ : int
|
76 | 77 | Number of outputs.
|
77 | 78 |
|
78 |
| - n_features_in_ : int |
79 |
| - Number of features seen during :term:`fit`. |
| 79 | + n_features_in_ : `None` |
| 80 | + Always set to `None`. |
80 | 81 |
|
81 | 82 | .. versionadded:: 0.24
|
| 83 | + .. deprecated:: 1.0 |
| 84 | + Will be removed in 1.0 |
82 | 85 |
|
83 | 86 | sparse_output_ : bool
|
84 | 87 | True if the array returned from predict is to be in sparse CSC format.
|
@@ -164,8 +167,6 @@ def fit(self, X, y, sample_weight=None):
|
164 | 167 |
|
165 | 168 | self.n_outputs_ = y.shape[1]
|
166 | 169 |
|
167 |
| - self.n_features_in_ = None # No input validation is done for X |
168 |
| - |
169 | 170 | check_consistent_length(X, y)
|
170 | 171 |
|
171 | 172 | if sample_weight is not None:
|
@@ -421,6 +422,16 @@ def score(self, X, y, sample_weight=None):
|
421 | 422 | X = np.zeros(shape=(len(y), 1))
|
422 | 423 | return super().score(X, y, sample_weight)
|
423 | 424 |
|
| 425 | + # TODO: Remove in 1.2 |
| 426 | + # mypy error: Decorated property not supported |
| 427 | + @deprecated( # type: ignore |
| 428 | + "`n_features_in_` is deprecated in 1.0 and will be removed in 1.2." |
| 429 | + ) |
| 430 | + @property |
| 431 | + def n_features_in_(self): |
| 432 | + check_is_fitted(self) |
| 433 | + return None |
| 434 | + |
424 | 435 |
|
425 | 436 | class DummyRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
426 | 437 | """Regressor that makes predictions using simple rules.
|
@@ -459,10 +470,12 @@ class DummyRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
459 | 470 | Mean or median or quantile of the training targets or constant value
|
460 | 471 | given by the user.
|
461 | 472 |
|
462 |
| - n_features_in_ : int |
463 |
| - Number of features seen during :term:`fit`. |
| 473 | + n_features_in_ : `None` |
| 474 | + Always set to `None`. |
464 | 475 |
|
465 | 476 | .. versionadded:: 0.24
|
| 477 | + .. deprecated:: 1.0 |
| 478 | + Will be removed in 1.0 |
466 | 479 |
|
467 | 480 | n_outputs_ : int
|
468 | 481 | Number of outputs.
|
@@ -518,7 +531,6 @@ def fit(self, X, y, sample_weight=None):
|
518 | 531 | )
|
519 | 532 |
|
520 | 533 | y = check_array(y, ensure_2d=False)
|
521 |
| - self.n_features_in_ = None # No input validation is done for X |
522 | 534 | if len(y) == 0:
|
523 | 535 | raise ValueError("y must not be empty.")
|
524 | 536 |
|
@@ -656,3 +668,13 @@ def score(self, X, y, sample_weight=None):
|
656 | 668 | if X is None:
|
657 | 669 | X = np.zeros(shape=(len(y), 1))
|
658 | 670 | return super().score(X, y, sample_weight)
|
| 671 | + |
| 672 | + # TODO: Remove in 1.2 |
| 673 | + # mypy error: Decorated property not supported |
| 674 | + @deprecated( # type: ignore |
| 675 | + "`n_features_in_` is deprecated in 1.0 and will be removed in 1.2." |
| 676 | + ) |
| 677 | + @property |
| 678 | + def n_features_in_(self): |
| 679 | + check_is_fitted(self) |
| 680 | + return None |
0 commit comments