8 Types of Sampling Techniques
By: Prakhar Mishra
Tags: Statistics, Python, Data Science, Probability, Machine Learning

8 Types of Sampling Techniques

Image from Author

Sampling is the process of selecting a subset(a predetermined number of observations) from a larger population. It’s a pretty common technique wherein, we run experiments and draw conclusions about the population, without the need of having to study the entire population. In this blog, we will go through two types of sampling methods:

Probability Sampling —Here we choose a sample based on the theory of probability. Non-Probability Sampling — Here we choose a sample based on non-random criteria, and not every member of the population has a chance of being included.

Random Sampling

Under Random sampling, every element of the population has an equal probability of getting selected. Below fig. shows the pictorial view of the same — All the points collectively represent the entire population wherein every point has an equal chance of getting selected.

Random Sampling

You can implement it using python as shown below —

import random population = 100

data = range(population) print(random.sample(data,5))

> 4, 19, 82, 45, 41

Stratified Sampling

Under stratified sampling, we group the entire population into subpopulations by some common property. For example — Class labels in a typical ML classification task. We then randomly sample from those groups individually, such that the groups are still maintained in the same ratio as they were in the entire population. Below fig. shows a pictorial view of the same — We have two groups with a count ratio of x and 4x based on the colour, we randomly sample from yellow and green sets separately and represent the final set in the same ratio of these groups.

Stratified Sampling

You can implement it very easily using python sklearn lib. as shown below —

from sklearn.model_selection import train_test_split



stratified_sample, _ = train_test_split(population, test_size=0.9, stratify=population[['label']])

print (stratified_sample)

You can also implement it without the lib., read this.

Cluster Sampling

In Cluster sampling, we divide the entire population into subgroups, wherein, each of those subgroups has similar characteristics to that of the population when considered in totality. Also, instead of sampling individuals, we randomly select the entire subgroups. As can be seen in the below fig. that we had 4 clusters with similar properties (size and shape), we randomly select two clusters and treat them as samples.

Cluster Sampling

Real-Life example — Class of 120 students divided into groups of 12 for a common class project. Clustering parameters like (Designation, Class, Topic) are all similar over here as well.

You can implement it using python as shown below —

import numpy as np clusters=5

pop_size = 100

sample_clusters=2 #assigning cluster ids sequentially from 1 to 5 on gap of 20

cluster_ids = np.repeat([range(1,clusters+1)], pop_size/clusters) cluster_to_select = random.sample(set(cluster_ids), sample_clusters) indexes = [i for i, x in enumerate(cluster_ids) if x in cluster_to_select] cluster_associated_elements = [el for idx, el in enumerate(range(1, 101)) if idx in indexes] print (cluster_associated_elements)

Systematic Sampling

Systematic sampling is about sampling items from the population at regular predefined intervals(basically fixed and periodic intervals). For example — Every 5th element, 21st element and so on. This sampling method tends to be more effective than the vanilla random sampling method in general. Below fig. shows a pictorial view of the same — We sample every 9th and 7th element in order and then repeat this pattern.

Systematic Sampling

You can implement it using python as shown below —

population = 100

step = 5 sample = [element for element in range(1, population, step)]

print (sample)

Multistage sampling

Under Multistage sampling, we stack multiple sampling methods one after the other. For example, at the first stage, cluster sampling can be used to choose clusters from the population and then we can perform random sampling to choose elements from each cluster to form the final set. Below fig. shows a pictorial view of the same —

Multi-stage Sampling

You can implement it using python as shown below —