python数据按列归一化
时间: 2023-11-03 10:06:50 浏览: 97
lianghua.zip_归一化_数据归一化
要进行Python数据按列归一化,可以使用以下方法之一:
方法一:使用NumPy库的min-max归一化函数
```python
import numpy as np
def column_normalization(data):
min_vals = np.min(data, axis=0)
max_vals = np.max(data, axis=0)
normalized_data = (data - min_vals) / (max_vals - min_vals)
return normalized_data
# 使用示例
d = [[3, 4, 6, 1, 5], [-3, 4, 6, -1, -5]]
normalized_d = column_normalization(d)
print(normalized_d)
```
方法二:使用sklearn库的MinMaxScaler函数
```python
from sklearn.preprocessing import MinMaxScaler
import numpy as np
def column_normalization(data):
scaler = MinMaxScaler()
normalized_data = scaler.fit_transform(data)
return normalized_data
# 使用示例
d = [[3, 4, 6, 1, 5], [-3, 4, 6, -1, -5]]
normalized_d = column_normalization(d)
print(normalized_d)
```
阅读全文