Shape / rows · All operations
Oversample or draw with replacement
A variant of Sample rows
Draw rows with replacement, or synthesise new minority-class rows, so rows can appear more than in the input.
Status
- In arcform
Runs as a SQL step
arcform carries it as a
sql:step today.
The DuckDB step
Draw rows with replacement, and synthesise new minority rows
CREATE TEMP TABLE points AS SELECT * FROM (VALUES
(1, 'major', 1.0, 5.0), (2, 'major', 2.0, 6.0), (3, 'major', 3.0, 4.0), (4, 'major', 4.0, 7.0),
(5, 'major', 5.0, 5.0), (6, 'major', 6.0, 6.0), (7, 'major', 7.0, 4.0), (8, 'major', 8.0, 7.0),
(9, 'minor', 0.0, 0.0), (10, 'minor', 1.0, 1.0), (11, 'minor', 10.0, 10.0)
) t(id, class, x1, x2);
-- 1. draw with replacement: eight rows from the three minority rows, each pick a seeded hash of its draw number
CREATE TEMP TABLE minor AS SELECT *, row_number() OVER (ORDER BY id) AS k FROM points WHERE class = 'minor';
CREATE TEMP TABLE drawn AS
SELECT d.draw, m.id, m.class, m.x1, m.x2
FROM range(8) d(draw)
JOIN minor m ON m.k = 1 + hash(d.draw::VARCHAR || '-draw-3') % (SELECT count(*) FROM minor);
-- 2. synthesise: each new row sits on the line from a minority row to its nearest minority neighbour (SMOTE)
CREATE TEMP TABLE neighbour AS
SELECT a.id AS seed_id, b.id AS neighbour_id, a.x1 AS a1, a.x2 AS a2, b.x1 AS b1, b.x2 AS b2
FROM minor a JOIN minor b ON a.id <> b.id
QUALIFY row_number() OVER (PARTITION BY a.id ORDER BY (a.x1 - b.x1) ^ 2 + (a.x2 - b.x2) ^ 2, b.id) = 1;
CREATE TEMP TABLE seeds AS SELECT *, row_number() OVER (ORDER BY seed_id) AS k FROM neighbour;
CREATE TEMP TABLE synthetic AS
SELECT d.draw, s.seed_id, s.neighbour_id,
s.a1 + u * (s.b1 - s.a1) AS x1, s.a2 + u * (s.b2 - s.a2) AS x2
FROM (SELECT draw, 0.05 + 0.9 * (hash(draw::VARCHAR || '-gap-9') % 1000) / 1000.0 AS u FROM range(5) t(draw)) d
JOIN seeds s ON s.k = 1 + d.draw % (SELECT count(*) FROM seeds);
SELECT draw, id FROM drawn ORDER BY draw;
SELECT * FROM synthetic ORDER BY draw;
SELECT CASE WHEN ((SELECT count(*) FROM drawn) = 8 AND (SELECT count(DISTINCT id) FROM drawn) BETWEEN 2 AND 7 AND (SELECT bool_and(id IN (9, 10, 11)) FROM drawn) AND (SELECT list((seed_id, neighbour_id) ORDER BY seed_id) FROM neighbour) = [(9, 10), (10, 9), (11, 10)] AND (SELECT count(*) FROM synthetic) = 5 AND (SELECT count(*) FROM synthetic s JOIN points p ON p.x1 = s.x1 AND p.x2 = s.x2) = 0 AND (SELECT bool_and(x1 BETWEEN 0 AND 10 AND x2 BETWEEN 0 AND 10 AND x1 = x2) FROM synthetic) AND (SELECT 3 + count(*) FROM synthetic) = (SELECT count(*) FROM points WHERE class = 'major')) THEN 'as expected' ELSE error('the draw was not eight rows with repeats from the minority class, or the synthetic rows were not five new points between a minority row and its nearest neighbour') END AS verdict;- The statement builds its own data.
- It needs nothing installed beyond DuckDB itself.
- The statement checks its own result and raises an error when it is wrong: “the draw was not eight rows with repeats from the minority class, or the synthetic rows were not five new points between a minority row and its nearest neighbour”.
- It passed on DuckDB
v2.0.0 (Cyanoptera) d54cbbe3df.
What other tools call it
Meridian's classification; an independent blind rating agreed on 95.7% of 324 rows (variant, version 3).
Alteryx Designer (1)
Oversample Fieldread 2026-09-27Resample so a chosen value of a field reaches a target share, for imbalanced binary targets
KNIME Analytics Platform (2)
Bootstrap Samplingread 2026-09-27Draw rows at random with replacement
SMOTEread 2026-09-27Oversample by synthesising artificial minority-class rows (SMOTE)
RapidMiner Studio (2)
SMOTE Upsamplingread 2026-09-27Oversample the minority class by synthesising rows between nearest neighbours (SMOTE)
Sample (Bootstrapping)read 2026-09-27Sample rows with replacement (bootstrap)
Background
Oversampling is a technique used to adjust the class distribution of a data set, the ratio between the different classes it represents.[1] Random oversampling supplements training data with multiple copies of some of the minority classes, which may be chosen at random with replacement.[1] More complex oversampling techniques create artificial data points, with algorithms such as the synthetic minority oversampling technique (SMOTE).[1]
When to use it
A dataset is imbalanced if the classification categories are not approximately equally represented.[2] Real-world data sets are often predominately composed of normal examples with only a small percentage of abnormal or interesting examples.[2] Oversampling and undersampling introduce a bias to select more samples from one class than from another, to compensate for an imbalance already present in the data or likely to develop in a purely random sample.[1]
Resampling the entire dataset before splitting it into training and test partitions is a common pitfall that leads to data leakage.[3] Data leakage from resampling makes the reported performance of a model over-optimistic.[3] Resampling the whole dataset means the model is not tested on data with a class distribution like the real use case, and the resampling may use information from samples later used for testing.[3] Split the data first, oversample the training set alone, and evaluate on rows that keep their natural class shares. (Meridian's view)
SMOTE has been shown to yield poorly calibrated models, with an overestimated probability of belonging to the minority class.[1] SMOTE might connect inliers and outliers, which might lead to a sub-optimal decision function.[4] An oversampled table can hold repeated rows and rows that never existed, so count distinct keys rather than rows when checking it against its source, and keep a column that marks the synthetic rows. (Meridian's view)
The method
Bootstrapping is a procedure for estimating the distribution of an estimator by resampling, often with replacement, one's data or a model estimated from the data.[5] For observations that can be assumed independent and identically distributed, bootstrapping can be implemented by constructing resamples with replacement of the observed data set, each of equal size to it.[5] The bootstrap was first described by Bradley Efron in "Bootstrap methods: another look at the jackknife" (1979).[5]
The Synthetic Minority Over-sampling Technique was published by N. V. Chawla, K. W. Bowyer, L. O. Hall and W. P. Kegelmeyer in the Journal of Artificial Intelligence Research, Vol. 16 (2002).[2] SMOTE over-samples the minority class by creating synthetic minority class examples.[2] SMOTE generates a new sample from a minority sample by selecting one of its k nearest neighbours and placing the new sample at a random point on the line between the two.[4][1] In imbalanced-learn, RandomOverSampler over-samples by duplicating some of the original minority samples, while SMOTE and the Adaptive Synthetic (ADASYN) method generate new samples by interpolation.[4] In imbalanced-learn, of the over-sampling methods presented, only RandomOverSampler can deal with the categorical features in mixed data, and SMOTENC is an extension of SMOTE that treats categorical data differently.[4]
Compared with the alternatives
Oversampling and undersampling are opposite and roughly equivalent techniques.[1] Combining SMOTE's over-sampling of the minority class with under-sampling of the majority class can achieve better classifier performance in Receiver Operating Characteristic (ROC) space than under-sampling the majority class alone.[2] A key result of Efron's paper introducing the bootstrap was the favourable performance of bootstrap methods using sampling with replacement, compared with prior methods like the jackknife that sample without replacement.[5]
Sources
- [1]Oversampling and undersampling in data analysis - Wikipediasecondary source
- [2]SMOTE: Synthetic Minority Over-sampling Technique | Journal of Artificial Intelligence Researchsecondary source
- [3]9. Common pitfalls and recommended practices — Version 0.14.2documentation
- [4]2. Over-sampling — Version 0.14.2documentation
- [5]Bootstrapping (statistics) - Wikipediasecondary source