207 votes
Accepted

Train/Test/Validation Set Splitting in Sklearn

You could just use sklearn.model_selection.train_test_split twice. First to split to train, test and then split train again into validation and train. Something ...
user avatar
  • 2,412
75 votes

Train/Test/Validation Set Splitting in Sklearn

There is a great answer to this question over on SO that uses numpy and pandas. The command (see the answer for the discussion): ...
user avatar
  • 895
57 votes
Accepted

Merging multiple data frames row-wise in PySpark

Stolen from: https://stackoverflow.com/questions/33743978/spark-union-of-multiple-rdds Outside of chaining unions this is the only way to do it for DataFrames. ...
user avatar
52 votes
Accepted

What is the difference between bootstrapping and cross-validation?

Both cross validation and bootstrapping are resampling methods. bootstrap resamples with replacement (and usually produces new "surrogate" data sets with the same number of cases as the original ...
user avatar
43 votes
Accepted

Why use both validation set and test set?

Let's assume that you are training a model whose performance depends on a set of hyperparameters. In the case of a neural network, these parameters may be for instance the learning rate or the number ...
user avatar
  • 1,687
42 votes
Accepted

How to use the output of GridSearch?

Decided to go away and find the answers that would satisfy my question, and write them up here for anyone else wondering. The .best_estimator_ attribute is an instance of the specified model type, ...
user avatar
  • 1,642
32 votes
Accepted

How does the validation_split parameter of Keras' fit function work?

You actually would not want to resample your validation set after each epoch. If you did this your model would be trained on every single sample in your dataset and thus this will cause overfitting. ...
user avatar
  • 8,518
30 votes

Train/Test/Validation Set Splitting in Sklearn

Adding to @hh32's answer, while respecting any predefined proportions such as (75, 15, 10): ...
user avatar
24 votes
Accepted

How to calculate the fold number (k-fold) in cross validation?

The number of folds is usually determined by the number of instances contained in your dataset. For example, if you have 10 instances in your data, 10-fold cross-validation wouldn't make sense. $k$-...
user avatar
  • 8,518
23 votes
Accepted

Cross validation Vs. Train Validate Test

If k-fold cross-validation is used to optimize the model parameters, the training set is split into k parts. Training happens k times, each time leaving out a different part of the training set. ...
user avatar
  • 471
19 votes
Accepted

Cross Validation in Keras

From the Keras documentation, you can load the data into Train and Test sets like this: (X_train, y_train), (X_test, y_test) = mnist.load_data() As for cross ...
user avatar
17 votes

Why use both validation set and test set?

The test set and cross validation set have different purposes. If you drop either one, you lose its benefits: The cross validation set is used to help detect over-fitting and to assist in hyper-...
user avatar
  • 27.4k
16 votes
Accepted

When do I have to use aucPR instead of auROC? (and vice versa)

Yes, you are correct that the dominant difference between the area under the curve of a receiver operator characteristic curve (ROC-AUC) and the area under the curve of a Precision-Recall curve (PR-...
user avatar
  • 6,678
16 votes

Merging multiple data frames row-wise in PySpark

Sometime, when the dataframes to combine do not have the same order of columns, it is better to df2.select(df1.columns) in order to ensure both df have the same ...
user avatar
15 votes
Accepted

How to choose a classifier after cross-validation?

You do cross-validation when you want to do any of these two things: Model Selection Error Estimation of a Model Model selection can come in different scenarios: Selecting one algorithm vs others ...
user avatar
  • 1,470
13 votes
Accepted

Cross validation for highly imbalanced data with undersampling

You should always do your evaluation of model performance on data that has not been over/undersampled. You can setup a pipeline with scikit-learn to perform your undersampling on the training set and ...
user avatar
  • 662
12 votes

How to calculate the fold number (k-fold) in cross validation?

Depends on how much CPU juice you are willing to afford for the same. Having a lower K means less variance and thus, more bias, while having a higher K means more variance and thus, and lower bias. ...
user avatar
  • 8,036
11 votes
Accepted

What is GridSearchCV doing after it finishes evaluating the performance of parameter combinations that takes so long?

Yep I figured it out. The answer is that by default GridSearchCV's last act is to expose the API of the estimator object you passed so that you can directly call things like ...
user avatar
  • 1,694
10 votes
Accepted

Can overfitting occur even with validation loss still dropping?

I am not sure if the validation set is balanced or not. You have a severe data imbalance problem. If you sample equally and randomly from each class to train your network, and then a percentage of ...
user avatar
10 votes
Accepted

How to estimate GridSearchCV computing time?

You could fit your model/pipeline (with default parameters) to your data once and see how long it takes to train. Then you would multiply that by how many times you want to train the model through ...
user avatar
  • 7,568
10 votes
Accepted

Why you shouldn't upsample before cross validation

To see clearly why the procedure of upsampling before CV is mistaken and it leads to data leakage and other undesired consequences, it is useful to imagine first the simpler "baseline" case, ...
user avatar
  • 1,810
10 votes

Why is the k-fold cross-validation needed?

Given the randomization, it is unlikely that there will be a dramatic change from one run into the next one in the loop of the cross-validation. This assumption is wrong, it's true only if the ...
user avatar
  • 22.2k
9 votes

Train/Test/Validation Set Splitting in Sklearn

You can use train_test_split twice. I think this is most straightforward. ...
user avatar
9 votes
Accepted

Which is first ? Tuning the parameters or selecting the model

You can tune parameters only if you have already trained the model, otherwise there is nothing to tune. However, i've also read that model selection shoud be done before tuning the parameters. ...
user avatar
9 votes
Accepted

Validation vs. test vs. training accuracy. Which one should I compare for claiming overfit?

Which two accuracies I compare to see if the model is overfitting or not? You should compare the training and test accuracies to identify over-fitting. A training accuracy that is subjectively far ...
user avatar
  • 8,629
8 votes
Accepted

Cross-validation: K-fold vs Repeated random sub-sampling

If you have an adequate number of samples and want to use all the data, then k-fold cross-validation is the way to go. Having ~1,500 seems like a lot but whether it is adequate for k-fold cross-...
user avatar
  • 836
8 votes

Does modeling with Random Forests require cross-validation?

By default random forest picks up 2/3rd data for training and rest for testing for regression and almost 70% data for training and rest for testing during classification.By principle since it ...
user avatar
  • 571
8 votes
Accepted

Nested cross-validation and selecting the best regression model - is this the right SKLearn process?

Yours is not an example of nested cross-validation. Nested cross-validation is useful to figure out whether, say, a random forest or a SVM is better suited for your problem. Nested CV only outputs a ...
user avatar
8 votes

How to choose a classifier after cross-validation?

No. You don't select any of the k classifiers built during k-fold cross-validation. First of all, the purpose of cross-validation is not to come up with a predictive model, but to evaluate how ...
user avatar
  • 1,153
8 votes
Accepted

Using Cross Validation technique for a CNN model

Question 1: Why do most CNN models not apply the cross-validation technique? $k$-fold cross-validation is often used for simple models with few parameters, models with simple hyperparameters and ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible