官术网_书友最值得收藏!

How to do it...

The following steps demonstrate how to take a dataset, consisting of features X and labels y, and split these into a training and testing subset:

  1. Start by importing the train_test_split module and the pandas library, and read your features into X and labels into y:
from sklearn.model_selection import train_test_split
import pandas as pd

df = pd.read_csv("north_korea_missile_test_database.csv")
y = df["Missile Name"]
X = df.drop("Missile Name", axis=1)
  1. Next, 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
)
  1.  We 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
)
  1. We end up with a training set that's 60% of the size of the original data, a validation set of 20%, and a testing set of 20%.

The following screenshot shows the output:

主站蜘蛛池模板: 周口市| 梅河口市| 方城县| 胶州市| 柳江县| 乌兰浩特市| 忻城县| 双流县| 辉县市| 莱阳市| 阜阳市| 文登市| 双牌县| 江口县| 会宁县| 沙湾县| 达日县| 永靖县| 石景山区| 河池市| 汝南县| 卢氏县| 池州市| 安仁县| 乌兰浩特市| 安徽省| 兰坪| 惠水县| 宣恩县| 河北区| 南丹县| 多伦县| 忻城县| 图们市| 金堂县| 安平县| 文山县| 滁州市| 育儿| 荆门市| 板桥市|