# Oversampling of data set for class balancing

We have a set of $$n$$ three-dimensional vectors:

{{x_1, y_1, z_1}, {x_2, y_2, z_2}, {x_3, y_3, z_3}, ..., {x_n, y_n, z_n}}


They represent the results of $$n$$ measurements of three features and are assigned to some minority class.

I am going to artificially generate more data points to obtain a more abundant class for training.

For this purpose, I plan to combine the original points into pairs of nearest neighbors and create of them a net of tetrahedrons. Then I want to put an additional point in the middle of each edge. It would be even better to place these points in the middle of the formed triangles and most preferably in the middle of the tetrahedrons.

In this way, I would obtain an artificial increase in the density of the data series.

This is useful, inter alia, for class balancing for machine learning like in SMOTE procedure.

Does anyone from Dear Colleagues have an idea how to achieve this effect? Or maybe you know the way how to do something like that in a smarter way?

The following is not exactly what you described, mostly because I do not fully understand your request about networks of tetrahedra. Perhaps you will clarify that part.

Anyway, here goes. Let's generate some points to play with:

pts = RandomReal[{-2, 2}, {50, 3}];


This first finds the nearest neighbors to each point in the cloud, then generates a new point that is the average between these two nearest neighbors:

newpts = Mean[{#, First@Nearest[Complement[pts, {#}], #, 1]}] & /@ pts;

ListPointPlot3D[
{pts, newpts},
PlotStyle -> PointSize[0.02], PlotRange -> All,
PlotLegends -> {"original pts", "new pts"}
]


• If I have points distributed like this: A ---- B -------- C ---- D, the function proposed by you will place additional points this way: A-E-B -------- C-F-D This will increase the density of points in already dense areas. This will act on a scale of single points with an accidental location. It threatens with overfitting the classifier. I would prefer to create a triangulation grid of points, sth like Mesh. In 1D, we will encounter segments, in 2D - triangles, in 3D - tetrahedrons (symplices of the respective dimension). Then, I would put additional points in the middle of such symplices. – Druid Mar 27 at 10:37