-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
ENH Adds n_features_in_ to ensemble module #19326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
14778ba
186e7a2
cb12f64
5366110
f11e457
65edf9f
4f40b0f
679443c
a04fbad
9568948
d89cb0b
4e1bac9
905d85c
803461d
f30d144
43be0d8
44e21c1
bc43b6a
b1eb01c
bed7034
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,7 @@ class calls the ``fit`` method of each sub-estimator on random samples | |
from ..tree import (DecisionTreeClassifier, DecisionTreeRegressor, | ||
ExtraTreeClassifier, ExtraTreeRegressor) | ||
from ..tree._tree import DTYPE, DOUBLE | ||
from ..utils import check_random_state, check_array, compute_sample_weight | ||
from ..utils import check_random_state, compute_sample_weight, deprecated | ||
from ..exceptions import DataConversionWarning | ||
from ._base import BaseEnsemble, _partition_estimators | ||
from ..utils.fixes import delayed | ||
|
@@ -312,9 +312,6 @@ def fit(self, X, y, sample_weight=None): | |
# ensemble sorts the indices. | ||
X.sort_indices() | ||
|
||
# Remap output | ||
self.n_features_ = X.shape[1] | ||
|
||
y = np.atleast_1d(y) | ||
if y.ndim == 2 and y.shape[1] == 1: | ||
warn("A column-vector y was passed when a 1d array was" | ||
|
@@ -446,7 +443,8 @@ def _compute_oob_predictions(self, X, y): | |
(n_samples, 1, n_outputs) | ||
The OOB predictions. | ||
""" | ||
X = check_array(X, dtype=DTYPE, accept_sparse='csr') | ||
X = self._validate_data(X, dtype=DTYPE, accept_sparse='csr', | ||
reset=False) | ||
|
||
n_samples = y.shape[0] | ||
n_outputs = self.n_outputs_ | ||
|
@@ -530,12 +528,22 @@ def feature_importances_(self): | |
for tree in self.estimators_ if tree.tree_.node_count > 1) | ||
|
||
if not all_importances: | ||
return np.zeros(self.n_features_, dtype=np.float64) | ||
return np.zeros(self.n_features_in_, dtype=np.float64) | ||
|
||
all_importances = np.mean(all_importances, | ||
axis=0, dtype=np.float64) | ||
return all_importances / np.sum(all_importances) | ||
|
||
# TODO: Remove in 1.2 | ||
# mypy error: Decorated property not supported | ||
@deprecated( # type: ignore | ||
"Attribute n_features_ was deprecated in version 1.0 and will be " | ||
"removed in 1.2. Use 'n_features_in_' instead." | ||
) | ||
@property | ||
def n_features_(self): | ||
return self.n_features_in_ | ||
|
||
|
||
def _accumulate_prediction(predict, X, out, lock): | ||
""" | ||
|
@@ -1163,6 +1171,10 @@ class labels (multi-output problem). | |
n_features_ : int | ||
The number of features when ``fit`` is performed. | ||
|
||
.. deprecated:: 1.0 | ||
Attribute `n_features_` was deprecated in version 1.0 and will be | ||
removed in 1.2. Use `n_features_in_` instead. | ||
|
||
n_outputs_ : int | ||
The number of outputs when ``fit`` is performed. | ||
|
||
|
@@ -1463,6 +1475,10 @@ class RandomForestRegressor(ForestRegressor): | |
n_features_ : int | ||
The number of features when ``fit`` is performed. | ||
|
||
.. deprecated:: 1.0 | ||
Attribute `n_features_` was deprecated in version 1.0 and will be | ||
removed in 1.2. Use `n_features_in_` instead. | ||
|
||
n_outputs_ : int | ||
The number of outputs when ``fit`` is performed. | ||
|
||
|
@@ -1783,6 +1799,10 @@ class labels (multi-output problem). | |
n_features_ : int | ||
The number of features when ``fit`` is performed. | ||
|
||
.. deprecated:: 1.0 | ||
Attribute `n_features_` was deprecated in version 1.0 and will be | ||
removed in 1.2. Use `n_features_in_` instead. | ||
|
||
n_outputs_ : int | ||
The number of outputs when ``fit`` is performed. | ||
|
||
|
@@ -2068,6 +2088,10 @@ class ExtraTreesRegressor(ForestRegressor): | |
n_features_ : int | ||
The number of features. | ||
|
||
.. deprecated:: 1.0 | ||
Attribute `n_features_` was deprecated in version 1.0 and will be | ||
removed in 1.2. Use `n_features_in_` instead. | ||
|
||
n_outputs_ : int | ||
The number of outputs. | ||
|
||
|
@@ -2292,6 +2316,10 @@ class RandomTreesEmbedding(BaseForest): | |
n_features_ : int | ||
The number of features when ``fit`` is performed. | ||
|
||
.. deprecated:: 1.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1.0. -> 1.0 |
||
Attribute `n_features_` was deprecated in version 1.0 and will be | ||
removed in 1.2. Use `n_features_in_` instead. | ||
|
||
n_outputs_ : int | ||
The number of outputs when ``fit`` is performed. | ||
|
||
|
@@ -2421,7 +2449,7 @@ def fit_transform(self, X, y=None, sample_weight=None): | |
X_transformed : sparse matrix of shape (n_samples, n_out) | ||
Transformed dataset. | ||
""" | ||
X = check_array(X, accept_sparse=['csc']) | ||
X = self._validate_data(X, accept_sparse=['csc']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uhm what is the reason that the common test where not failing for this transformer since we did not introduce There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Or do you think of another test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about |
||
if issparse(X): | ||
# Pre-sort indices to avoid that each individual tree of the | ||
# ensemble sorts the indices. | ||
|
Uh oh!
There was an error while loading. Please reload this page.