简体   繁体   English

Logistic回归训练集的功能

[英]Function for Logistic Regression Training Set

I am trying to create a function to test a logistic regression model developed on a training set. 我正在尝试创建一个功能来测试在训练集上开发的逻辑回归模型。

For example 例如

train <- filter(y, folds != i)
test <- filter(y, folds == i)

I want to be able to use the formula for different data sets. 我希望能够将公式用于不同的数据集。 For example, if I were to take y to be a response variable such as “ low ” in the birthwt data set and x to be the explanatory variables eg “age", “race” how would I implement these arguments into glm.train formula without having to type the function separately for different data sets ? 例如,如果我将y用作反应变量,例如birthwt数据集中的“ low ”,而将x用作解释变量,例如“age", “race”我将如何将这些参数实现为glm.train公式不必为不同的数据集分别键入函数?

glm.train <- glm(y ~x, family = binomial, data =  train)

You can use reformulate to create a formula based on strings: 您可以使用reformulate公式以基于字符串创建公式:

x <- c("age", "race")
y <- "low"

form <- reformulate(x, response = y)
# low ~ age + race

Use this formula for glm : glm使用以下公式:

glm.train <- glm(form, family = binomial, data =  train)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM