R
在R的逻辑回归过程中,我在拆分和子集数据时收到以下错误消息。我被困在“子集”步骤R,r,regression,R,Regression,在R的逻辑回归过程中,我在拆分和子集数据时收到以下错误消息。我被困在“子集”步骤 库(caTools) 拆分您正在对列进行拆分。如果您阅读了帮助页面: 用法: sample.split( Y, SplitRatio = 2/3, group = NULL ) Arguments: Y: Vector of data labels. If there are only a few labels (as is expected) than relative ratio o
库(caTools)
拆分您正在对列进行拆分。如果您阅读了帮助页面:
用法:
sample.split( Y, SplitRatio = 2/3, group = NULL )
Arguments:
Y: Vector of data labels. If there are only a few labels (as is
expected) than relative ratio of data in both subsets will be
the same.
您提供的是整个数据帧,它以列表的形式读取。因此,如果您有一个因变量,例如y
,它将是:
split <-sample.split(df1$y, SplitRatio = 0.5)
training <- df1[split,]
testing <- df1[!split,]
split永远不要把的“TRUE”
和“FALSE”`放在引号里——这会使它们成为字符串,而不是逻辑值。这不一定是您的问题,但这是最佳实践。我会尝试training=df1[split,]
和testing=df1[!split,]
但可能会签出head(split)
以确保它是真/假值,并将length(split)
与nrow(df1)进行比较
以确保尺寸正确。在这种情况下,删除引号并不能解决问题。split有9个值,TRUE或FALSE。我认为这是造成问题的原因。我在df1中有333030行,如错误消息所示。同时,我应该使用什么分割比率?谢谢它起作用了!谢谢!
split <-sample.split(df1$y, SplitRatio = 0.5)
training <- df1[split,]
testing <- df1[!split,]
split <-sample.split(1:nrow(df1), SplitRatio = 0.5)
training <- df1[split,]
testing <- df1[!split,]