from sklearn.preprocessing import MinMaxScaler,其中MinMaxScaler是一个类,作用是用作数据归一化。MinMaxScaler()会生成一个归一化实例instance,一般用来归一化一组数据,之后的反归一化需要使用同一个instance才能成功反归一化。
feature_range : tuple (min, max), default=(0, 1)
Desired range of transformed data.
eg:sc=MinMaxScaler(feature_range=(0,1))
copy : bool, default=True
Set to False to perform inplace row normalization and avoid a
copy (if the input is already a numpy array).
clip : bool, default=False
Set to True to clip transformed values of held-out data to
provided `feature range`.
The transformation is given by:
X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0))
X_scaled = X_std * (max - min) + min
where min, max = feature_range.
from sklearn.preprocessing import MinMaxScaler
import numpy as np
d=np.random.randint(10,100,size=10)
sc=MinMaxScaler(feature_range=(0,1))
#归一化
d=sc.fit_transform(d.reshape(-1,1))
#反归一化
d_invers=sc.inverse_transform(d)
#归一化与反归一化必须是同一个MinMaxScaler对象