Write a python code to divide the data set into two parts as 70 % for training and 30 % for testing
Answers
Answered by
0
The simplest way would be to use train_test_split (sklearn module) and set shuffle to False. Shuffle takes priority over the random_state parameter. So, if you set shuffle as FALSE, the first n observations (i.e. 90 rows) in your dataset will go to the train dataset, and the last 10 rows would go to the test dataset. Code:
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.10, shuffle=False)
If the partition is fixed, then you can use this code
train_pct_index = int(0.9 * len(X))
X_train, X_test = X[:train_pct_index], X[train_pct_index:]
y_train, y_test = y[:train_pct_index], y[train_pct_index:]
Similar questions
Social Sciences,
4 months ago
Computer Science,
4 months ago
Physics,
9 months ago
Biology,
1 year ago
Biology,
1 year ago