Invert MinMaxScaler from scikit_learn

前端 未结 3 1357
青春惊慌失措
青春惊慌失措 2021-02-20 06:15

To feed my generative neural net, I need to normalize some data between -1 and 1.

I do it with MinMaxScaler from Sklearn and it works great. Now, my generat

3条回答
  •  情深已故
    2021-02-20 07:12

    Let us start by defining a pandas dataframe:

    cols = ['A', 'B']
    data = pd.DataFrame(np.array([[2,3],[1.02,1.2],[0.5,0.3]]),columns=cols)
    

    The we scale the data using the MinMaxScaler

    scaler = preprocessing.MinMaxScaler(feature_range = (0,1))
    scaled_data = scaler.fit_transform(data[cols])
    

    Now, to invert the transformation you should call the inverse transform:

    scaler.inverse_transform(scaled_data)
    

提交回复
热议问题