Punn not Poon
Punn not Poon

Reputation: 1

ValueError: Expected n_neighbors <= n_samples, but n_samples = 2, n_neighbors = 6

I tried to use the SMOTE to solve my imbalance data problem which are white blood cell that contain 5 classes class1: 212 images class2: 744 images class3: 2,427 images class4: 561 images class5: 6,231 images

Here are my code

data_gen = ImageDataGenerator(rescale=1./255,
    width_shift_range=0.05,
    height_shift_range=0.05,
    horizontal_flip=True,
    vertical_flip=True,
    validation_split=0.2)

train_gen = data_gen.flow_from_directory(directory = TRAIN_PATH,subset='training',batch_size = BATCH_SIZE,shuffle = True,class_mode = 'categorical',target_size = (IMAGE_SIZE, IMAGE_SIZE))


valid_gen = data_gen.flow_from_directory(directory = TRAIN_PATH,subset='validation',batch_size = BATCH_SIZE,shuffle = False,class_mode = 'categorical',target_size = (IMAGE_SIZE, IMAGE_SIZE))

test_gen = ImageDataGenerator(rescale=1./255).flow_from_directory(directory = TEST_PATH,batch_size = BATCH_SIZE,shuffle = False,class_mode = 'categorical',target_size = (IMAGE_SIZE, IMAGE_SIZE))


from collections import Counter

counter = Counter(train_gen.classes)

print(counter.items())


from imblearn.over_sampling import SMOTE


X_train, y_train = train_gen.next()


X_train = X_train.reshape(X_train.shape[0], -1)

np.asarray(y_train.argmax(axis=1)))

X_train_sm, y_train_sm = SMOTE(random_state=42).fit_resample(X_train,y_train)

X_train_sm = X_train_sm.reshape(X_train_sm.shape[0], IMAGE_SIZE, IMAGE_SIZE, 3)

this error occur and I have tried to solve by determine the k_neighbor value but it still error

ValueError: Expected n_neighbors <= n_samples, but n_samples = 2, n_neighbors = 6

I have tried to solve by determine the k_neighbors value but it still error.

Upvotes: 0

Views: 56

Answers (0)

Related Questions