数据分析基础:数据缩放

199 阅读1分钟

基础代码

import numpy as np
import matplotlib.pyplot as plt


x = np.asarray([x*10 for x in np.random.random(size=10)])
print(x)

fig = plt.figure(num=1, figsize=(10, 3))
plt.subplot(131)
plt.plot([i for i in range(x.size)], x)
# 缩放
plt.subplot(132) # 步骤1:减去均值
plt.plot([i for i in range(x.size)], [i-x.mean() for i in x])

plt.subplot(133) # 步骤2:归一化(除以数量级)
plt.plot([i for i in range(x.size)], [(i-x.mean())/10 for i in x])

plt.show()

DataScale.png