简体   繁体   English

绘制用于Logistic回归的响应面(3D图)

[英]plotting response Surface for logistic regression(3D plot)

I want to plot the response surface for logistic regression.我想绘制响应面以进行逻辑回归。 I tried with scatterplot3d but got nothing.我尝试使用scatterplot3d但一无所获。
The plot should have X-axis=Age, Y-Axis=Fare, and Z-Axis= predicted probabilities.该图应具有X轴=年龄,Y轴=票价和Z轴=预测概率。

library(mlr)
library(tidyverse)
#install.packages("ciTools")
library(ciTools)
#install.packages("titanic")
data(titanic_train, package = "titanic")
titanicTib <- as_tibble(titanic_train)
titanicTib
fctrs <- c("Survived", "Sex", "Pclass")

titanicClean <- titanicTib %>%
  mutate_at(.vars = fctrs, .funs = factor) %>%
  mutate(FamSize = SibSp + Parch) %>%
  select(Survived, Pclass, Sex, Age, Fare, FamSize)

titanicClean

imp <- impute(titanicClean, cols = list(Age = imputeMean()))

sum(is.na(titanicClean$Age))
sum(is.na(imp$data$Age))
imp$data %>%
  glimpse()

model <- glm(Survived ~ (Pclass + Sex + Age + Fare + FamSize),
             family = "binomial", data = imp$data)

summary(model)



newdata<- data.frame(FamSize = mean(imp$data$FamSize),
                   Fare = seq(min(imp$data$Fare), max(imp$data$Fare), length.out= 102)
                   Sex = factor(rep(c("male"), 102)),
                   Pclass = factor(rep(c(1:3), each=34)),
                   Age = rep(seq(1, 100, 3), 3) )


preds <- predict(model, newdata = newdata, type = "response" , se.fit =TRUE)

I tried with scatterplot3d like this:我尝试使用scatterplot3d像这样:

scatterplot3d(imp$data$Age[1:20], imp$data$Fare[1:20], imp$data$Survived[1:20],
                    angle = 55,
                    main="3D Scatter Plot",
                    xlab = "Age",
                    ylab = "Fare",
                    zlab = "Survived", color="steelblue", grid = TRUE,
                    )

I want to plot the response surface for logistic regression.我想绘制响应面以进行逻辑回归。 I tried with scatterplot3d but got nothing.我尝试使用scatterplot3d但一无所获。
The plot should have X-axis=Age, Y-Axis=Fare, and Z-Axis= predicted probabilities.该图应具有X轴=年龄,Y轴=票价和Z轴=预测概率。

library(mlr)
library(tidyverse)
#install.packages("ciTools")
library(ciTools)
#install.packages("titanic")
data(titanic_train, package = "titanic")
titanicTib <- as_tibble(titanic_train)
titanicTib
fctrs <- c("Survived", "Sex", "Pclass")

titanicClean <- titanicTib %>%
  mutate_at(.vars = fctrs, .funs = factor) %>%
  mutate(FamSize = SibSp + Parch) %>%
  select(Survived, Pclass, Sex, Age, Fare, FamSize)

titanicClean

imp <- impute(titanicClean, cols = list(Age = imputeMean()))

sum(is.na(titanicClean$Age))
sum(is.na(imp$data$Age))
imp$data %>%
  glimpse()

model <- glm(Survived ~ (Pclass + Sex + Age + Fare + FamSize),
             family = "binomial", data = imp$data)

summary(model)



newdata<- data.frame(FamSize = mean(imp$data$FamSize),
                   Fare = seq(min(imp$data$Fare), max(imp$data$Fare), length.out= 102)
                   Sex = factor(rep(c("male"), 102)),
                   Pclass = factor(rep(c(1:3), each=34)),
                   Age = rep(seq(1, 100, 3), 3) )


preds <- predict(model, newdata = newdata, type = "response" , se.fit =TRUE)

I tried with scatterplot3d like this:我尝试使用scatterplot3d像这样:

scatterplot3d(imp$data$Age[1:20], imp$data$Fare[1:20], imp$data$Survived[1:20],
                    angle = 55,
                    main="3D Scatter Plot",
                    xlab = "Age",
                    ylab = "Fare",
                    zlab = "Survived", color="steelblue", grid = TRUE,
                    )

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

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