jupyter 规范化缩放
时间: 2023-12-28 12:26:12 浏览: 32
在Jupyter Notebook中进行规范化缩放可以通过以下步骤实现:
1. 安装Jupyter Notebook:可以使用conda或pip来安装Jupyter Notebook。在conda环境下,可以使用以下命令安装:
```shell
conda install jupyter notebook
```
或者使用pip安装:
```shell
pip install jupyter notebook
```
2. 在Jupyter Notebook中导入所需的库和数据集:
```python
import matplotlib.pyplot as plt
import numpy as np
from sklearn.preprocessing import MinMaxScaler
# 导入数据集
X_train = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # 假设这是你的训练数据集
X_features = ['feature1', 'feature2', 'feature3'] # 特征名称
```
3. 进行规范化缩放:
```python
# 创建MinMaxScaler对象
scaler = MinMaxScaler()
# 对训练数据集进行规范化缩放
X_norm = scaler.fit_transform(X_train)
# 绘制规范化前后的特征分布图
fig, ax = plt.subplots(1, 4, figsize=(12, 3))
for i in range(len(ax)):
# 绘制规范化前的特征分布图
norm_plot(ax[i], X_train[:, i])
ax[i].set_xlabel(X_features[i])
ax[0].set_ylabel("count")
fig.suptitle("distribution of features before normalization")
plt.show()
fig, ax = plt.subplots(1, 4, figsize=(12, 3))
for i in range(len(ax)):
# 绘制规范化后的特征分布图
norm_plot(ax[i], X_norm[:, i])
ax[i].set_xlabel(X_features[i])
ax[0].set_ylabel("count")
fig.suptitle(f"distribution of features after normalization")
plt.show()
```
这样,你就可以在Jupyter Notebook中进行规范化缩放了。