Skip to contents

Data balance. Most classes adopt random undersampling, while a few classes adopt smote method to oversample to obtain relatively balanced data;

Usage

mi_balance_data(data, ratio = 0.3, parallel = FALSE)

Arguments

data

A data frame. Except for class column, all are numeric types.

ratio

Numeric between 0 and 1. The percent of the test set split from data.

parallel

Logical.

Value

A list contains a train set and a test set.

Examples

library(dplyr)
data <- rename(iris, class = Species)
mi_balance_data(data)
#> [[1]]
#>     Sepal.Length Sepal.Width Petal.Length Petal.Width      class
#> 1            4.9         3.0          1.4         0.2     setosa
#> 2            4.7         3.2          1.3         0.2     setosa
#> 3            4.6         3.1          1.5         0.2     setosa
#> 4            5.0         3.6          1.4         0.2     setosa
#> 5            5.4         3.9          1.7         0.4     setosa
#> 6            4.6         3.4          1.4         0.3     setosa
#> 7            4.4         2.9          1.4         0.2     setosa
#> 8            4.9         3.1          1.5         0.1     setosa
#> 9            5.4         3.7          1.5         0.2     setosa
#> 10           4.8         3.4          1.6         0.2     setosa
#> 11           4.8         3.0          1.4         0.1     setosa
#> 12           5.8         4.0          1.2         0.2     setosa
#> 13           5.7         4.4          1.5         0.4     setosa
#> 14           5.4         3.9          1.3         0.4     setosa
#> 15           5.4         3.4          1.7         0.2     setosa
#> 16           5.1         3.7          1.5         0.4     setosa
#> 17           4.6         3.6          1.0         0.2     setosa
#> 18           5.1         3.3          1.7         0.5     setosa
#> 19           4.8         3.4          1.9         0.2     setosa
#> 20           5.2         3.5          1.5         0.2     setosa
#> 21           4.7         3.2          1.6         0.2     setosa
#> 22           4.8         3.1          1.6         0.2     setosa
#> 23           5.4         3.4          1.5         0.4     setosa
#> 24           5.2         4.1          1.5         0.1     setosa
#> 25           5.5         4.2          1.4         0.2     setosa
#> 26           5.0         3.2          1.2         0.2     setosa
#> 27           5.5         3.5          1.3         0.2     setosa
#> 28           4.9         3.6          1.4         0.1     setosa
#> 29           5.1         3.4          1.5         0.2     setosa
#> 30           5.0         3.5          1.3         0.3     setosa
#> 31           4.5         2.3          1.3         0.3     setosa
#> 32           5.0         3.5          1.6         0.6     setosa
#> 33           5.1         3.8          1.9         0.4     setosa
#> 34           4.8         3.0          1.4         0.3     setosa
#> 35           5.0         3.3          1.4         0.2     setosa
#> 36           7.0         3.2          4.7         1.4 versicolor
#> 37           6.4         3.2          4.5         1.5 versicolor
#> 38           6.9         3.1          4.9         1.5 versicolor
#> 39           5.5         2.3          4.0         1.3 versicolor
#> 40           5.7         2.8          4.5         1.3 versicolor
#> 41           6.3         3.3          4.7         1.6 versicolor
#> 42           4.9         2.4          3.3         1.0 versicolor
#> 43           5.2         2.7          3.9         1.4 versicolor
#> 44           5.0         2.0          3.5         1.0 versicolor
#> 45           5.9         3.0          4.2         1.5 versicolor
#> 46           6.2         2.2          4.5         1.5 versicolor
#> 47           5.6         2.5          3.9         1.1 versicolor
#> 48           6.1         2.8          4.0         1.3 versicolor
#> 49           6.3         2.5          4.9         1.5 versicolor
#> 50           6.4         2.9          4.3         1.3 versicolor
#> 51           6.6         3.0          4.4         1.4 versicolor
#> 52           6.8         2.8          4.8         1.4 versicolor
#> 53           6.7         3.0          5.0         1.7 versicolor
#> 54           5.7         2.6          3.5         1.0 versicolor
#> 55           5.5         2.4          3.8         1.1 versicolor
#> 56           5.5         2.4          3.7         1.0 versicolor
#> 57           5.8         2.7          3.9         1.2 versicolor
#> 58           6.0         2.7          5.1         1.6 versicolor
#> 59           5.4         3.0          4.5         1.5 versicolor
#> 60           6.7         3.1          4.7         1.5 versicolor
#> 61           6.3         2.3          4.4         1.3 versicolor
#> 62           5.6         3.0          4.1         1.3 versicolor
#> 63           5.5         2.5          4.0         1.3 versicolor
#> 64           6.1         3.0          4.6         1.4 versicolor
#> 65           5.0         2.3          3.3         1.0 versicolor
#> 66           5.6         2.7          4.2         1.3 versicolor
#> 67           5.7         3.0          4.2         1.2 versicolor
#> 68           5.7         2.9          4.2         1.3 versicolor
#> 69           6.2         2.9          4.3         1.3 versicolor
#> 70           5.7         2.8          4.1         1.3 versicolor
#> 71           6.3         3.3          6.0         2.5  virginica
#> 72           5.8         2.7          5.1         1.9  virginica
#> 73           6.3         2.9          5.6         1.8  virginica
#> 74           6.5         3.0          5.8         2.2  virginica
#> 75           7.6         3.0          6.6         2.1  virginica
#> 76           4.9         2.5          4.5         1.7  virginica
#> 77           7.3         2.9          6.3         1.8  virginica
#> 78           6.7         2.5          5.8         1.8  virginica
#> 79           6.5         3.2          5.1         2.0  virginica
#> 80           6.4         2.7          5.3         1.9  virginica
#> 81           6.8         3.0          5.5         2.1  virginica
#> 82           5.7         2.5          5.0         2.0  virginica
#> 83           6.5         3.0          5.5         1.8  virginica
#> 84           7.7         3.8          6.7         2.2  virginica
#> 85           7.7         2.6          6.9         2.3  virginica
#> 86           6.9         3.2          5.7         2.3  virginica
#> 87           7.7         2.8          6.7         2.0  virginica
#> 88           6.3         2.7          4.9         1.8  virginica
#> 89           7.2         3.2          6.0         1.8  virginica
#> 90           7.2         3.0          5.8         1.6  virginica
#> 91           7.9         3.8          6.4         2.0  virginica
#> 92           6.4         2.8          5.6         2.2  virginica
#> 93           6.3         2.8          5.1         1.5  virginica
#> 94           7.7         3.0          6.1         2.3  virginica
#> 95           6.3         3.4          5.6         2.4  virginica
#> 96           6.4         3.1          5.5         1.8  virginica
#> 97           6.0         3.0          4.8         1.8  virginica
#> 98           6.7         3.1          5.6         2.4  virginica
#> 99           6.9         3.1          5.1         2.3  virginica
#> 100          6.8         3.2          5.9         2.3  virginica
#> 101          6.7         3.0          5.2         2.3  virginica
#> 102          6.3         2.5          5.0         1.9  virginica
#> 103          6.5         3.0          5.2         2.0  virginica
#> 104          6.2         3.4          5.4         2.3  virginica
#> 105          5.9         3.0          5.1         1.8  virginica
#> 
#> [[2]]
#>    Sepal.Length Sepal.Width Petal.Length Petal.Width      class
#> 1           4.9         3.0          1.4         0.2     setosa
#> 2           5.0         3.6          1.4         0.2     setosa
#> 3           4.4         2.9          1.4         0.2     setosa
#> 4           4.3         3.0          1.1         0.1     setosa
#> 5           5.7         4.4          1.5         0.4     setosa
#> 6           5.1         3.3          1.7         0.5     setosa
#> 7           5.0         3.0          1.6         0.2     setosa
#> 8           5.4         3.4          1.5         0.4     setosa
#> 9           5.2         4.1          1.5         0.1     setosa
#> 10          4.4         3.0          1.3         0.2     setosa
#> 11          5.0         3.5          1.6         0.6     setosa
#> 12          4.8         3.0          1.4         0.3     setosa
#> 13          4.6         3.2          1.4         0.2     setosa
#> 14          5.3         3.7          1.5         0.2     setosa
#> 15          5.0         3.3          1.4         0.2     setosa
#> 16          7.0         3.2          4.7         1.4 versicolor
#> 17          5.7         2.8          4.5         1.3 versicolor
#> 18          6.3         3.3          4.7         1.6 versicolor
#> 19          4.9         2.4          3.3         1.0 versicolor
#> 20          5.9         3.0          4.2         1.5 versicolor
#> 21          6.0         2.2          4.0         1.0 versicolor
#> 22          6.7         3.1          4.4         1.4 versicolor
#> 23          6.6         3.0          4.4         1.4 versicolor
#> 24          5.5         2.4          3.7         1.0 versicolor
#> 25          5.8         2.7          3.9         1.2 versicolor
#> 26          5.5         2.5          4.0         1.3 versicolor
#> 27          6.1         3.0          4.6         1.4 versicolor
#> 28          5.8         2.6          4.0         1.2 versicolor
#> 29          5.0         2.3          3.3         1.0 versicolor
#> 30          5.7         2.9          4.2         1.3 versicolor
#> 31          6.3         2.9          5.6         1.8  virginica
#> 32          7.6         3.0          6.6         2.1  virginica
#> 33          6.8         3.0          5.5         2.1  virginica
#> 34          5.7         2.5          5.0         2.0  virginica
#> 35          6.5         3.0          5.5         1.8  virginica
#> 36          7.7         2.6          6.9         2.3  virginica
#> 37          6.9         3.2          5.7         2.3  virginica
#> 38          5.6         2.8          4.9         2.0  virginica
#> 39          7.4         2.8          6.1         1.9  virginica
#> 40          7.9         3.8          6.4         2.0  virginica
#> 41          6.3         2.8          5.1         1.5  virginica
#> 42          7.7         3.0          6.1         2.3  virginica
#> 43          6.9         3.1          5.1         2.3  virginica
#> 44          5.8         2.7          5.1         1.9  virginica
#> 45          6.3         2.5          5.0         1.9  virginica
#>