← Writing
Data & Analytics

A Guide to Sampling Techniques: CRISP-DM Data Preparation

Data Mastery Series — Episode 7: Data Sampling

3 Mar 20236 min readMachine Learning
CRISP-DM · Part 3 of 9

A Guide to Sampling Techniques: CRISP-DM Data Preparation

Data Mastery Series — Episode 7: Data Sampling

If you are interested in articles related to my experience, please feel free to contact me: linkedin.com/in/nattapong-thanngam


CRISP-DM framework (Image by Author)

Sampling is the process of selecting a subset of data from a larger population to estimate characteristics of the whole population. It is an essential technique used in statistical analysis to make inferences about a larger group based on a smaller sample. In this blog, we will go through two types of sampling methods:

  1. Probability sampling techniques involve selecting samples at random from the population with a known probability of selection. The sampling techniques in this group, such as simple random sampling, systematic sampling, and stratified sampling, are considered more rigorous and statistically sound.
  2. Non-probability sampling techniques, on the other hand, do not involve random selection and may not represent the population accurately. The sampling techniques in this group, such as first/last records, column values subset, and class rebalancing, are less rigorous and less representative of the population.

There are various sampling techniques that are commonly used in data analysis, and in this article, we will discuss some of the most popular ones. We will go through each technique and explain how it works, its advantages, and its limitations.

Data Set:

  • The dataset is a randomly generated dataset that provides a sample of information about final exam grades. It contains 32 rows of data, each representing a single student.
  • The distribution of final exam grades for the students is as follows: 4, 8, 8, 8, and 4 for the grades 4, 3, 2, 1, and 0, respectively.
  • In order to show the differences between each sampling strategy based on the “Final Exam Grade,” this blog will use a sampling technique on the dataset with a sample size of 25%.
  • First records
    This sampling technique involves selecting the first few records in the dataset as the sample. This technique is straightforward to implement but may not be representative of the entire population if the first records are not representative. In this example, the first 8 rows are designated as the sample, while the remaining rows are used as the testing set.

First records — sampling techniques (Image by Author)

First records — sampling techniques (Image by Author)

  • Last records
    This sampling technique involves selecting the last few records in the dataset as the sample. Like the first records technique, this technique is easy to implement but may not be representative of the entire population. In this example, the last 8 rows are designated as the sample, while the remaining rows are used as the testing set.

Last records — sampling techniques (Image by Author)

Last records — sampling techniques (Image by Author)

  • Systematic Sampling
    This technique involves selecting every nth record from the population. For instance, if the interval is 4, every first data point out of four data points will be selected as a sample. This technique can be useful when the population is large and ordered.

Systematic Sampling — sampling techniques (Image by Author)

Systematic Sampling — sampling techniques (Image by Author)

  • Random Sampling (Fixed Number of Records)
    This technique involves selecting a fixed number of records at random from the population. This technique can be useful when the population size is known, and a specific sample size is required. In this example, 8 data points are used to construct the sample.

Random Sampling (Fixed Number of Records) — sampling techniques (Image by Author)

Random Sampling (Fixed Number of Records) — sampling techniques (Image by Author)

  • Random Sampling (Approximate Ratio)
    This technique involves selecting a random subset of records based on a specific ratio. For instance, a particular ratio like 25% of the dataset can be assigned to the sample. This method is widely used in data science, and the implementation can be easily done using the sklearn.model_selection import train_test_split module.

Random Sampling (Approximate Ratio) — sampling techniques (Image by Author)

Random Sampling (Approximate Ratio) — sampling techniques (Image by Author)

  • Stratified Sampling:
    This technique involves dividing the population into subgroups or strata based on specific criteria and selecting a random sample from each subgroup. For example, data can be divided into subgroups based on Final Exam Grade, and then select a random sample from each subgroup. This technique is useful when we want to ensure that the sample is representative of the entire population.

Stratified Sampling — sampling techniques (Image by Author)

Stratified Sampling — sampling techniques (Image by Author)

Note:

  • Please note that the results of running the code may vary due to the use of the random method. To ensure consistent results, you may want to consider specifying a random seed.
  • In conclusion, selecting an appropriate sampling technique is critical to obtaining a representative sample from the population. The choice of technique depends on the characteristics of the population and the research questions being addressed. By selecting a representative sample, researchers can draw valid inferences about the entire population.
  • Sampling techniques in machine learning can provide several benefits such as reducing computation time, saving costs, and improving interpretability, especially when working with very large datasets.
  • If you’re interested in learning more about different sampling techniques, check out this article on Towards Data Science: “8 Types of Sampling Techniques.” It’s a great resource.

Please feel free to contact me, I am willing to share and exchange on topics related to Data Science and Supply Chain. Facebook: facebook.com/nattapong.thanngam
Linkedin: linkedin.com/in/nattapong-thanngam

Originally published on Medium

Related