Question: library ( DAAG ) library ( ggplot 2 ) library ( dplyr ) library ( tree ) library ( ISLR 2 ) library ( MASS

library(DAAG)
library(ggplot2)
library(dplyr)
library(tree)
library(ISLR2)
library(MASS)
library(klaR)
library(e1071)
df=data.frame(nassCDS)
df=subset(df, select=-c(caseid))
df <- df %>%
group_by(yearVeh)%>%
mutate(yearmod=case_when(
yearVeh>=1953 & yearVeh<1958 ~ "1",
yearVeh>=1958 & yearVeh<1963 ~ "2",
yearVeh>=1963 & yearVeh<1968 ~ "3",
yearVeh>=1968 & yearVeh<1973 ~ "4",
yearVeh>=1973 & yearVeh<1978 ~ "5",
yearVeh>=1978 & yearVeh<1983 ~ "6",
yearVeh>=1983 & yearVeh<1988 ~ "7",
yearVeh>=1988 & yearVeh<1993 ~ "8",
yearVeh>=1993 & yearVeh<1998 ~ "9",
yearVeh>=1998 ~ "10"
))
ca<-na.omit(df)
attach(ca)
table(ca$dead)
table(ca$sex)
ca$frontal<-as.factor(ca$frontal)
ca$yearacc<-as.factor(ca$yearacc)
ca$deploy<-as.factor(ca$deploy)
ca$injSeverity<-as.factor(ca$injSeverity)
ca$yearmod<-as.factor(ca$yearmod)
ca$occRole<-as.factor(ca$occRole)
ca$dvcat<-factor(ca$dvcat)
ca=subset(ca, select=-c(yearVeh, abcat))
set.seed(1)
ttds<-sample(c(TRUE, FALSE), nrow(ca), replace=TRUE, prob=c(0.7,0.3))
train<-ca[ttds,]
test<-ca[!ttds,]
Please demonstrate how to fit a multi-layer neural network to predict the variable dead based on the provided code (The dataset is one found in the package DAAG). Determine how many hidden layers and neurons the neural net model should have in the code. Use the train dataset to train the neural net and test its accuracy using the test dataset.
Also please troubleshoot the code first before posting.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!