import numpy as np
# 1. 最大值最小值归一化
# 天池蒸汽案例
# ...
# 2. Z-score(0-均值)归一化
# 生成两个随机数组 x1 和 x2
x1 = np.random.randint(1, 10, size=(10, 1))
x2 = np.random.randint(1000, 10000, size=(10, 1))
# 将两个数组连接成一个二维数组 X
X = np.concatenate([x1, x2], axis=1)
# 使用 Z-score 归一化
X_norm = (X - X.mean(axis=0)) / X.std(axis=0)
print("Z-score 归一化结果:\n", X_norm)
# 使用 scikit-learn 中的 StandardScaler 进行归一化
from sklearn.preprocessing import StandardScaler
standard = StandardScaler()
standard.fit(X)
X_norm2 = standard.transform(X)
print("使用 StandardScaler 归一化结果:\n", X_norm2)
05归一化
最新推荐文章于 2024-09-05 15:39:23 发布