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 will be enough. Thanks in advance.

$\endgroup$
  • 2
    $\begingroup$ Just split it twice. $\endgroup$ – Emre Aug 20 '16 at 19:32
  • $\begingroup$ Wouldn't that be somewhat ugly? I mean there must be a way in scikit-learn for that. $\endgroup$ – enterML Aug 20 '16 at 19:33
1
$\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.

| improve this answer | |
$\endgroup$
-1
$\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)

https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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