如何将预测列添加到数据框

时间:2022-07-04 16:32:47

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 ?

我使用以下代码来预测x的值。我想将预测值/列添加到数据框中。怎么加?

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.

data $ val是验证集,数据$ train是训练集。

1 个解决方案

#1


1  

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))

#1


1  

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))