# SMOTE throws error for multi class imbalance problem

I am trying to use SMOTE to correct imbalance in my multi-class classification problem. Although SMOTE works perfectly on the iris dataset as per the SMOTE help document, it does not work on a similar dataset. Here is how my data looks. Note it has three classes with values 1, 2, 3.

> data
looking risk every status
1        0    1     0      1
2        0    0     0      1
3        0    0     0      2
4        0    0     0      1
5        0    0     0      1
6        3    0     0      1
7        0    0     0      1
8        0    0     0      1
9        0    1     0      1
10       0    0     0      1
11       0    0     0      3
12       0    0     0      1
13       0    0     0      1
14       0    0     0      1
15       0    0     0      2


It is in the form of dataframe, same as iris:

> class(data)
[1] "data.frame"


Here is my code using SMOTE and the error that it throws:

> newData <- SMOTE(status ~ ., data, perc.over = 600,perc.under=100)
Error in scale.default(T, T[i, ], ranges) : subscript out of bounds
1: In FUN(newX[, i], ...) :
no non-missing arguments to max; returning -Inf
2: In FUN(newX[, i], ...) :
no non-missing arguments to max; returning -Inf
3: In FUN(newX[, i], ...) :
no non-missing arguments to max; returning -Inf
4: In FUN(newX[, i], ...) : no non-missing arguments to min; returning Inf
5: In FUN(newX[, i], ...) : no non-missing arguments to min; returning Inf
6: In FUN(newX[, i], ...) : no non-missing arguments to min; returning Inf

• please try converting your target column (i.e. "status") to factor and consider marking @xing's post below as the answer. – Greenish Apr 20 '17 at 16:19

I have encountered a similar problem, and I solved it by transferring the class values ("status" in your case) into factor type. After using data$status=factor(data$status), newData prints as follows:

     looking risk every status
7          0    0     0      1
2          0    0     0      1
7.1        0    0     0      1
12         0    0     0      1
4          0    0     0      1
12.1       0    0     0      1
11         0    0     0      3
8         NA   NA    NA      3
9         NA   NA    NA      3
10        NA   NA    NA      3
111       NA   NA    NA      3
121       NA   NA    NA      3
13        NA   NA    NA      3


No errors!

• That's a pity that it is not mentionned in SMOTE documentation that it works only if the labels are factor! – Pop Nov 25 '15 at 10:26
• That was it for me. converting to factor fixed it. – Greenish Apr 20 '17 at 16:18