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

Closed
@nullland1027

Description

@nullland1027

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions