That's pretty easy to do. Use randperm
to generate a random permutation of indices from 1
up to as many points as you have... which is 208 in your case.
Once you generate this sequence, simply use this and subset into your X
and Y
to extract the training and test data and labels. As such, do something like this:
num_points = size(X,2);
split_point = round(num_points*0.7);
seq = randperm(num_points);
X_train = X(:,seq(1:split_point));
Y_train = Y(seq(1:split_point));
X_test = X(:,seq(split_point+1:end));
Y_test = Y(seq(split_point+1:end));
The split_point
determines how many points we need to place into our training set, and we will need to round it in case this calculation yields any decimal points. I also didn't hard code 208 in there because your data set might grow and so this will work with any size data set you choose. X_train
and Y_train
will contain your data and labels for your training set while X_test
and Y_test
will contain your data and labels for your test set.
As such, the first column of X_train
is your data point for the first element of your training set, with the first element of Y_train
serving as the label for that particular point... and so on and so forth!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…