I need to make a classification using logistic regression.

test data and training set are set like this:

train = data.frame( x1 = c(1,2,3), x2 = c(3,4,5), y = c(1,1,0)) test = data.frame( x1 = c(1,2,5), x2 = c(1,3,5)) 

How to implement this code?

I tried, but in the end bugs came out

 mldata <- mlogit.data(train, choice = "y") formula = as.formula(paste("y ~ ", "x1+x2")) mlogitModel = mlogit(formula, mldata) pred = preict(mlogit_model, test) 

    1 answer 1

    To classify using logistic regression, you can use the function glm() with the argument family = binomial(link = "logit") . To obtain the probability of assigning observations to a particular class, the function predict() .

     fit <- glm(y ~ x1 + x2, data = train, family = "binomial") pred <- predict(fit, newdata = test, type = "response")