首页 > 解决方案 > 如何使用 Python 的“imblearn”库将 (120, 100, 100) 形状的图像数据重塑为 (120, 10000) 形状以进行欠采样?

问题描述

我正在使用Python的imblearn库进行欠采样。

必要代码:

undersample = RandomUnderSampler(sampling_strategy='majority')
X_under, y_under = undersample.fit_resample(X, y)

这里X是我的(120, 100, 100) 形状的图像数据集 & ,y(120,) 形状的图像标签。我在这里遇到错误。但是如果我给X形状 (x_value, y_value)那么它就可以了。有什么方法可以将(120, 100, 100) 形状的图像数据转换为(120, 10000)形状?

标签: pythonimbalanced-dataimblearn

解决方案


将图像数据转换为 numpy 数组,然后重塑,这将解决它

import numpy as np
# assuming X is the image data of shape (120,100,100)
X = np.asarray(image)
X_reshape = X.reshape(120,10000) 

推荐阅读