Press "Enter" to skip to content

MinMaxScaler in sklearn

  • sklearn中的特征缩放
➜ test ✗ cat MinMaxScaler.py
# 导入MinMaxScaler
from sklearn.preprocessing import MinMaxScaler
# 使用numpy存储数据
import numpy
# 将权重以浮点数形式存储在numpy.array中, 如若此处为整数, fit_transform时会报错
weights = numpy.array([[115.], [140.], [175.]])
# 生成MinMaxScaler对象
scaler = MinMaxScaler()
# 使用fit_transform()计算特征缩放后的权重
rescaler_weights = scaler.fit_transform(weights)
# 结果输出
print(rescaler_weights)

执行结果:

➜ test ✗ python3 MinMaxScaler.py
[[0.        ]
 [0.41666667]
 [1.        ]]

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *