如何将sklearn MinMaxScaler()中的值转换回实际值?

时间:2017-11-03 02:16:51

标签: python tensorflow scikit-learn keras

我像这样使用sklearn MinMaxScaler()。

from sklearn.preprocessing import MinMaxScaler

sc = MinMaxScaler()

train_sc = sc.fit_transform(train)
test_sc = sc.transform(test)

它将数据更改为0-1范围。在我预测之后它仍然是值0-1。如何转换回实际值?

1 个答案:

答案 0 :(得分:4)

对输出预测数据使用inverse_transform()

from sklearn.preprocessing import MinMaxScaler

data = [[-1, 2], [-0.5, 6], [0, 10], [1, 18]]
scaler = MinMaxScaler()
scaler.fit(data)    

print(scaler.transform([[2, 2]]))
Out>>> [[ 1.5  0. ]]

// This is what you need
print(scaler.inverse_transform([[ 1.5  0. ]]))
Out>>> [[ 2.0  2.0]]