Files
labs/Module-3/1.Train-Test-Split.ipynb

3.4 KiB

In [ ]:
from sklearn.model_selection import train_test_split
import pandas as pd
In [ ]:
df = pd.read_csv("./north_korea_missile_test_database.csv")
In [ ]:
y = df["Missile Name"]
x = df.drop("Missile Name", axis=1)
In [ ]:
print(y.shape)

print(x.shape)
In [ ]:
# Randomly split the dataset and its labels into a training set consisting 80% of the size of the original dataset and a testing set 20% of the size
X_train, X_test, y_train, y_test = train_test_split(x,y,test_size=0.2, random_state = 31)
In [ ]:
# We will apply the train_test_split method once more, to obtain a validation set, x_val and y_val
X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size = 0.25, random_state=31)
In [ ]:
# 60% of the size of the original data, a validation set of 20% and a testing set of 20%
print(len(X_train))
print(len(y_train))
print(len(X_val))
print(len(y_val))
print(len(X_test))
print(len(y_test))
In [ ]:
print(y_train)
In [ ]:
print(y_val)
In [ ]:
print(y_test)
In [ ]:
In [ ]: