Home > Mobile >  SMOTE target variable not found in R
SMOTE target variable not found in R

Time:10-05

Why is it when I run the smote function in R, an error appears saying that my target variable is not found? I am using the smotefamily package to run this smote function.

tv_smote <- SMOTE(tv_smote, Churn, K = 5, dup_size = 0)

Error in table(target) : object 'Churn' not found

Chunk Codes

CodePudding user response:

Generally, you should include the minimum code and data needed to reproduce the problem. This saves time and gives you more chance of getting an answer. However, try this...

tv_smote <- SMOTE(tv_smote, tv_smote$Churn, K = 5, dup_size = 0)

CodePudding user response:

I can get the same error by doing this:

library(smotefamily)

df <- data.frame(x = 1:8, y = 8:1)

df_smote <- SMOTE(df, y, K = 3, dup_size = 0)

It appears to me that SMOTE doesn't know y is a column name. In the documentation, ?SMOTE, it says that the target argument is "A vector of a target class attribute corresponding to a dataset X." My interpretation of this is that you need to supply a vector, not a name. Changing it to df_smote <- SMOTE(df, df$y, K = 3, dup_size = 0) gets past that part.

I am not familiar with the SMOTE function, but from testing it would appear that SMOTE cannot accept dataframes with any factor type columns. I get Error in get.knnx(data, query, k, algorithm) : Data non-numeric when using as.factor.

  • Related