我在不平衡的数据集上尝试了多种技术,例如过采样,欠采样,ROSE和两者(过采样和欠采样)来平衡数据集。当我将所有这些技术应用于一个小的数据集时,这些技术就可以完美地工作
library(ROSE)
> table(df4$Price)
0 1
100020 1249
> data.rose <- ROSE(Price~., data=df4, seed=3, N = 200040)$data
> table(data.rose$Price)
0 1
99960 100080
# Oversampling
> data.balanced.over <- ovun.sample(Price ~ ., data = df4, method = "over",N = 200040)$data
table(data.balanced.over$Price)
0 1
100020 100020
> data.balanced.both <- ovun.sample(Price ~ ., data = df4, method = "both",N = 200040)$data
> table(data.balanced.both$Price)
0 1
99903 100137
> data.balanced.under <- ovun.sample(Price ~ ., data = df4, method = "under",N = 2538)$data
> table(data.balanced.under$Price)
0 1
1289 1249
但是当我将所有这些技术应用于大型数据集时,我就出错了
> table(mydata$Price)
0 1
33003944 1150753
> data.rose <- ROSE(Price~., data=mydata, seed=3)$data
Error in omnibus.balancing(formula, data, subset, na.action, N, p, method = "rose", :
Too few observations.
> data.balanced.over <- ovun.sample(Price ~ ., data = mydata, method = "over",N = 66007888)$data
Error in (function (formula, data, method, subset, na.action, N, p = 0.5, :
Too few observations.
> data.balanced.under <- ovun.sample(Price ~ ., data = mydata, method = "under",N = 2301506)$data
Error in (function (formula, data, method, subset, na.action, N, p = 0.5, :
Too few observations.