How to Fix AttributeError: ‘Simple_Imputer’ object has no attribute ‘fill_value_categorical’

Diagram of Simple_Imputer object has no attribute fill_value_categorical

Diagram

AttributeError: ‘Simple_Imputer’ object has no attribute ‘fill_value_categorical’ error occurs when Simple_Imputer class does not have an attribute called “fill_value_categorical”. The “fill_value_categorical” attribute was removed in version 0.24 of the scikit-learn library.

How to fix it?

To fix the AttributeError: ‘Simple_Imputer’ object has no attribute ‘fill_value_categorical’ error, use the “fill_value” attribute instead of the “fill_value_categorical” attribute.

from sklearn.impute import SimpleImputer

imputer = SimpleImputer(missing_values="NaN", strategy="mean", fill_value="")
imputer.fit(X_train)

If you are using an older version of the scikit-learn library, you can still use the “fill_value_categorical” attribute, but it is deprecated and will eventually be removed.

Here is a table of the old and new attributes for the SimpleImputer class:

Old attribute New attribute
fill_value_categorical fill_value

I hope this will fix the error.

Related posts

AttributeError: ‘SMOTE’ object has no attribute ‘fit_sample’

AttributeError: ‘RandomUnderSampler’ object has no attribute ‘fit_resample’

AttributeError: ‘Pipeline’ object has no attribute ‘fit_resample’

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.