Search code examples
pythonimbalanced-dataimblearn

How can I reshape (120, 100, 100) shaped image data to (120, 10000) shape to undersample using "imblearn" library of Python?


I am working with imblearn library of Python for undersampling.

Necessary code:

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

Here X is my image dataset & of (120, 100, 100) shape and y is images' labels which is of (120,) shape. I am getting an error here. But if I give X of shape (x_value, y_value) then it works. Is there any way I can convert (120, 100, 100) shape of image data to (120, 10000) shape?


Solution

  • convert the image data into an numpy array and then reshape, that would solve it

    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)