R语言:使用SMOTE出现错误

错误1、“length of 'dimnames' [2] not equal to array extent”

我的原代码:

balanceData <- SMOTE(status~.,selecData,perc.over=500,perc.under=100)

错误原因是将tibble数据结构传入了DMwR::SMOTE(),使用as.data.frame()将数据un-tibble化即可,修改的代码如下:

balanceData <- SMOTE(status~.,as.data.frame(selecData),perc.over=500,perc.under=100)

参考的资料:

https://stackoverflow.com/questions/38616260/smote-length-of-dimnames-2-not-equal-to-array-extent

错误2、“Error in T[i, ] : 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”

 使用str(as.data.frame(selecData))可以看到

'data.frame':	141 obs. of  4 variables:
 $ status         : num  0 1 0 0 0 0 0 0 0 0 ...

status是num型,我们需要把它转化成Factor型,在使用SMOTE()前,先:

selecData$status = as.factor(selecData$status)

参考资料:

https://arulvelkumar.wordpress.com/2017/04/30/smote-function-in-r-error-in-ti-subscript-out-of-bounds/

猜你喜欢

转载自blog.csdn.net/qq_35155649/article/details/84780788