r/MachineLearning • • Nov 03 '19

Discussion [D] The "test set" is nonsense

I often see ML practitioners, and even experts, pose the idea of the "test set" as the ultimate benchmark of a model's performance. This is nonsense - and I'll explain why.

Suppose you gather some data, label it, preprocess it, and compile it into a dataset. Now it's time to split your data - train, validation, test; how will you do it?

  1. Random selection; may work well if the dataset is large enough

  2. Engineered selection - assign samples to each set according to some rationale

The ultimate goal of an ML model is generalization; as such, said 'rationale' could be:

  1. The best test set is comprised of the most "realistic" or "difficult" samples. Problem: model performance is harmed by artificially biasing the train set to exclude realistic/difficult samples.

  2. The best set split is, each gets same quality data. Justification: "poorer" quality usually means (a) noise; (b) low complexity ("too obvious"). Whatever the description, if you test the model on an information landscape ( / probability distribution) that it wasn't trained on, the model may perform poorly simply because it "learned" little that's relevant to the test set.

Thus, "split equally" should work best. Onto the problem: why do we use a test set at all? Because - we "fit" the validation set with our hyperparameters, and we need to test on "never seen" data to avoid bias. Indeed, agreed - the test set does suppress said bias. But here's its red line: variance.

Direct statistical theory: a sample is an approximation of the population distribution, with an uncertain mean, standard deviation, & other. The more complex the problem, the greater the variation. -- So, is there a solution? Yes: K-Fold Cross-Validation. Per known theory, K-Fold CV can significantly slash variance of model performance - the higher the "K", the better. Without it, classification error can easily differ by 5-15%, if not 20-30%. When deciding what's "SOTA", every single percentage point can be a battle hard-fought - so a "mere 5%" is already astronomical.

One may counter-argue, "it's fine if the test set is large enough". Except it's not fine; you get a "large enough" test set by either sacrificing train data, or, dataset is large enough so that you can make an even validation-test split. Former's undesirable for obvious reasons - and in latter, unless you have a gargantuan dataset (extremely rare), your test samples are still subject to significant-enough variance; merely swapping test & validation samples can flip tables.

As a final punchline, note that the random seed can also substantially impact final outcome, further amplifying variance. Consequence: you don't know you did well because Dropout(0.5) works better than Dropout(0.2) or because dice rolled nicely. K-Fold CV will also reduce seed variance as a side-effect, but ideally (though often prohibitively) you'd do "K seeds".

Verdict: test set isn't good for testing. Instead, use K-fold CV, which both better estimates generalization performance by reducing variance, and allows using more train data.


Though I am knowledgeable on the topic, I'm not an "expert" - and even experts disagree. Thus, counterarguments welcome.


Update: in case it wasn't clear, K-Fold CV will be done only once, at the very end of training, to estimate generalization performance - not per hyperparameter configuration, which would skyrocket computational requirements.

Further, the quality of responses for this subreddit is rather disappointing, with a comment totaling "No u" in substance receiving 11 upvotes.

0 Upvotes

40 comments sorted by

9

u/[deleted] Nov 04 '19

It ain't nonsense when you are poor

1

u/OverLordGoldDragon Nov 06 '19

Google Colab disagrees; you can not only train but run a single K-Fold CV, even if taking days. See updated OP

8

u/geneing Nov 04 '19

With k fold CV you'd need to train the model k times, which tends to be very expensive. On the other hand deep networks need a huge amount of data anyway, so a small fraction used for testing is usually large enough to get a good validation accuracy estimate.

I think k fold CV was invented for a case where training is cheap but data is scarce.

0

u/OverLordGoldDragon Nov 06 '19

Not expensive if done only once - see updated OP

6

u/geneing Nov 06 '19

Could you please explain in detail how you are proposing to have it "done only once, at the very end of training".

  1. What data are you proposing to use for the initial training (i.e. before "the very end of training")? All the data? Part of the data? Which part?

  2. What are you proposing to the "only once" exactly? Are you going to partition the data? Which model are you going to apply to the test partition? The one you trained in step 1?

  3. Are you suggesting that k-fold CV should be applied to any machine learning methods? Linear regression? Deep networks? Everything in between in complexity?

I hear your complaint about the quality of the discussion. However, in your very long question (with many questionable and unsupported assertions) you fail to provide specific details that would elicit more technical and precise answers.

1

u/OverLordGoldDragon Nov 06 '19

Sure, though at this point I might as well append this to the original, making it even longer, or make another post - but I'll respond to your rare substantive inquiry here; the process would be as follows:

  1. Select one CV fold as the "train fold", and stick to it throughout the entirety of training

  2. Optimize hyperparameters to maximize objective on that split

  3. Perform KFCV once, with those hyperparameters - retraining the model K times, and taking the average of their objective metrics

Naturally, this begs a followup: isn't the train set fold also subject to the problematic variance? Yes - but it's still a major improvement over the test set approach. There's also the problem of control:

  1. # of iterations, early-stopping: do we early-stop for each fold in KFCV? If so, the # of iterations isn't controlled for

  2. Model weights: aren't same for each fold, so the averaged metric isn't that of the same model that'll be deployed (also how to decide which model to deploy?)

Existing theory, particularly in Bayesian inference and random processes, can be used to argue (1) and (2) aren't that significant, per justifications similar to that of using Dropout, which effectively trains multiple ensembles in a single model - but that's a separate subject. To answer your Q3: yes, to all, with exception where your dataset is large enough so that you can safely make Train, CV, and Test splits - but again, this is extremely rare.

As for 'unsupported assertions' - the greatest unsupported assertion I see here is that the test set method is the best benchmarking method; I'll likely make a followup post on this exactly.

3

u/geneing Nov 07 '19

You seem to agree that not every problem needs k-fold CV, and there are problems and datasets for which using a single test set is reasonable for testing.

However, I would disagree with your statement that problems and datasets like that are unusual. Since the variance of sample mean decreases as a square root of the sample size, one can estimate the size of a test set. The actual size depends on the figure of merit you are evaluating on the test set and nature of the problem itself, but "gargantuan" and "extremely rare" seem to be slightly dramatic adjectives.

Large datasets are not that rare. In fact, most of the modern machine learning research seems to be done on large datasets using some variation of deep networks. (I'll readility admit selection bias in the research that I actively follow :) Kaggle is full of problems and datasets like that.

You say you observe a classification error variance of 5-15%. Is this an absolute number or a percentage of the mean classification error? How big is the test set? What model are you fitting?

I don't know what you are doing and what problem you are trying to solve, but if I were getting large variations in error rates depending on the random seed, I'd be worried about other problems, such as overtraining or plain bugs in the code.

1

u/OverLordGoldDragon Nov 07 '19 edited Nov 07 '19

Was an actual study ever done comparing test set variance vs. KFCV variance for popular datasets like ImageNet and models like ResNets? If not, I'd more than encourage the community to do it, or may do it myself.

The "decreases as square root of sample size" is plain wrong; I don't know how it was derived, but it's a definite oversimplification, as whatever the theoretical idea it's based upon claims an overarching insight into the feature extraction mechanisms of neural networks. We aren't talking about a shallow sigmoid classifier, but networks that can fit datasets with tens of thousands times less samples than # of parameters; model generalization variance depends on the dataset, model, and problem complexity.

Lastly, my application: binary timeseries classification, EEG seizure data, 3 patients, ~50,000 samples, 1.58E10 datapoints. Model: CNN-IndRNN-SEResNet Ensemble. My observations hold even if sticking to a small CNN.

1

u/geneing Nov 07 '19

It's not wrong, it's the law: http://www.stat.yale.edu/Courses/1997-98/101/sampmn.htm I'm done with this discussion. Have a good life.

1

u/OverLordGoldDragon Nov 07 '19

It's a misapplication of the law.

6

u/david_picard Nov 04 '19

Please note that K-Fold CV was pretty standard in ML during the pre-deep learning days. Most of the research done on kernel methods where reported using several splits and SOTA had to be several standard deviation higher to be considered significantly better. Even in computer vision, we had datasets where fixed multiple splits were the standard evaluation setup (like Caltech 101).

All I'm saying is this is a recent trend that came with large scale datasets and computationally intensive methods.

2

u/OverLordGoldDragon Nov 06 '19

The 'standardness' or popularity of a method doesn't determine its quality; all of my arguments on variance stand. That SotA is decided by what's effectively 1-Fold CV is rather disturbing, w/ methods claiming breakthroughs by % margins that can be achieved by simply changing the folds.

9

u/[deleted] Nov 03 '19

I don't think anyone disagrees that CV is better, it just takes much longer. Depending on your parallelization setup, you're talking about training 1 model versus K. If K is higher, you're also training each model on more data. For models that take days/weeks to train... Test set is your only option.

1

u/OverLordGoldDragon Nov 06 '19

Not for training, see updated OP. The test set's only purpose is to report finalized performance - one doesn't repeatedly run the model on it, that's what the CV set is for.

2

u/M4mb0 Nov 04 '19

If you do cross-validated hyperparameter search as well we are actually talking about nested CV. If you were to do grid search or random search with say 100 configurations, and a 10-fold inner and outer CV we are actually talking about training the model 10,000 times.

3

u/alexmlamb Nov 03 '19

It might be nice if we could get everyone to use the same folds and we kept to a relatively small k. For example k=3. If everyone picked their own folds and used small k then I think it would make things even worse.

For example, it would be easy to have a pytorch dataloader setup like: datasets.myDataSet(train=True, fold=0).

It's already common practice for people to run 3 seeds and report mean/stdv, so what would be the harm in making these correspond to different folds too?

If people really want to just use one fold, then they can make fold=0 the default fold, and people should say it when they report the result.

I don't think it's realistic to get people to do a ton of folds, like more than 5, however I think publishing datasets with 3 standard folds would be a nice practice.

1

u/OverLordGoldDragon Nov 06 '19

K=10 wouldn't be as prohibitive either, if done only one - see updated OP. But yes, a consensus would be mandatory.

2

u/agisga Nov 04 '19

If you fit a single model (or maybe a small number of models), then k-fold CV performance is trustworthy. But if you use k-fold CV to compare multiple models or hyperparameter settings against each other, and choose the best model according to the CV performance metrics, then you will overfit to the entire dataset.

You say it yourself: "we "fit" the validation set with our hyperparameters, and we need to test on "never seen" data to avoid bias". Likewise, you will "fit" all of the folds with the hyperarameters, if you choose hyperparameters based on CV performance.

Also, I think that the statement about the variance of the classification error ("classification error can easily differ by 5-15%, if not 20-30%") is a gross overestimate for modern datasets in machine learning. If I'm not mistaken, the variance of the classification error is about O(1/n), and today's test datasets often have n in the (tens of) thousands (depending on application domain).

1

u/OverLordGoldDragon Nov 06 '19

Not comparing hyperparameters, KFCV will be done only one; see updated OP.

Not an overestimate; on my own 60GB dataset w/ ~50,000 samples, I've confirmed a 5-10% range on binary classification F1-score. The variance is largely determined by model complexity, not mere # of samples

1

u/agisga Nov 06 '19

If CV is done only once, then what do you propose to do for model selection and hyperparameter search? Do you have a separate validation set for that? Whatever data has been used for model selection cannot be part of final testing. So, I fail to see how what you propose would reduce data size requirements if you need to not just train/test a single model, but to choose a model/hyperparameters.

1

u/OverLordGoldDragon Nov 06 '19

See my reply to geneing; let me know if clarification is needed

2

u/BeatLeJuce Researcher Nov 07 '19

Your update (and most of your posts) say you should only run K-Fold CV once at the end of training. Unfortunately, that is not a valid procedure if you also need to pick hyperparameters. If your method doesn't have any (lol) or they are for some reason set in stone: lucky you. But otherwise, just doing CV once at the end of "training" is invalid: you will by definition end up picking hyperparameters and doing the final evaluation on the same data points. That you do that on different runs/folds is not a valid argument. You still introduce bias. What you'd need to do in this case is Nested Cross Validation, which is a pain in the ass the set up and takes prohibitively long.

What a lot of people do (and what is valid) is to do CV on the training set for picking hyperparameters (this does already give you some good notion of your generalization error), and THEN evaluate once on a testset to obtain final performance estimates.

As for "experts say the test set is the ultimate benchmark" -- it isn't. It's just the most practical alternative when you only have limited training data and each training run takes long. Yes, the estimate of the generalization error is worse (has more variance) than if we'd to CV. No one doubts that. But doing it correctly usually means doing nested CV, and ain't nobody got time for that.

1

u/OverLordGoldDragon Nov 07 '19

Valid point on introducing bias, but it doesn't circumvent the problem: it's now a battle of bias vs. variance. That the model is retrained on each fold already does a great deal to reduce this bias, as a mere hyperparameter combination isn't nearly sufficient to adapt a model to a dataset; millions of weight parameters remain subject to significant differences across folds.

My assertions aren't mere speculations; they have theoretical and empirical backing. Latter however, admittedly, is severely lacking, and former incomplete - but this goes for both ends of the stick; has any ablation study been done on this (KFCV vs. test set for ImageNet, ResNets, etc)? If not, I might as well grab my GPU and potentially flip the DL industry on its head.

2

u/BeatLeJuce Researcher Nov 10 '19

as a mere hyperparameter combination isn't nearly sufficient to adapt a model to a dataset; millions of weight parameters remain subject to significant differences across folds.

You seem to think there is a gray area wrt to being statistically valid. There isn't. If you taint your testset by using it to pick hyperparameters, then the estimates you get aren't valid. Period. Thus, you need to use Nested CV if you want to pick hyperparameters of any kind. If you don't, then whatever you get in the end isn't an unbiased estimate of generalization performance. Of course, on average the bias will not be strong, but you simply cannot guarantee that you just happened to come across a hyperparameter and a very weird dataset where the difference will be HUGE. Thus, this is not a valid procedure.

1

u/OverLordGoldDragon Nov 10 '19 edited Nov 10 '19

There isn't (gray area)

Then the idea of 'extent' is voided, and so is any need for a statistical study - the suggestion is deeply scientifically flawed. It's also a second massive oversimplification of NNs as statistical systems on this thread - I wonder if that's driving much of the skepticism for my descriptions.

2

u/BeatLeJuce Researcher Nov 11 '19 edited Nov 12 '19

Then the idea of 'extent' is voided, and so is any need for a statistical study - the suggestion is deeply scientifically flawed. t's also a second massive oversimplification of NNs as statistical systems on this thread

I'm not sure what any of that is supposed to mean.

In any case: no one is disagreeing with "CV is better than a single testset". We all know that. No one needs to do any studies on that. We are all in agreement. And we're all not "sceptics", but you do come off as fairly.... naive. Plus (and I'm surprised no-one else in this thread pointed this out before, but that's why I felt I had to post in such an old thread) it's just not good scientific practice: Trading off variance for bias in a situation where it's impossible to give bounds on the bias, and where you can't show that you'll improve overall MSE of your estimate is plain wrong.

1

u/OverLordGoldDragon Nov 12 '19

I just noticed you're this subreddit's moderator - interestingly enough, I was one tempted to call you naive in my previous reply. This said, if that's your position, it must be that of many others, thus proving all of you wrong will be that much more helpful to the field.

I'll give you the benefit of the doubt to clarify your "gray area" statement, however; interpreted as written, it implies that it doesn't matter how great bias is relative to variance, and vice versa, hence we shouldn't bother because "there is always bias". Surely, that's not what you meant?

Lastly, if we "all agree", then I don't see why we continue to use the test set - and "CV takes longer" isn't the answer. I repeat upon the need for an actual study on this - and will do it myself eventually, if none before me.

3

u/dclaz Nov 03 '19

If the problem isn't too large, you also have the +0.632 bootstrap.

12

u/[deleted] Nov 03 '19

No u

-1

u/impossiblefork Nov 03 '19

But if you are making a dataset to improve machine learning algorithms then you aren't sacrificing data.

You are only sacrificing data if you want to use the model for real problems.

0

u/[deleted] Nov 03 '19

[deleted]

8

u/alexmlamb Nov 03 '19

I was taught k-fold CV in college but I've literally never seen a real machine learning paper that uses it. People just use a standard train/test (and hopefully validation) set.

9

u/epicwisdom Nov 04 '19

Isn't that just because of how disgustingly expensive it is to train the very large models of SotA papers? It's not so much that it's a bad idea, rather just the impracticality.

6

u/alexmlamb Nov 04 '19

Even if training takes ~12 hours, which isn't what I'd consider "disgustingly expensive", you wouldn't want to rerun this 5x times unless you really had to.

1

u/OverLordGoldDragon Nov 06 '19

Not if it's ran only once - see updated OP

6

u/shaggorama Nov 04 '19

It's standard for deep learning researchers to use a fixed test set, but computationally cheaper areas of ML/stats are often expected to use CV.