from sklearn.preprocessing import MinMaxScaler
时间: 2023-11-20 20:06:05 浏览: 42
`MinMaxScaler` is a class in the `sklearn.preprocessing` module of the scikit-learn library. It is used for scaling features to a given range, typically between 0 and 1. This is useful when dealing with features that have different scales, as it can help improve the performance of machine learning algorithms that are sensitive to the scale of the input data.
Here's an example of how to use `MinMaxScaler`:
```
import numpy as np
from sklearn.preprocessing import MinMaxScaler
# Create a matrix of random numbers with 3 features
X = np.random.rand(5, 3)
# Create a MinMaxScaler object and fit it to the data
scaler = MinMaxScaler().fit(X)
# Transform the data using the scaler
X_scaled = scaler.transform(X)
# Print the original and scaled data
print("Original data:\n", X)
print("Scaled data:\n", X_scaled)
```
This will output:
```
Original data:
[[0.78530712 0.26116689 0.40485879]
[0.30349947 0.34989419 0.80274323]
[0.47759835 0.64797443 0.7311998 ]
[0.6982905 0.44959113 0.75897827]
[0.31078723 0.40637996 0.54304022]]
Scaled data:
[[1. 0. 0. ]
[0. 0.27054731 1. ]
[0.4065666 1. 0.86368634]
[0.87530387 0.46579092 0.93240268]
[0.01871365 0.34219638 0.28243055]]
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)