Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DOC misleading version added info for cv_results["n_features"] in RFECV #30048

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

Closed
nullland1027 opened this issue Oct 12, 2024 · 2 comments Β· Fixed by #30049
Closed

DOC misleading version added info for cv_results["n_features"] in RFECV #30048

nullland1027 opened this issue Oct 12, 2024 · 2 comments Β· Fixed by #30049

Comments

@nullland1027
Copy link

nullland1027 commented Oct 12, 2024

Describe the bug

I'm using the scikit-learn version 1.3.0. When I use
rfecv = RFECV(....) rfecv.fit(X, y) print(rfecv.cv_results_)
that code gives me a traceback: KeyError: 'n_features'
I seen that key in the doc.
image

Steps/Code to Reproduce

from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import StratifiedKFold
from sklearn.feature_selection import RFECV

X, y = load_iris(return_X_y=True)
model = RandomForestClassifier(random_state=42)
cv = StratifiedKFold(n_splits=5)

rfecv = RFECV(
    estimator=model,
    step=8,
    cv=cv,
    scoring='accuracy',
    n_jobs=-1,
    verbose=10
)
rfecv.fit(X, y)

print(rfecv.cv_results_["n_features"])
print(rfecv.n_features_)

Expected Results

It should have the key.

Actual Results

print(rfecv.cv_results_["n_features"])

KeyError: 'n_features'

Versions

1.3.0
@nullland1027 nullland1027 added Bug Needs Triage Issue requires triage labels Oct 12, 2024
@glemaitre
Copy link
Member

n_features has been added in 1.5: #28670

We could have a PR that move the ..versionadded under the cv_results_ add and a ..versionadded:: 1.5 specifically for the n_features key.

@glemaitre glemaitre added Documentation and removed Bug Needs Triage Issue requires triage labels Oct 12, 2024
@glemaitre glemaitre changed the title module sklearn.feature_selection.RFECV's attribute cv_results_ doesn't have key called n_features DOC misleading version added info for cv_results["n_features"] in RFECV Oct 12, 2024
@nullland1027
Copy link
Author

Thank you bro!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants