text_plain_output_1.png
from imblearn.under_sampling import RandomUnderSampler

import numpy as np

seed = 42
np.random.seed = seed

x_train = np.asarray(x_train, np.float32) / 255
x_test = np.asarray(x_test, np.float32) / 255
y_train = np.asarray(y_train)
y_test = np.asarray(y_test)

shape = 50 * 50 * 3
x_train = x_train.reshape(x_train.shape[0], shape)
x_test = x_test.reshape(x_test.shape[0], shape)

from imblearn.under_sampling import RandomUnderSampler
underampler = RandomUnderSampler(sampling_strategy='auto')
x_train_fit, y_train_fit = underampler.fit_resample(x_train, y_train)
X_test_fit, Y_test_fit = underampler.fit_resample(x_test, y_test)
x_train_ = x_train_fit.reshape(x_train_fit.shape[0], 50, 50, 3)
x_test_ = X_test_fit.reshape(X_test_fit.shape[0], 50, 50, 3)

print('Train data shape =', x_train_.shape)
print(' Test data shape =', x_test_.shape)