Reputation: 11
I try to use ROSE library on R to rebalancing target variable in my dataset. Here is my information of my dataset.
I would like to undersampling the dataset to make the percentage of minor class increase to 5%.
Here is my code :
df_Under <- ovun.sample(Target ~ ., data = df, method = "under", N =5580, seed = 1)
However, after run the code above, I got the following error message.
"Error in (function (formula, data, method, subset, na.action, N, p = 0.5, :Too few observations."
I tried play with other method of ROSE such as "over" and "both" but there are the same error occurs.
How can I fixed this problem ?
Kind regards,
Upvotes: 1
Views: 3669
Reputation: 21
I was facing the same problem. The problem was actually in the dataset which had columns (variables) with NA/Nan.
Please try running the code after NA removal.
Let me know if this helps.
Upvotes: 2
Reputation: 43
data.balanced.under <- ovun.sample(Target ~ ., data = df, method = "under",p= 0.5)$data
this will solve your problem
Upvotes: 0
Reputation: 1314
I believe you want your code to use p = 0.05
(5%) not p = 0.5
(50%) like you have (which is the function's default) and to over
sample to bring up the sample size of the minority class like you mentioned in your post:
df_Under <- ovun.sample(Target ~ ., data = df, method = "over", N =5580, seed = 1, p = 0.05)
Upvotes: 0