Search code examples
pythonscikit-learnjoblib

AttributeError: 'MinMaxScaler' object has no attribute 'clip'


I get the following error when I attempt to load a saved sklearn.preprocessing.MinMaxScaler

/shared/env/lib/python3.6/site-packages/sklearn/base.py:315: UserWarning: Trying to unpickle estimator MinMaxScaler from version 0.23.2 when using version 0.24.0. This might lead to breaking code or invalid results. Use at your own risk.
  UserWarning)
[2021-01-08 19:40:28,805 INFO train.py:1317 - main ] EXCEPTION WORKER 100: 
Traceback (most recent call last):
  ...
  File "/shared/core/simulate.py", line 129, in process_obs
    obs = scaler.transform(obs)
  File "/shared/env/lib/python3.6/site-packages/sklearn/preprocessing/_data.py", line 439, in transform
    if self.clip:
AttributeError: 'MinMaxScaler' object has no attribute 'clip'

I trained the scaler on one machine, saved it, and pushed it to a second machine where it was loaded and used to transform input.

# loading and transforming
import joblib
from sklearn.preprocessing import MinMaxScaler

scaler = joblib.load('scaler')
assert isinstance(scaler, MinMaxScaler)
data = scaler.transform(data)  # throws exception

Solution

  • The issue is you are training the scaler on a machine with an older verion of sklearn than the machine you're using to load the scaler.

    Noitce the UserWarning

    UserWarning: Trying to unpickle estimator MinMaxScaler from version 0.23.2 when using version 0.24.0. This might lead to breaking code or invalid results. Use at your own risk. UserWarning)

    The solution is to fix the version mismatch. Either by upgrading one sklearn to 0.24.0 or downgrading to 0.23.2