liveBook · Manning

Dataset split

As explained in Cyber Threat Hunting

A train-test split partitions a labeled data set into separate subsets for model training and performance evaluation.

A train-test split partitions labeled data into separate subsets: one trains a supervised machine-learning model, while the other evaluates its performance. section 9.2.5

Use a practical split workflow:

  • Start with an 80-20 split, assigning 80% of the data to training and 20% to testing. section 9.2.5
  • Check that class distributions remain approximately balanced in both subsets. section 9.2.5
  • Continue preprocessing with feature scaling before applying PCA to the training data. section 9.2.5

Splitting a labeled data set

Separate feature columns from the class label, then call scikit-learn’s train_test_split with test_size=0.2 and random_state=42 to produce X_train, X_test, y_train, and y_test. section 9.2.5

Listing 9.12 Splitting df_orig_selected
from sklearn.model_selection import train_test_split                #1
 
X = df_orig_selected.drop(‚class', axis=1)                          #2
y = df_orig_selected['class']                                       #3
X_train, X_test, y_train, y_test = \
    train_test_split(X, y, test_size=0.2, random_state=42           #4

Inspect the concrete Python split used to create training and testing features and labels. section 9.2.5

How Cyber Threat Hunting covers it

How deep it goes
Explains an 80-20 workflow, verifies class balance, and stops before model evaluation details.
Examples
Uses 20,001 labeled data points, X_train and X_test shapes, and pie charts showing class distributions.
What it assumes
Assumes labeled data and supervised-learning context while establishing the need for separate training and evaluation sets.
What you can do after
Apply it via scikit-learn to create training and testing subsets and inspect their class balance.
How it connects
Connects supervised machine learning with class balance, feature scaling, and principal component analysis.

Also explained in

Compare how 21 books explain dataset split →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Cyber Threat Hunting. The section links point to the parts of the book it draws on.