0
我試圖用rpart在R中創建一個decisiontree。我如何使用rpart創建一棵簡單的樹?
#rm(list = ls())
cat("\014")
library("rpart")
#data
mf <- factor(c("m","m","f","f","m","f","m"))
heights <- c(180, 175 , 160, 166, 185, 170, 190)
x = data.frame(cbind(heights, mf))
#create tree
fit <- rpart(mf ~ ., data = x, method = "anova")
predicted <- predict(fit,character = 180)
我預計「預測」給我一個「m」或「f」,但我得到的只是一個微不足道的數字。 爲了得到一封信,我需要改變什麼?
感謝