gpt4 book ai didi

python - 如何标准缩放 3D 矩阵?

转载 作者:太空狗 更新时间:2023-10-30 00:47:27 24 4
gpt4 key购买 nike

我正在处理信号分类问题,想先缩放数据集矩阵,但我的数据是 3D 格式(批处理、长度、 channel )。
我尝试使用 Scikit-learn 标准缩放器:

from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

但是我收到了这个错误信息:

Found array with dim 3. StandardScaler expected <= 2

我认为一种解决方案是将矩阵按多个 2D 矩阵中的每个 channel 拆分,分别缩放它们,然后以 3D 格式放回原处,但我想知道是否有更好的解决方案。
非常感谢。

最佳答案

只有3行代码...

scaler = StandardScaler()
X_train = scaler.fit_transform(X_train.reshape(-1, X_train.shape[-1])).reshape(X_train.shape)
X_test = scaler.transform(X_test.reshape(-1, X_test.shape[-1])).reshape(X_test.shape)

关于python - 如何标准缩放 3D 矩阵?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50125844/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com