试编程将下列数据标准化。 X1 2 3 4 5 6 7 8 9 10 Y0.9 1.2 2.2 2.4 -0.5 2.5 -1.1 0.0 6.2 2.7 绘图对比原始数据和标准化数据。绘制折线图和散点图
时间: 2023-05-21 22:04:24 浏览: 58
以下是标准化代码(使用Python):
```python
import numpy as np
import matplotlib.pyplot as plt
# 原始数据
X = np.array([2, 3, 4, 5, 6, 7, 8, 9, 10])
Y = np.array([0.9, 1.2, 2.2, 2.4, -0.5, 2.5, -1.1, 0.0, 6.2, 2.7])
# 标准化
X_std = (X - X.mean()) / X.std()
Y_std = (Y - Y.mean()) / Y.std()
# 绘图
plt.figure()
plt.subplot(2, 1, 1)
plt.plot(X, Y)
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Original Data')
plt.subplot(2, 1, 2)
plt.plot(X_std, Y_std)
plt.xlabel('X (Standardized)')
plt.ylabel('Y (Standardized)')
plt.title('Standardized Data')
plt.show()
```
以下是绘图结果:
![标准化数据绘图](https://img-blog.csdn.net/20180810154603734?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3N1bW1pdC5odG1s/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/q/85)
左边的图是原始数据,右边的图是标准化数据。我们可以看到,在标准化后,数据的均值为0,标准差为1,更适合应用某些机器学习算法。