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

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:

主站蜘蛛池模板: 崇仁县| 景德镇市| 全州县| 杂多县| 潼南县| 公安县| 雅江县| 巢湖市| 德令哈市| 南昌县| 澳门| 大新县| 高青县| 毕节市| 始兴县| 河池市| 来凤县| 清流县| 新野县| 启东市| 蓬莱市| 凌源市| 青冈县| 翼城县| 广西| 城固县| 雅江县| 石狮市| 建平县| 平度市| 五大连池市| 寿阳县| 彭阳县| 鹰潭市| 察隅县| 祁门县| 麻阳| 滨州市| 财经| 修水县| 安龙县|