File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1049,13 +1049,25 @@ def grade_learner(predict, tests):
10491049 return mean (int (predict (X ) == y ) for X , y in tests )
10501050
10511051
1052- def train_test_split (dataset , start , end ):
1053- """Reserve dataset.examples[start:end] for test; train on the remainder."""
1054- start = int (start )
1055- end = int (end )
1052+ def train_test_split (dataset , start = None , end = None , test_split = None ):
1053+ """If you are giving 'start' and 'end' as parameters,
1054+ then it will return the testing set from index 'start' to 'end'
1055+ and the rest for training.
1056+ If you give 'test_split' as a parameter then it will return
1057+ test_split * 100% as the testing set and the rest as
1058+ training set.
1059+ """
10561060 examples = dataset .examples
1057- train = examples [:start ] + examples [end :]
1058- val = examples [start :end ]
1061+ if test_split == None :
1062+ train = examples [:start ] + examples [end :]
1063+ val = examples [start :end ]
1064+ else :
1065+ total_size = len (examples )
1066+ val_size = int (total_size * test_split )
1067+ train_size = total_size - val_size
1068+ train = examples [:train_size ]
1069+ val = examples [train_size :total_size ]
1070+
10591071 return train , val
10601072
10611073
You can’t perform that action at this time.
0 commit comments