0
$\begingroup$

I know how to split the dataset into train and test sets using train_test_split but is there any way that I can split the dataset into three different sets, i.e., "Train set", "Test set" and "Validation Set". An example should be enough.

$\endgroup$
2
  • 3
    $\begingroup$ Just split it twice. $\endgroup$
    – Emre
    Aug 20, 2016 at 19:32
  • 1
    $\begingroup$ Wouldn't that be somewhat ugly? I mean there must be a way in scikit-learn for that. $\endgroup$
    – enterML
    Aug 20, 2016 at 19:33

2 Answers 2

2
$\begingroup$

train_test_split is just a utility function around ShuffleSplit, which on its turn just randomly assigns each sample to either train or test, taking the desired probability into account. You can do that however you'd like, and there's no real reason to use that specific function.

Its not too hard to come up with some code that does that for three values or N values, if you rather avoid calling train_test_split twice.

$\endgroup$
0
$\begingroup$

Here you go.

import numpy as np
from sklearn.model_selection import train_test_split

X, y = np.arange(10).reshape((5, 2)), range(5)

list(y)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
X_train

y_train
X_test

y_test

train_test_split(y, shuffle=False)

Check this link.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.