I have two files namely -
label.csv. My aim is to to split these files into training and testing datasets before preprocessing the log_train file further.
log.csv file has a no. of columns including
id. For one value of
id, the file has 'z' no. of rows (this 'z' is different for different value of
id) . Whereas, in the
label.csv file there is just one row for each value of
id. I wish to split the files into -
label_test.csv obviously such that all rows corresponding to one value of
id goes either to train or test file with corresponding values in label_train or label_test file.
I have already tried doing:
X_train,X_test,y_train,y_test=train_test_split(df,df_label,test_size = 0.2, random_state = 0)
but this gives me the error:
Traceback (most recent call last):
File "tmp.py", line 35, in <module>
X_train, X_test, y_train, y_test = train_test_split(df,df_label,test_size = 0.2, random_state = 0)
File "/home/yamini/virtual/home/yamini/virtual/lib/python3.6/site-packages/sklearn/model_selection/_split.py", line 2184, in train_test_split
arrays = indexable(*arrays)
File "/home/yamini/virtual/home/yamini/virtual/lib/python3.6/site-packages/sklearn/utils/validation.py", line 260, in indexable
File "/home/yamini/virtual/home/yamini/virtual/lib/python3.6/site-packages/sklearn/utils/validation.py", line 235, in check_consistent_length
" samples: %r" % [int(l) for l in lengths])
ValueError: Found input variables with inconsistent numbers of samples: [608, 3]
How can I achieve this in python?