In When One Class Is Rare, SMOTE gave the rare class more rows by interpolating between real ones: each new row is a plausible point placed between a real rare row and one of its rare neighbours, not a copy. Here you build that step yourself.
To make one new row, SMOTE:
feature by feature. So lands exactly on , lands exactly on , and lands halfway between them.
The library makes the choices in steps 3 and 4 at random. To make your output checkable, every new row here comes with its choices written down.
Task: write smote_rows(X, y, minority, recipes).
X is a list of rows, each a list of numbers, and y holds one label per row. minority is the rare class's label.recipes is a list of (row, rank, gap) tuples, one per new row. row is the index in X of the starting rare row . rank picks the neighbour : 1 is the nearest other rare row, 2 the second nearest, and so on. gap is .X counts as nearer.Return the new rows, one per recipe and in the same order, with every value rounded to 4 decimal places.
In every test, each recipe's row is a rare row, and its rank is never more than the number of other rare rows.