【发布时间】:2021-08-05 07:36:17
【问题描述】:
简介
我正在学习人工智能的基础知识。我创建了一个带有随机数据的 .csv 文件来测试Decision Trees。我目前在Jupyther Notebook 中使用 R。
问题
温度、湿度和风是决定您是否可以飞行的变量。
当我执行 ctree(vuelo~., data=vuelo.csv) 时,它只是一个单个节点,而 我期待一个包含变量(Temperatura、Humdedad、Viento)的完整树,正如我在纸上解决的那样。
使用的数据是下一张表:
temperatura humedad viento vuelo
1 Hot High Weak No
2 Hot High Strong No
3 Hot High Weak Yes
4 Mild High Weak Yes
5 Cool Normal Weak Yes
6 Cool Normal Strong No
7 Cool Normal Strong Yes
8 Mild High Weak No
9 Cool Normal Weak Yes
10 Mild Normal Weak Yes
11 Mild Normal Strong Yes
12 Mild High Strong Yes
13 Hot Normal Weak Yes
14 Mild High Strong No
我不确定在导入数据时是否遗漏了什么,但我所做的是:
test <- read.csv("vuelo.csv")
备注
- 我正在使用 R 中的“party”库(其中包含我从中获得一些想法的示例)
编辑:
这是dput() 请求的结果
structure(list(temperatura = structure(c(2L, 2L, 2L, 3L, 1L,
1L, 1L, 3L, 1L, 3L, 3L, 3L, 2L, 3L), .Label = c("Cool", "Hot",
"Mild"), class = "factor"), humedad = structure(c(1L, 1L, 1L,
1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L), .Label = c("High",
"Normal"), class = "factor"), viento = structure(c(2L, 1L, 2L,
2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 1L), .Label = c("Strong",
"Weak"), class = "factor"), vuelo = structure(c(1L, 1L, 2L, 2L,
2L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 1L), .Label = c("No", "Yes"
), class = "factor")), class = "data.frame", row.names = c(NA,
-14L))
【问题讨论】:
-
嗨,您可以在您的数据上运行
dput()吗?这样,它将创建允许其他人轻松将数据读入 R 的代码。另见stackoverflow.com/a/5963610/5805670(dput部分) -
@slamballais 如果我理解你的链接,那就是你要求的,对吧?
-
是的,完美,谢谢!会去看看。
标签: r decision-tree