本文介绍了如何标准缩放 3D 矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on a signal classification problem and would like to scale the dataset matrix first, but my data is in a 3D format (batch, length, channels).
I tried to use Scikit-learn Standard Scaler:

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

但我收到此错误消息:

找到带有dim 3 的数组.预期StandardScaler

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

I think one solution would be to split the matrix by each channel in multiples 2D matrices, scale them separately and then put back in 3D format, but I wonder if there is a better solution.
Thank you very much.

推荐答案

您必须为每个通道安装和存储一个缩放器

You'll have to fit and store a scaler for each channel

from sklearn.preprocessing import StandardScaler

scalers = {}
for i in range(X_train.shape[1]):
    scalers[i] = StandardScaler()
    X_train[:, i, :] = scalers[i].fit_transform(X_train[:, i, :])

for i in range(X_test.shape[1]):
    X_test[:, i, :] = scalers[i].transform(X_test[:, i, :])

这篇关于如何标准缩放 3D 矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:08
查看更多