How can I split a continuous target into a train/test set such that the mean and standard deviation are the same?
Ältere Kommentare anzeigen
I'm trying to do an 80-20 split on my target so that the distributions are the same. I've tried using cvpartition but I don't believe it can handle a continuous target. Suggestions to use N don't result in a split that maintains the distribution of my target
target = randn(100, 1);
cv = cvpartition(100, 'Holdout', 0.2);
train_idx = training(cv);
test_idx = test(cv);
figure;
hold on;
H_TRAIN = histogram(target(train_idx));
H_TEST = histogram(target(test_idx));
legend([H_TRAIN; H_TEST], {'Train', 'Test'});
hold off;
[h,p,ks2stat] = kstest2(target(train_idx), target(test_idx))

Running a two-sample KS-test returns that the null hypothesis that both samples came from the same continuous distribution can't be rejected, but is this the way to know for certain that my target is split correctly?
Antworten (1)
Kategorien
Mehr zu MATLAB Coder finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
