i was trying to predict price for used car data in r. i have done all the preprocessing and divided the data into training and test set. here i am using regression tree. when i was trying to get accuracy i got this error.
library(rpart)
library(tidyverse)
library(dplyr)
dput(head(train.df, 5))
reg_tree <- rpart(price ~ .,
data = train.df,
method = "anova", minbucket = 1, maxdepth = 30, cp = 0.001)
accuracy(predict(reg_tree, train.df), train.df$price)
structure(list(price = 33990, year = 2018L, manufacturer = structure(1L, .Label = c("acura",
"alfa-romeo", "aston-martin", "audi", "bmw", "buick", "cadillac",
"chevrolet", "chrysler", "datsun", "dodge", "ferrari", "fiat",
"ford", "gmc", "harley-davidson", "honda", "hyundai", "infiniti",
"jaguar", "jeep", "kia", "land rover", "lexus", "lincoln", "mazda",
"mercedes-benz", "mercury", "mini", "mitsubishi", "nissan", "pontiac",
"porsche", "ram", "rover", "saturn", "subaru", "tesla", "toyota",
"volkswagen", "volvo"), class = "factor"), condition = structure(4L, .Label = c("excellent",
"fair", "good", "like new", "new", "salvage"), class = "factor"),
cylinders = structure(6L, .Label = c("10 cylinders", "12 cylinders",
"3 cylinders", "4 cylinders", "5 cylinders", "6 cylinders",
"8 cylinders", "other"), class = "factor"), fuel = structure(3L, .Label = c("diesel",
"electric", "gas", "hybrid", "other"), class = "factor"),
odometer = 22267, title_status = structure(1L, .Label = c("clean",
"lien", "missing", "parts only", "rebuilt", "salvage"), class = "factor"),
transmission = structure(1L, .Label = c("automatic", "manual",
"other"), class = "factor"), drive = structure(2L, .Label = c("4wd",
"fwd", "rwd"), class = "factor"), size = structure(3L, .Label = c("compact",
"full-size", "mid-size", "sub-compact"), class = "factor"),
type = structure(4L, .Label = c("bus", "convertible", "coupe",
"hatchback", "mini-van", "offroad", "other", "pickup", "sedan",
"SUV", "truck", "van", "wagon"), class = "factor"), paint_color = structure(10L, .Label = c("black",
"blue", "brown", "custom", "green", "grey", "orange", "purple",
"red", "silver", "white", "yellow"), class = "factor")), row.names = 31113L, class = "data.frame")
Error in UseMethod("accuracy") :
no applicable method for 'accuracy' applied to an object of class "c('double', 'numeric')"
could anyone please help me in this.
Thanks in advance.