Keras “不平衡学习”;平衡式“批量发电机”;对于>;二维数据
我正在使用不平衡学习的“平衡批处理生成器”尝试对具有4维的图像阵列执行欠采样。我运行了下面的代码: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
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)