I'm writing a function that needs to determine whether an object passed to it is an imputer (can check with isinstance(obj,
_BaseImputer
)
), a scaler, or something else.
While all imputers have a common base class that identifies them as imputers, scalers do not. I found that all scalers in sklearn.preprocessing._data
inherit (OneToOneFeatureMixin, TransformerMixin, BaseEstimator)
, so I could check if they are instances of all of them. However that could generate false positives (not sure which other object may inherit the same base classes). It doesn't feel very clean or pythonic either.
I was also thinking of checking whether the object has the .inverse_transform()
method. However, not only scalers have that, a SimpleImputer (and maybe other objects) have also.
How can I easily check if my object is a scaler?