You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IterativeImputer skip iterative part if keep_empty_features is set to True #29375
#Test this exampleimportnumpyasnpfromsklearn.experimentalimportenable_iterative_imputerfromsklearn.imputeimportIterativeImputer# Example data with a feature that has all missing valuesX= [[np.nan, 0, 1], [np.nan, 2, 3], [np.nan, 4, 5]]
imp=IterativeImputer(keep_empty_features=True)
X_imputed=imp.fit_transform(X)
print(X_imputed)
You can test this code for keep_empty_features= True and False
Incase of False, it removes that feature and the returned array size may vary. But if True then it returns the same size but with 0 in the example which i provided above.
But for your example, it's returning different output when its set to True.
I think, it should return the same output as when it was set to False.
@xuefeng-xu Are you interested in taking this bug.
In the latest case which you provided, I am unable to make the required changes to make it work as I am a new contributer. And this has few complex changes to satisfy.
Traceback (most recent call last):
File "C:\Users\panur\scikit-learn\test.py", line 7, in <module>
print(imp.fit_transform(X))
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\panur\scikit-learn\sklearn\utils\_set_output.py", line 313, in wrapped
data_to_wrap = f(self, X, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\panur\scikit-learn\sklearn\base.py", line 1514, in wrapper
return fit_method(estimator, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\panur\scikit-learn\sklearn\impute\_iterative.py", line 789, in fit_transform
Xt, estimator = self._impute_one_feature(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\panur\scikit-learn\sklearn\impute\_iterative.py", line 418, in _impute_one_feature
estimator.fit(X_train, y_train, **params)
File "C:\Users\panur\scikit-learn\sklearn\base.py", line 1514, in wrapper
return fit_method(estimator, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\panur\scikit-learn\sklearn\linear_model\_bayes.py", line 238, in fit
X, y = self._validate_data(
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\panur\scikit-learn\sklearn\base.py", line 650, in _validate_data
X, y = check_X_y(X, y, **check_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\panur\scikit-learn\sklearn\utils\validation.py", line 1295, in check_X_y
X = check_array(
^^^^^^^^^^^^
File "C:\Users\panur\scikit-learn\sklearn\utils\validation.py", line 1081, in check_array
raise ValueError(
ValueError: Found array with 0 sample(s) (shape=(0, 3)) while a minimum of 1 is required by BayesianRidge.
Activity
Anurag-Varma commentedon Jul 3, 2024
/take
Can any member check this and remove needs triage.
Then assign me the issue.
Anurag-Varma commentedon Jul 4, 2024
/take
Anurag-Varma commentedon Jul 4, 2024
@xuefeng-xu
When
keep_empty_features=FalseThe output is:
But what is the expected result when
keep_empty_features=True?According to your output, it is replacing the nan values as:
xuefeng-xu commentedon Jul 4, 2024
@Anurag-Varma I think the output should be the same as
keep_empty_features=False.Anurag-Varma commentedon Jul 4, 2024
@xuefeng-xu I think it's working as required
keep_empty_featuresbool, default=False
You can test this code for
keep_empty_features=True and FalseWhen True:
When False:
xuefeng-xu commentedon Jul 4, 2024
@Anurag-Varma For data you provided, there's no need to fit any estimater since it just need to discard the first column or replace it with zeros.
For the data sample I provided, do you think
IterativeImputershould behave the same?Anurag-Varma commentedon Jul 4, 2024
@xuefeng-xu I understand it now.
So incase features that consist exclusively of missing values then it will return 0 if its set True.
Incase of False, it removes that feature and the returned array size may vary. But if True then it returns the same size but with 0 in the example which i provided above.
But for your example, it's returning different output when its set to True.
I think, it should return the same output as when it was set to False.
xuefeng-xu commentedon Jul 4, 2024
@Anurag-Varma Thank you! I currently don't have time to fix this, if you want to do it, feel free to open a PR.
adrinjalali commentedon Jul 4, 2024
so for completeness, this is current behavior:
And I agree it seems they need to be the same.
A PR is welcome.
Anurag-Varma commentedon Jul 9, 2024
@xuefeng-xu Are you interested in taking this bug.
In the latest case which you provided, I am unable to make the required changes to make it work as I am a new contributer. And this has few complex changes to satisfy.
Anurag-Varma commentedon Jul 10, 2024
For the new case which @xuefeng-xu has given:
I also found a new error in the below code:
Causes the following error:
arifqodari commentedon Sep 2, 2024
Hi @xuefeng-xu , I can reproduce the issues. Can I work on this issue?
xuefeng-xu commentedon Sep 3, 2024
Sure, go ahead @adrinjalali
arifqodari commentedon Sep 3, 2024
/take