class sklearn.preprocessing.MinMaxScaler
(feature_range=(0, 1), copy=True)
首先可以使用
# 数据归一化
scaler = MinMaxScaler(feature_range=(0, 1))
scaled = scaler.fit_transform(dataset)
对数据进行归一化,如果使用归一化之后的数据进行了预测,得到了预测值,这个时候需要将预测值反归一化回来,这时候便可以使用MinMaxScaler中的scale_属性和min_属性
min_:ndarray of shape (n_features,)
Per feature adjustment for minimum. Equivalent to min - X.min(axis=0) * self.scale_
scale_:ndarray of shape (n_features,)
Per feature relative scaling of the data. Equivalent to (max - min) / (X.max(axis=0) - X.min(axis=0))
具体意思可以看下面这个代码理解
from sklearn.preprocessing import MinMaxScaler
scaler=MinMaxScaler(feature_range=(0, 1))
data=[[1],[10],]
data
print(data)
>>>[[1], [10]]
new_data=scaler.fit_transform(data)
new_data
#对同一列的数据进行操作
print(new_data)
>>>array([[0.],
[1.]])
scale_new = MinMaxScaler()
scale_new.min_, scale_new.scale_ = scaler.min_[0], scaler.scale_[0]
yhat=[[0.5]]
inv_yhat = scale_new.inverse_transform(yhat)
inv_yhat
print(inv_yhat)
>>>array([[5.5]])
"""scale_跟min_是MinMaxScaler的两个属性,在使用的时候如以下形式
scale_new = MinMaxScaler()
scale_new.min_, scale_new.scale_ = scaler.min_[0], scaler.scale_[0]
data是有多个列,所以这里需要用[]中的数字表示具体对第几列的数据进行操作"""