Keras “不平衡学习”;平衡式“批量发电机”;对于>;二维数据

Keras “不平衡学习”;平衡式“批量发电机”;对于>;二维数据,keras,imblearn,Keras,Imblearn,我正在使用不平衡学习的“平衡批处理生成器”尝试对具有4维的图像阵列执行欠采样。我运行了下面的代码: training_generator, steps_per_epoch = balanced_batch_generator(x_train, y_train, sampler=NearMiss(), batch_size=10) 并得到以下错误: ValueError: Found array with dim 4. Estimator expected <= 2. ValueErro

我正在使用不平衡学习的“平衡批处理生成器”尝试对具有4维的图像阵列执行欠采样。我运行了下面的代码:

training_generator, steps_per_epoch = balanced_batch_generator(x_train, y_train, sampler=NearMiss(), batch_size=10)
并得到以下错误:

ValueError: Found array with dim 4. Estimator expected <= 2.

ValueError:找到具有dim 4的数组。估计器期望二维数据,但我想知道是否有解决这个问题的方法。我会通过手动分割数据来执行欠采样/过采样,但是我想利用keras良好实现的功能,如
NearMiss
,智能地对我的数据进行采样。

您需要为
x_列车
重塑阵列:

x.train.shape #So you know the values for all 4 dims (1st dim, 2nd dim, 3rd dm, 4th dm)
x_train = x_train.reshape(x_train.shape[0],-1)
然后使用
平衡批处理\u生成器
。之后:

x_train = x_train.reshape(x_train.shape[0], initial Value for the 2nd dim, initial Value for the 3rd, initial Value for the 4th)

for x_train, y_train in training_generator:
    break

您的
x_列
包含带有初始尺寸的平衡批次。您不需要重塑
y\u train
,因为它只包含标签。(
dim您需要为您的
x\u列车重新调整阵列的形状

x.train.shape #So you know the values for all 4 dims (1st dim, 2nd dim, 3rd dm, 4th dm)
x_train = x_train.reshape(x_train.shape[0],-1)
然后使用
balanced\u batch\u生成器
。然后:

x_train = x_train.reshape(x_train.shape[0], initial Value for the 2nd dim, initial Value for the 3rd, initial Value for the 4th)

for x_train, y_train in training_generator:
    break
您的
x\u列
包含带有初始尺寸的平衡批次。您不需要重塑
y\u列
,因为它只包含标签。(
dim)