0

I have written this function to re-sample my data for class imbalance learning, but when i run it gives me factor level [2] is duplicated, OR Error in adj.formula(formula, data) : object 'originalData' not found.

SampleData<-function(originalData, ch)
{
  if(ch==1)
  {
    training<-ovun.sample(defects~.,data=originalData, method = "over", N=nrow(originalData[originalData$defects=="FALSE",])*2)$data
  }

  else if(ch == 2)
  {
    data <- ovun.sample(defects~.,seed = 54321,data=originalData, method = "under", N=nrow(originalData[originalData$defects=="TRUE",])*2)$data
  }

  else if(ch == 3)
  {
    data <- ovun.sample(defects~.,seed = 54321,data=originalData, method = "both", p = 0.5, N=nrow(originalData))$data
  }

  else if(ch == 4)
  {

    data<-SMOTE(defects~.,data=originalData,seed = 54321, perc.over = 200, perc.under = 100, k = 5)
  }
  else if(ch == 5)
  {

    data<- ROSE(defects ~ ., data  = originalData,seed = 54321,N=nrow(originalData))$data
  }

  else
  {
    data <- originalData
  }
  return(data)
}
  • 1
    It would be easier to help if you included a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Stuff that should be included: What is `originalData` and `ch`? And what are the functions `ovun.sample`, `SMOTE` and `ROSE`? – henrik_ibsen Mar 10 '20 at 17:25
  • these are re-sampling functions which belong to ROSE and DMwR packages. – Mohammad Azzeh Mar 10 '20 at 18:21

0 Answers0