Notes

Random Sampling

When you build a supervised model, you’re trying to learn patterns that generalize beyond the examples you happened to collect. Random sampling is the simple idea of picking data points “by chance” so your training and evaluation sets look like the same underlying population.

What random sampling means in practice

In model development, random sampling usually shows up as randomly selecting rows to form a train/validation/test split. Each example has an equal probability of landing in each split (given the chosen proportions), which helps prevent you from accidentally creating a training set that’s systematically easier or harder than the test set. In scikit-learn, this is the default behavior of utilities like train_test_split when shuffle=True, controlled by a random seed (random_state) so results are reproducible.

Why it matters for supervised learning

Most evaluation metrics assume the test set is a fair “miniature” of what the model will see after deployment. Random sampling supports that assumption by reducing selection bias. If you ignore it and split data in a biased way, you can get:

  • Over-optimistic performance (test set too similar to training examples)
  • Over-pessimistic performance (test set contains a different subpopulation)
  • Unstable results that change wildly from run to run without a fixed random_state
Concrete examples (and common caveats)

For spam detection, random sampling can create balanced-looking splits where both train and test include a mix of spam and non-spam. For credit scoring, it helps ensure borrowers across income ranges appear in each split. Two important caveats: use stratified sampling when classes are imbalanced, and avoid naive random splits for time-ordered data (demand forecasting) or grouped data (multiple rows per customer), where time-based or group-based splitting is safer.

Random sampling is selecting data points from a dataset by chance, typically with equal selection probability, to form subsets such as training, validation, and test sets. In supervised learning, it matters because it reduces selection bias and helps ensure each split reflects the same underlying data distribution, making performance estimates more reliable. Example: randomly assigning 80% of labeled examples to training and 20% to testing.

Imagine you have a huge jar of mixed candies and you want to guess what kinds are inside. Instead of counting every candy, you grab a handful without looking. If your grab is fair, that handful should look like the whole jar.

Random sampling is that “fair handful” idea applied to data. When building an AI model, you often need to split your data into parts, like a set to learn from and a set to check how well it learned. By choosing examples at random, you reduce the chance of accidentally picking only one type of case (like only easy emails) and getting a misleading result.