Question: Help with R, receiving error with predict with either a tree or rules must be provided Here is my code: #read.cvs(mushrooms.csv, stringAsFactors = TRUE) install.packages(arules)

Help with R, receiving error with predict with "either a tree or rules must be provided"

Here is my code:

#read.cvs("mushrooms.csv", stringAsFactors = TRUE)

install.packages("arules")

install.packages("modeldata")

install.packages("mlbench")

install.packages("C50")

library(C50)

library(mlbench)

library(RWeka)

library(modeldata)

# Load the mushroom dataset

mushrooms <- read.csv("https://raw.githubusercontent.com/PacktPublishing/Machine-Learning-with-R-Third-Edition/master/Chapter05/mushrooms.csv")

#data(mushrooms)

# Convert all columns to factors

summary(mushrooms)

mushrooms$Id <- NULL

for (i in 1: ncol(mushrooms)) {

mushrooms[,i] <- as.factor(mushrooms[,i])

}

# Split the data into training and testing sets

set.seed(123) # for reproducibility

training_inds <- sort(sample(nrow(mushrooms), nrow(mushrooms)*0.7))

x_train <- mushrooms[training_inds, -ncol(mushrooms)]

y_train <- mushrooms$habitat[training_inds]

x_test <- mushrooms[-training_inds, -ncol(mushrooms)]

y_test <- mushrooms$habitat[-training_inds]

# C5.0 decision trees

c50_model <- C5.0(x_train, y_train)

c50_preds <- predict(c50_model, x_test)

I am having a problem with the c50_preds <- predict(c50_model, x_test) part giving me an error.

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 Databases Questions!