8000 [MRG+1] Changing default model for IterativeImputer to BayesianRidge by sergeyf · Pull Request #13038 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG+1] Changing default model for IterativeImputer to BayesianRidge #13038

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

Merged
Merged
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
16 changes: 4 additions & 12 deletions sklearn/impute.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,10 @@ class IterativeImputer(BaseEstimator, TransformerMixin):
computed during the final round. A round is a single imputation of each
feature with missing values.

predictor : estimator object, default=RidgeCV() or BayesianRidge()
predictor : estimator object, default=BayesianRidge()
The predictor to use at each step of the round-robin imputation.
If ``sample_posterior`` is True, the predictor must support
``return_std`` in its ``predict`` method. Also, if
``sample_posterior=True`` the default predictor will be
:class:`sklearn.linear_model.BayesianRidge` and
:class:`sklearn.linear_model.RidgeCV` otherwise.
``return_std`` in its ``predict`` method.

sample_posterior : boolean, default=False
Whether to sample from the (Gaussian) predictive posterior of the
Expand Down Expand Up @@ -868,13 +865,8 @@ def fit_transform(self, X, y=None):
.format(self.n_iter))

if self.predictor is None:
if self.sample_posterior:
from .linear_model import BayesianRidge
self._predictor = BayesianRidge()
else:
from .linear_model import RidgeCV
# including a very small alpha to approximate OLS
self._predictor = RidgeCV(alphas=np.array([1e-5, 0.1, 1, 10]))
from .linear_model import BayesianRidge
self._predictor = BayesianRidge()
else:
self._predictor = clone(self.predictor)

Expand Down
6 changes: 4 additions & 2 deletions sklearn/tests/test_impute.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def test_iterative_imputer_imputation_order(imputation_order):

@pytest.mark.parametrize(
"predictor",
[DummyRegressor(), BayesianRidge(), ARDRegression(), RidgeCV()]
[None, DummyRegressor(), BayesianRidge(), ARDRegression(), RidgeCV()]
)
def test_iterative_imputer_predictors(predictor):
rng = np.random.RandomState(0)
Expand All @@ -565,7 +565,9 @@ def test_iterative_imputer_predictors(predictor):
# check that types are correct for predictors
hashes = []
for triplet in imputer.imputation_sequence_:
assert isinstance(triplet.predictor, type(predictor))
expected_type = (type(predictor) if predictor is not None
else type(BayesianRidge()))
assert isinstance(triplet.predictor, expected_type)
hashes.append(id(triplet.predictor))

# check that each predictor is unique
Expand Down
0