我正在尝试使用ROSE包中的“ ovun.sample”函数对R中的数据集进行上采样或过采样,而没有进行任何计算。
mission <- read.csv(file.choose(), header = T)
colnames(mission) <- c("Gen", "Age", "Key_Comp", "Weight", "Height", "Pulse", "HBP", "LBP",
"RR", "PMH", "HB", "Urea", "Creatinine", "Arrival", "Arrival_State",
"Admsn_Type", "C2H", "B2P", "Concession", "Actl_Amt", "Stay",
"ICU_stay", "Ward_stay", "Implant", "Implant_Cost", "GRL")
library(caTools)
set.seed(123)
split <- sample.split(mission, SplitRatio = 0.7)
train <- subset(mission, split == T)
test <- subset(mission, split == F)
over <- ovun.sample(GRL ~.,data = train, method = "over", N = 254)$mission
over$GRL
"NULL"
table(over$GRL)
"< table of extent 0 >"
当我运行“ over $ GRL”时,我得到“ NULL”作为响应,当我运行“ table(over $ GRL)”时,我得到“ <扩展表0>”。我无法对数据集进行过采样或欠采样。有人可以帮我这个忙吗?
为了完整起见,这是我对评论的回答:
mission <- read.csv(file.choose(), header = T)
colnames(mission) <- c("Gen", "Age", "Key_Comp", "Weight", "Height", "Pulse", "HBP", "LBP",
"RR", "PMH", "HB", "Urea", "Creatinine", "Arrival", "Arrival_State",
"Admsn_Type", "C2H", "B2P", "Concession", "Actl_Amt", "Stay",
"ICU_stay", "Ward_stay", "Implant", "Implant_Cost", "GRL")
library(caTools)
set.seed(123)
split <- sample.split(mission, SplitRatio = 0.7)
train <- subset(mission, split == T)
test <- subset(mission, split == F)
# this line was the problem - it should end $data, not $mission
over <- ovun.sample(GRL ~.,data = train, method = "over", N = 254)$data
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句