library("dplyr")
library("data.table")
library("spikeSlabGAM")
downloadAM <- function(auto_url) {
automobile <-
fread(auto_url,
na.strings = "?")
return(automobile)
}
prepareAM <- function(am) {
# Only select categorical variables and numerical output
sam = am %>% select(c(3:9, 15:16, 18, 26))
colnames(sam) = c(
"make",
"fuel-type",
"aspiration",
"num-of-doors",
"body-style",
"drive-wheels",
"engine-location",
"engine-type",
"num-of-cylinders",
"fuel-system",
"price"
)
pAM = data.frame(select(sam,-"price") %>% sapply(function(x)
as.factor(x)))
pAM$price = sam$price
return(pAM %>% filter(complete.cases(.)))
}
am = downloadAM(
'https://archive.ics.uci.edu/ml/machine-learning-databases/autos/imports-85.data'
) %>% prepareAM()
formula = formula(paste(
"price ~ fct(",
paste(colnames(am)[-11], collapse = ") + fct("),
")",
sep = ""
))
m <- spikeSlabGAM(formula, data = am)
predict(m, am)
table(am$engine.type)
dohc dohcv l ohc ohcf ohcv rotor
12 0 12 143 15 13 4
am$engine.type <- factor(am$engine.type)
predict(m, am)