Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Pass optional column names to parallel tree function in using the self.feature_names_in attribute. #26208

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion 13 sklearn/ensemble/_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,16 @@ def _parallel_build_trees(
verbose=0,
class_weight=None,
n_samples_bootstrap=None,
feature_names_in_=None,
):
"""
Private function used to fit a single tree in parallel."""
if verbose > 1:
print("building tree %d of %d" % (tree_idx + 1, n_trees))

if feature_names_in_ is not None:
tree.feature_names_in_ = feature_names_in_

if bootstrap:
n_samples = X.shape[0]
if sample_weight is None:
Expand Down Expand Up @@ -343,9 +347,15 @@ def fit(self, X, y, sample_weight=None):
# Validate or convert input data
if issparse(y):
raise ValueError("sparse multilabel-indicator for y is not supported.")

X, y = self._validate_data(
X, y, multi_output=True, accept_sparse="csc", dtype=DTYPE
X,
y,
multi_output=True,
accept_sparse="csc",
dtype=DTYPE,
)

if sample_weight is not None:
sample_weight = _check_sample_weight(sample_weight, X)

Expand Down Expand Up @@ -467,6 +477,7 @@ def fit(self, X, y, sample_weight=None):
verbose=self.verbose,
class_weight=self.class_weight,
n_samples_bootstrap=n_samples_bootstrap,
feature_names_in_=getattr(self, "feature_names_in_", None),
)
for i, t in enumerate(trees)
)
Expand Down
1 change: 0 additions & 1 deletion 1 sklearn/tree/_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,6 @@ def fit(self, X, y, sample_weight=None, check_input=True):
self : DecisionTreeClassifier
Fitted estimator.
"""

super().fit(
X,
y,
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.