Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Train Test Split | Recognizing Handwritten Digits
Recognizing Handwritten Digits

book
Train Test Split

In Python, the train_test_split function, part of the sklearn.model_selection module, is frequently utilized for dividing a dataset into two parts: a training subset and a testing subset.

This train_test_split() function performs a random partitioning of the dataset into these subsets, determined by a predefined test size or train size.

Compito

Swipe to start coding

  1. Split the dataset into training and test sets. Use only the first 1000 samples for splitting.

  2. Print the shapes and sizes of the resulting training and test sets for both the feature matrix and the target vector.

Soluzione

from sklearn.model_selection import train_test_split

# Split the data
X_train, X_test, y_train, y_test = train_test_split(X[:1000], Y[:1000], test_size=1/7)

# Print the resulting shapes and sizes
print('TRAIN Feature matrix shape:', X_train.shape)
print('TRAIN Target vector size:', y_train.size)
print('TEST Feature matrix shape:', X_test.shape)
print('TEST Target vector size:', y_test.size)

Mark tasks as Completed
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 6
AVAILABLE TO ULTIMATE ONLY
some-alt