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

Fix/handle categorical features #30798 #30799

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 9 commits into
base: main
Choose a base branch
Loading
from
6 changes: 5 additions & 1 deletion 6 sklearn/feature_selection/_sequential.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from numbers import Integral, Real

import numpy as np
import pandas as pd

from ..base import BaseEstimator, MetaEstimatorMixin, _fit_context, clone, is_classifier
from ..metrics import check_scoring, get_scorer_names
Expand Down Expand Up @@ -310,7 +311,10 @@ def _get_best_new_feature_score(self, estimator, X, y, cv, current_mask, **param
candidate_mask[feature_idx] = True
if self.direction == "backward":
candidate_mask = ~candidate_mask
X_new = X[:, candidate_mask]
if isinstance(X, pd.DataFrame):
X_new = X.iloc[:, candidate_mask]
else:
X_new = X[:, candidate_mask]
Comment on lines +314 to +317
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should the function _safe_indexing instead.

However, here it is already to late because you already too late. We should avoid the call to validate_data or at least not validate X to not convert it to a NumPy array.

We also need to use n_features = _num_features(X) to compute the number of features.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glemaitre Should I modify the earlier validation step to prevent X from being converted to a NumPy array? If so, should I change how validate_data is called, or should we handle it differently?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validate_data has a skip_check_array arg which would skip conversion to numpy.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scores[feature_idx] = cross_val_score(
estimator,
X_new,
Expand Down
7 changes: 7 additions & 0 deletions 7 sklearn/metrics/_ranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,14 @@ def average_precision_score(

def _binary_uninterpolated_average_precision(
y_true, y_score, pos_label=1, sample_weight=None

):
if len(y_true) < 2:
raise ValueError(
f"Average precision requires at least 2 samples. Got {len(y_true)}."
" A single sample cannot form a precision-recall curve."
)

precision, recall, _ = precision_recall_curve(
y_true, y_score, pos_label=pos_label, sample_weight=sample_weight
)
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.