10
$\begingroup$

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
In addition: Warning messages:
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
$\endgroup$
1
  • $\begingroup$ please try converting your target column (i.e. "status") to factor and consider marking @xing's post below as the answer. $\endgroup$
    – Greenish
    Commented Apr 20, 2017 at 16:19

1 Answer 1

13
$\begingroup$

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!

$\endgroup$
2
  • $\begingroup$ That's a pity that it is not mentionned in SMOTE documentation that it works only if the labels are factor! $\endgroup$
    – Pop
    Commented Nov 25, 2015 at 10:26
  • $\begingroup$ That was it for me. converting to factor fixed it. $\endgroup$
    – Greenish
    Commented Apr 20, 2017 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.