0

The dataset that I'm working on is unbalanced, so I'm trying to balance the dataset by using undersampling but I get an error

my code

library(unbalanced)

#convert class to binary
levels(car$class)[1]<-"0"#acc
levels(car$class)[2]<-"1"#good 
levels(car$class)[3]<-"2"#unacc
levels(car$class)[4]<-"3"#vgood
#find the number of columns
n_car<-ncol(car)
#class of the data set
outcome_car<-car$class
input_car<-car[ ,-7]
data_car<-ubUnder(X=input_car, Y= outcome_car, perc = 40,  method = "percPos")

and here is the error that I got

Error: all(unique(Y) %in% c(0, 1)) is not TRUE

when I try to balance another dataset the code is work well, so I think maybe that's because I have on this dataset 4 levels and on another dataset 2 levels? but how can deal with this error?

thank you

Sotos
  • 51,121
  • 6
  • 32
  • 66
Fatima Mb
  • 21
  • 3
  • I m not aware of that function (please include any packages you used) but the error is very clear. Maybe [combine levels in your factor variable](https://stackoverflow.com/questions/30032616/how-to-combine-two-levels-in-one-categorical-variable-in-r) – Sotos Apr 25 '18 at 11:47
  • library(unbalanced) – Fatima Mb Apr 25 '18 at 11:53
  • I am also trying another function which is `ovun.sample` from ROSE Packages but I got the same error – Fatima Mb Apr 25 '18 at 12:00

0 Answers0