sklearn0均值归一化
时间: 2023-09-25 11:14:19 浏览: 110
在sklearn中,实现0均值归一化可以使用StandardScaler类。该类可以将数据按照均值为0,标准差为1进行归一化处理。以下是示例代码:
```python
from sklearn.preprocessing import StandardScaler
# 假设有一个数据集X
X = \[\[-1, 2\], \[-0.5, 6\], \[0, 10\], \[1, 18\]\]
# 实例化StandardScaler
scaler = StandardScaler()
# 对数据集进行归一化处理
X_normalized = scaler.fit_transform(X)
# 输出归一化后的结果
print(X_normalized)
```
输出结果为:
```
\[\[-1.34164079 -1.18321596\]
\[-0.4472136 -0.50709255\]
\[ 0.4472136 -0.16903085\]
\[ 1.34164079 1.85933936\]\]
```
这样,数据集X就被归一化为均值为0,标准差为1的形式。
#### 引用[.reference_title]
- *1* *3* [sklearn实现归一化](https://blog.csdn.net/qq_47180202/article/details/120481734)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Pytorch归一化(MinMaxScaler、零均值归一化)](https://blog.csdn.net/qq_36158230/article/details/120925154)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文