Skip to main content
added 130 characters in body
Source Link
kjetil b halvorsen
  • 82.8k
  • 32
  • 201
  • 663

SMOTE(form, data, perc.over = 200, k = 5, perc.under = 200, learner = NULL, ...)

SMOTE(form, data, perc.over = 200, k = 5, perc.under = 200,
    learner = NULL, ...)
library(caret)
library(DMwR)

set.seed(2969)
imbal_train <- twoClassSim(10000, intercept = -20, linearVars = 20)
table(imbal_train\\\$Class)

set.seed(9560)
smote_train <- SMOTE(Class ~ ., data  = imbal_train)                         
table(smote_train\\\$Class)[2]

perc.over <- 100*(table(smote_train\\\$Class)[2]-table(imbal_train\\\$Class)[2])/table(imbal_train\\\$Class)[2]
perc.under <- 100*table(smote_train\\\$Class)[1]/(table(smote_train\\\$Class)[2]-table(imbal_train\\\$Class)[2])

perc.over = 200

perc.under = 200

set.seed(1234)
imbal_train <- twoClassSim(10000, intercept = -40, linearVars = 40)
table(imbal_train\\\$Class)

set.seed(5678)
smote_train <- SMOTE(Class ~ ., data  = imbal_train)                         
table(smote_train\\\$Class)

perc.over <- 100*(table(smote_train\\\$Class)[2]-table(imbal_train\\\$Class)[2])/table(imbal_train$Class)[2]
perc.under <- 100*table(smote_train\\\$Class)[1]/(table(smote_train\\\$Class)[2]-table(imbal_train\\\$Class)[2])

perc.over = 200

perc.under = 200

library(caret)
library(DMwR)
        
set.seed(2969)
imbal_train <- twoClassSim(10000, intercept = -20, linearVars = 20)
table(imbal_train\\\$Class)
    
set.seed(9560)
smote_train <- SMOTE(Class ~ ., data  = imbal_train)                         
table(smote_train\\\$Class)[2]
        
perc.over <- 100*(table(smote_train\\\$Class)[2] - table(imbal_train\
    $Class)[2])/table(imbal_train\\\$Class)[2]
perc.under <- 100*table(smote_train\\\$Class)[1]/
    (table(smote_train\\\$Class)[2] - table(imbal_train\\\$Class)[2])
    
perc.over = 200

perc.under = 200
    
set.seed(1234)
imbal_train <- twoClassSim(10000, intercept = -40, linearVars = 40)

table(imbal_train\\\$Class)

set.seed(5678)
smote_train <- SMOTE(Class ~ ., data  = imbal_train)                         
table(smote_train\\\$Class)
        
perc.over <- 100*(table(smote_train\\\$Class)[2] - 
    table(imbal_train\\\$Class)[2])/table(imbal_train$Class)[2]
perc.under <- 100*table(smote_train\\\$Class)[1]/
    (table(smote_train\\\$Class)[2]-table(imbal_train\\\$Class)[2])
    
perc.over = 200

perc.under = 200

SMOTE(form, data, perc.over = 200, k = 5, perc.under = 200, learner = NULL, ...)

library(caret)
library(DMwR)

set.seed(2969)
imbal_train <- twoClassSim(10000, intercept = -20, linearVars = 20)
table(imbal_train\\\$Class)

set.seed(9560)
smote_train <- SMOTE(Class ~ ., data  = imbal_train)                         
table(smote_train\\\$Class)[2]

perc.over <- 100*(table(smote_train\\\$Class)[2]-table(imbal_train\\\$Class)[2])/table(imbal_train\\\$Class)[2]
perc.under <- 100*table(smote_train\\\$Class)[1]/(table(smote_train\\\$Class)[2]-table(imbal_train\\\$Class)[2])

perc.over = 200

perc.under = 200

set.seed(1234)
imbal_train <- twoClassSim(10000, intercept = -40, linearVars = 40)
table(imbal_train\\\$Class)

set.seed(5678)
smote_train <- SMOTE(Class ~ ., data  = imbal_train)                         
table(smote_train\\\$Class)

perc.over <- 100*(table(smote_train\\\$Class)[2]-table(imbal_train\\\$Class)[2])/table(imbal_train$Class)[2]
perc.under <- 100*table(smote_train\\\$Class)[1]/(table(smote_train\\\$Class)[2]-table(imbal_train\\\$Class)[2])

perc.over = 200

perc.under = 200

SMOTE(form, data, perc.over = 200, k = 5, perc.under = 200,
    learner = NULL, ...)
library(caret)
library(DMwR)
        
set.seed(2969)
imbal_train <- twoClassSim(10000, intercept = -20, linearVars = 20)
table(imbal_train\\\$Class)
    
set.seed(9560)
smote_train <- SMOTE(Class ~ ., data  = imbal_train)                         
table(smote_train\\\$Class)[2]
        
perc.over <- 100*(table(smote_train\\\$Class)[2] - table(imbal_train\
    $Class)[2])/table(imbal_train\\\$Class)[2]
perc.under <- 100*table(smote_train\\\$Class)[1]/
    (table(smote_train\\\$Class)[2] - table(imbal_train\\\$Class)[2])
    
perc.over = 200

perc.under = 200
    
set.seed(1234)
imbal_train <- twoClassSim(10000, intercept = -40, linearVars = 40)

table(imbal_train\\\$Class)

set.seed(5678)
smote_train <- SMOTE(Class ~ ., data  = imbal_train)                         
table(smote_train\\\$Class)
        
perc.over <- 100*(table(smote_train\\\$Class)[2] - 
    table(imbal_train\\\$Class)[2])/table(imbal_train$Class)[2]
perc.under <- 100*table(smote_train\\\$Class)[1]/
    (table(smote_train\\\$Class)[2]-table(imbal_train\\\$Class)[2])
    
perc.over = 200

perc.under = 200
Source Link
Fra_Ve
  • 138
  • 9

I reproduced the example of https://topepo.github.io/caret/subsampling-for-class-imbalances.html and tried another one. Results are:

perc.over = 200

perc.under = 200

It seems that the parameters are those of usage of the function SMOTE in the DMwR documentation (pag. 82):

Usage

SMOTE(form, data, perc.over = 200, k = 5, perc.under = 200, learner = NULL, ...)

In usage k = 5, but I verified only perc.over and perc.under:

library(caret)
library(DMwR)

set.seed(2969)
imbal_train <- twoClassSim(10000, intercept = -20, linearVars = 20)
table(imbal_train\\\$Class)

set.seed(9560)
smote_train <- SMOTE(Class ~ ., data  = imbal_train)                         
table(smote_train\\\$Class)[2]

perc.over <- 100*(table(smote_train\\\$Class)[2]-table(imbal_train\\\$Class)[2])/table(imbal_train\\\$Class)[2]
perc.under <- 100*table(smote_train\\\$Class)[1]/(table(smote_train\\\$Class)[2]-table(imbal_train\\\$Class)[2])

perc.over = 200

perc.under = 200

set.seed(1234)
imbal_train <- twoClassSim(10000, intercept = -40, linearVars = 40)
table(imbal_train\\\$Class)

set.seed(5678)
smote_train <- SMOTE(Class ~ ., data  = imbal_train)                         
table(smote_train\\\$Class)

perc.over <- 100*(table(smote_train\\\$Class)[2]-table(imbal_train\\\$Class)[2])/table(imbal_train$Class)[2]
perc.under <- 100*table(smote_train\\\$Class)[1]/(table(smote_train\\\$Class)[2]-table(imbal_train\\\$Class)[2])

perc.over = 200

perc.under = 200