我需要有关createDataPartition的帮助 我收到此错误
createDataPartition中的错误(TBdta $ medv,p = 0.8,列表= FALSE):y必须至少具有2个数据点
我的代码
library(tibble)
dta <- url("http://course1.winona.edu/bdeppa/Stat%20425/Data/Boston_Housing.csv")
TBdta <- as_tibble(read.csv(dta, check.names = FALSE))
TBdta
运行下面的模块时出现错误
# Split out validation dataset
# create a list of 80% of the rows in the original dataset we can use for training
set.seed(7)
validationIndex <- createDataPartition(TBdta$medv, p=0.80, list=FALSE)
# select 20% of the data for validation
validation <- TBdta$medv[-validationIndex,]
# use the remaining 80% of data to training and testing the models
dataset <- TBdta$medv[validationIndex,]
createDataPartition中的错误(TBdta $ medv,p = 0.8,列表= FALSE):y必须至少具有2个数据点
答案 0 :(得分:0)
我想你需要的是
set.seed(7)
validationIndex <- caret::createDataPartition(TBdta$MEDV, p=0.80, list=FALSE)
validation <- TBdta[-validationIndex,]
dataset <- TBdta[validationIndex,]
让您拥有
dim(validation)
#[1] 99 14
dim(dataset)
#[1] 407 14