R中逻辑回归建模中的子集 [英] Subsetting in Logistic Regression modeling in R

查看:48
本文介绍了R中逻辑回归建模中的子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 R 中的逻辑回归过程中拆分和子集我的数据时收到以下错误消息.我被困在子集"中步骤.

I received the following error messages when splitting and subsetting my data in the process of logistic regression in R. I am stuck at the "subset" step.

    library(caTools)
    split <-sample.split(df1, SplitRatio = 0.5)
    split
    training <- subset(df1, split == "TRUE")
    testing <- subset(df1, split == "FALSE")

错误:

错误:必须使用有效的下标向量对行进行子集.逻辑下标必须与索引输入的大小匹配.x 输入有大小333030 但下标 i 的大小为 9.运行 rlang::last_error() 以查看发生错误的地方.

Error: Must subset rows with a valid subscript vector. i Logical subscripts must match the size of the indexed input. x Input has size 333030 but subscript i has size 9. Run rlang::last_error() to see where the error occurred.

推荐答案

您正在拆分列.如果您阅读帮助页面:

You are splitting on the columns. If you read the help page:

用法:

  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 ,它将是:

You are providing the whole data frame, which it reads as a list.So if you have a dependent variable, for example y , it would be:

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,]

这篇关于R中逻辑回归建模中的子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆