Shann
Shann

Reputation: 690

how to add predicted column to data frame

i am using the following code to predict the value of x. i'd like to add the predicted value/column to the data frame. How to add ?

logit.fit<- glm(x~.-y, family = binomial(logit),data = data$train) 
logit.preds <- predict(logit.fit,newdata=data$val,type="response") 
logit.pred <- prediction(logit.preds,data$val$x) 
logit.perf <- performance(logit.pred,"tpr","fpr")

data$val is the validation set and data$train is the training set.

Upvotes: 0

Views: 1888

Answers (1)

dimitris_ps
dimitris_ps

Reputation: 5951

The following should be what you are looking for

install.packages("broom")
install.packages("ggplot2")

iris$y <- (iris$Species=="setosa")*1
logit.fit<- glm(y ~ Sepal.Length+Sepal.Width+Petal.Length, 
            family = binomial(logit), data = iris) 

View(ggplot2::fortify(logit.fit))
View(broom::augment(logit.fit))

Upvotes: 1

Related Questions