Python Forum
How to fix With n_samples=0, test_size=0.2 and train_size=None, the resulting train s
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to fix With n_samples=0, test_size=0.2 and train_size=None, the resulting train s
#1
I wrote a text classification program. When I run the program have error. How to fix it?

input_shape = (128, 128, 3)
data_dir = '/content/drive/MyDrive/working/dataset'

real_data = [f for f in os.listdir(data_dir+'/real') if f.endswith('.png')]
fake_data = [f for f in os.listdir(data_dir+'/fake') if f.endswith('.png')]

X = []
Y = []

for img in real_data:
    X.append(img_to_array(load_img(data_dir+'/real/'+img)).flatten() / 255.0)
    Y.append(1)
for img in fake_data:
    X.append(img_to_array(load_img(data_dir+'/fake/'+img)).flatten() / 255.0)
    Y.append(0)

Y_val_org = Y

#Normalization
X = np.array(X)
Y = to_categorical(Y, 2)

#Reshape
X = X.reshape(-1, 128, 128, 3)

#Train-Test split
X_train, X_val, Y_train, Y_val = train_test_split(X, Y, test_size = 0.2, random_state=5)
 2234 
   2235     if n_train == 0:
-> 2236         raise ValueError(
   2237             "With n_samples={}, test_size={} and train_size={}, the "
   2238             "resulting train set will be empty. Adjust any of the "

ValueError: With n_samples=0, test_size=0.2 and train_size=None, the resulting train set will be empty. Adjust any of the aforementioned parameters.
Reply
#2
Please show the complete and unaltered error traceback.
Reply
#3
(Apr-15-2023, 11:25 AM)Larz60+ Wrote: Please show the complete and unaltered error traceback.

it sokay already solve this problem. thx
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to store the resulting Doc objects into a list named A xinyulon 1 1,909 Mar-08-2022, 11:49 PM
Last Post: bowlofred
  Adding a comma in the resulting value stsxbel 6 2,658 May-22-2021, 09:24 PM
Last Post: stsxbel
  How do I split a dataset into test/train/validation according to a particular group? 69195Student 1 2,291 May-12-2021, 08:27 PM
Last Post: bowlofred
  Delimited Values to ROW - Lucky Train ? karthi_python 1 2,356 May-30-2019, 06:40 AM
Last Post: karthi_python

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020