rm(list = ls())
library(dplyr)
library(rpart)
df <-read.csv("/data/bigfiles/iris.csv")
df <- df %>% as_tibble()
model <-
print(model$cptable[nrow(model$cptable), 'CP'])
可以使用 rpart 函数来建立决策树模型,如下所示:
model <- rpart(species ~ sepal_length + sepal_width, data = df, cp = 0.05)
代码使用了 ~ 运算符来指定输入和输出。species 是输出,sepal_length 和 sepal_width 是输入。使用 data 参数来指定数据帧,使用 cp 参数来指定剪枝所使用的最小交叉验证误差。
请问你想问啥呢?