-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
API Make IterativeImputer experimental #13824
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
99295f2
Make sklearn.impute a subpackage
jnothman 51a1686
Make IterativeImputer experimental
jnothman c751f46
Add missing files
jnothman 8aa289a
Update enable_iterative_imputer.py
jnothman 71b8067
Remove inappropriate test
jnothman f7fbe35
Merge branch 'exp-iterimo' of github.com:jnothman/scikit-learn into e…
jnothman 69b489e
add_subpackage
jnothman 5ec93e4
From experimental import * in doc/conf.py
jnothman 2b64a9f
Empty commit for azure restart
jnothman a2a0a53
Add tests subpackage too
jnothman 8702f2a
Fix copy-paste
jnothman 0f1014a
Update what's new
jnothman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,7 +105,16 @@ of ``y``. This is done for each feature in an iterative fashion, and then is | |
repeated for ``max_iter`` imputation rounds. The results of the final | ||
imputation round are returned. | ||
|
||
.. note:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you make a small change in l. 25 and 27 of this file. The hyperlinks does not work:
|
||
|
||
This estimator is still **experimental** for now: the predictions | ||
and the API might change without any deprecation cycle. To use it, | ||
you need to explicitly import ``enable_iterative_imputer``. | ||
|
||
:: | ||
|
||
>>> import numpy as np | ||
>>> from sklearn.experimental import enable_iterative_imputer | ||
>>> from sklearn.impute import IterativeImputer | ||
>>> imp = IterativeImputer(max_iter=10, random_state=0) | ||
>>> imp.fit([[1, 2], [3, 6], [4, 8], [np.nan, 3], [7, np.nan]]) # doctest: +NORMALIZE_WHITESPACE | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"""Enables IterativeImputer | ||
|
||
The API and results of this estimators might change without any deprecation | ||
cycle. | ||
|
||
Importing this file dynamically sets :class:`sklearn.impute.IterativeImputer` | ||
as an attribute of the impute module:: | ||
|
||
>>> # explicitly require this experimental feature | ||
>>> from sklearn.experimental import enable_iterative_imputer # noqa | ||
>>> # now you can import normally from impute | ||
>>> from sklearn.impute import IterativeImputer | ||
""" | ||
|
||
from ..impute._iterative import IterativeImputer | ||
from .. import impute | ||
|
||
impute.IterativeImputer = IterativeImputer | ||
impute.__all__ += ['IterativeImputer'] |
39 changes: 39 additions & 0 deletions
39
sklearn/experimental/tests/test_enable_iterative_imputer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Tests for making sure experimental imports work as expected.""" | ||
|
||
import textwrap | ||
|
||
from sklearn.utils.testing import assert_run_python_script | ||
|
||
|
||
def test_imports_strategies(): | ||
# Make sure different import strategies work or fail as expected. | ||
|
||
# Since Python caches the imported modules, we need to run a child process | ||
# for every test case. Else, the tests would not be independent | ||
# (manually removing the imports from the cache (sys.modules) is not | ||
# recommended and can lead to many complications). | ||
|
||
good_import = """ | ||
from sklearn.experimental import enable_iterative_imputer | ||
from sklearn.impute import IterativeImputer | ||
""" | ||
assert_run_python_script(textwrap.dedent(good_import)) | ||
|
||
good_import_with_ensemble_first = """ | ||
import sklearn.ensemble | ||
from sklearn.experimental import enable_iterative_imputer | ||
from sklearn.impute import IterativeImputer | ||
""" | ||
assert_run_python_script(textwrap.dedent(good_import_with_ensemble_first)) | ||
|
||
bad_imports = """ | ||
import pytest | ||
|
||
with pytest.raises(ImportError): | ||
from sklearn.impute import IterativeImputer | ||
|
||
import sklearn.experimental | ||
with pytest.raises(ImportError): | ||
from sklearn.impute import IterativeImputer | ||
""" | ||
assert_run_python_script(textwrap.dedent(bad_imports)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jnothman I believe this does not work as expected: