簡體   English   中英

當我嘗試對 R 中的數據集進行上采樣時,沒有執行任何操作

[英]When I am trying to upsample a dataset in R, no action is being performed

我正在嘗試使用 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)”時,我得到“<table of extent 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM