[Solved] I am building a decision tree model in R (rstudio) with the dataset…

I am building a decision tree model in R (rstudio) with the dataset attached but have gotten this error “Error in train_violence(violence$class ~ ., data = train_violence, method = “rpart”,  :
 could not find function “train_violence”
when i run it. i have the train_violence function already created so i do not understand the error. Could you please let me know what is wrong here? Below is what I have done with the dataset:

 

 

#create data frame and clean up data
Gunviolence <- data.frame(Gunviolence)
summary(Gunviolence)
#remove city,or,county, address and operations columns
Gunviolence_new <- Gunviolence[,!names(Gunviolence) %in% c(“City.Or.County”, “Address”, “Operations”)]
summary(Gunviolence_new)
###separate date variable into year/month/day
violence = Gunviolence_new %>% separate(Incident.Date, sep = “-“, into = c(“year”, “month”, “day”))
head(violence)
summary(violence)
str(violence)
#check for null values
view(violence)
is.na(violence)
#remove month and day columns
violence <- violence[,!names(violence) %in% c(“month”, “day”)]
summary(violence)
“`

#Create class variable and covert Injured variable to a factor
violence$class <- as.factor(ifelse(violence$Injured < mean(violence$Injured), “No”, “Yes”))
#Split data into traaining and testing
index_violence = createDataPartition(violence[,1], p =0.80, list = FALSE)
index_violence

train_violence = violence[index_violence,]
dim(train_violence)
#Validate the data
valid_violence = violence[-index_violence,]
dim(valid_violence)
#Create Harness
control_violence <- trainControl(method = “cv”, number = 10)
metric_violence <- “Accuracy”
#Build Decision Tree using rpart
set.seed(7)
fit.rpart <- train_violence(violence$class~., data = train_violence, method = “rpart”, metric = metric_violence, trControl = control_violence)
“`

Read more here: Source link