Back to questions
JuniorTheoryCommon
What does this program print?
import numpy as np
from sklearn.model_selection import train_test_split
X = np.array([[1, 0], [2, 1], [3, 0], [4, 1], [5, 0], [6, 1], [7, 0], [8, 1]])
y = np.array([10, 20, 30, 40, 50, 60, 70, 80])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=0)
print(X_train.shape[0], X_test.shape[0], y_test.shape[0])6 2 2
- Expecting
2 6 6:test_size=0.25is the share of rows that go to the test set, so 2 of the 8 rows are test rows and 6 stay for training. - Expecting
yto stay whole:train_test_splitsplits every array it gets by the same rows, soy_testholds the 2 answers of the 2 test rows.
- How many test rows would the same call produce for 10 rows, and why?
- Why does a fixed
random_statematter when you compare two versions of a model?