错误:C5.0 模型需要一个因子结果

huangapple go评论149阅读模式
英文:

Error: C5.0 models require a factor outcome

问题

我正在测试这段代码,以查看R是否正确设置,但我一直收到标题中的错误。

我的代码:

  1. require(C50) # 包含C5.0决策树的包
  2. require(gmodels) # 用于绘制图表和图形的包
  3. print("选择提示时的数据文件")
  4. dataset = read.table(file.choose(), header = T, sep=",")
  5. # 排除DayNo列(第1列)
  6. dataset = dataset[,-1]
  7. # 对训练数据的特征列和类别列(输出)应用决策树算法,并生成DT模型。
  8. model = C5.0(dataset[, -4], dataset[, 4])
  9. # 绘制生成的决策树的图表
  10. plot(model, type="s", main="决策树 1\n[用于训练模型的100%数据]")

输入数据:

  1. Day,Outlook,Humidity,Wind,Play
  2. D1,Sunny,High,Weak,No
  3. D2,Sunny,High,Strong,No
  4. D3,Overcast,High,Weak,Yes
  5. D4,Rain,High,Weak,Yes
  6. D5,Rain,Normal,Weak,Yes
  7. D6,Rain,Normal,Strong,No
  8. D7,Overcast,Normal,Strong,Yes
  9. D8,Sunny,High,Weak,No
  10. D9,Sunny,Normal,Weak,Yes
  11. D10,Rain,Normal,Weak,Yes
  12. D11,Sunny,Normal,Strong,Yes
  13. D12,Overcast,High,Strong,Yes
  14. D13,Overcast,Normal,Weak,Yes
  15. D14,Rain,High,Strong,No
英文:

I was testing this code to see if R is set up properly, but I kept receiving the error in the title.

My code:

  1. require(C50) # the package that has the C5.0 decision tree
  2. require(gmodels) # a package used draw diagrams and
  3. #graphs
  4. print("Choose the data file when prompted")
  5. dataset = read.table(file.choose(), header = T, sep=",")
  6. # to exclude the DayNo column (column #1)
  7. dataset = dataset[,-1]
  8. # apply the decision tree algorithm to the training data
  9. #feature columns, and class column (output), and generate a
  10. #DT Model.
  11. model = C5.0(dataset[, -4], dataset[, 4])
  12. # we plot the diagram of the generated decision tree
  13. plot(model, type="s", main="Decision Tree 1\n[%100 data
  14. used to train the model]")

Input data:

  1. Day,Outlook,Humidity,Wind,Play
  2. D1,Sunny,High,Weak,No
  3. D2,Sunny,High,Strong,No
  4. D3,Overcast,High,Weak,Yes
  5. D4,Rain,High,Weak,Yes
  6. D5,Rain,Normal,Weak,Yes
  7. D6,Rain,Normal,Strong,No
  8. D7,Overcast,Normal,Strong,Yes
  9. D8,Sunny,High,Weak,No
  10. D9,Sunny,Normal,Weak,Yes
  11. D10,Rain,Normal,Weak,Yes
  12. D11,Sunny,Normal,Strong,Yes
  13. D12,Overcast,High,Strong,Yes
  14. D13,Overcast,Normal,Weak,Yes
  15. D14,Rain,High,Strong,No

答案1

得分: 1

"Play"列必须是C5.0的一个'factor'因子

  1. text <-
  2. "
  3. Day,Outlook,Humidity,Wind,Play
  4. D1,Sunny,High,Weak,No
  5. D2,Sunny,High,Strong,No
  6. D3,Overcast,High,Weak,Yes
  7. D4,Rain,High,Weak,Yes
  8. D5,Rain,Normal,Weak,Yes
  9. D6,Rain,Normal,Strong,No
  10. D7,Overcast,Normal,Strong,Yes
  11. D8,Sunny,High,Weak,No
  12. D9,Sunny,Normal,Weak,Yes
  13. D10,Rain,Normal,Weak,Yes
  14. D11,Sunny,Normal,Strong,Yes
  15. D12,Overcast,High,Strong,Yes
  16. D13,Overcast,Normal,Weak,Yes
  17. D14,Rain,High,Strong,No
  18. "
  19. dataset <- read.table(text = text, header = TRUE, sep = ',')
  20. require(C50) # 包含C5.0决策树的包
  21. require(gmodels) # 用于绘制图表的包
  22. # 数据从文本字符串加载到此答案中
  23. # 打印“在提示时选择数据文件”
  24. # dataset = read.table(file.choose(), header = T, sep=",")
  25. # 排除DayNo列(第1列)
  26. dataset = dataset[, -1]
  27. # 结果必须是'factor'(类别)
  28. dataset$Play <- as.factor(dataset$Play)
  29. # 将决策树算法应用于训练数据
  30. # 特征列和类别列(输出),并生成
  31. # DT模型。
  32. model = C5.0(dataset[,-4], dataset[, 4])
  33. # 绘制生成的决策树的图表
  34. plot(model, type = "s", main = "Decision Tree 1\n[%100 data
  35. used to train the model]")

错误:C5.0 模型需要一个因子结果

英文:

The Play column must be a 'factor' for C5.0

  1. text <-
  2. "
  3. Day,Outlook,Humidity,Wind,Play
  4. D1,Sunny,High,Weak,No
  5. D2,Sunny,High,Strong,No
  6. D3,Overcast,High,Weak,Yes
  7. D4,Rain,High,Weak,Yes
  8. D5,Rain,Normal,Weak,Yes
  9. D6,Rain,Normal,Strong,No
  10. D7,Overcast,Normal,Strong,Yes
  11. D8,Sunny,High,Weak,No
  12. D9,Sunny,Normal,Weak,Yes
  13. D10,Rain,Normal,Weak,Yes
  14. D11,Sunny,Normal,Strong,Yes
  15. D12,Overcast,High,Strong,Yes
  16. D13,Overcast,Normal,Weak,Yes
  17. D14,Rain,High,Strong,No
  18. "
  19. dataset <- read.table(text = text, header = TRUE, sep = ',')
  20. require(C50) # the package that has the C5.0 decision tree
  21. require(gmodels) # a package used draw diagrams and
  22. #graphs
  23. # Data is loaded from text string in this answer
  24. # print("Choose the data file when prompted")
  25. # dataset = read.table(file.choose(), header = T, sep=",")
  26. # to exclude the DayNo column (column #1)
  27. dataset = dataset[, -1]
  28. # The outcome must be a 'factor' (category)
  29. dataset$Play <- as.factor(dataset$Play)
  30. # apply the decision tree algorithm to the training data
  31. #feature columns, and class column (output), and generate a
  32. #DT Model.
  33. model = C5.0(dataset[,-4], dataset[, 4])
  34. # we plot the diagram of the generated decision tree
  35. plot(model, type = "s", main = "Decision Tree 1\n[%100 data
  36. used to train the model]")

错误:C5.0 模型需要一个因子结果

huangapple
  • 本文由 发表于 2023年7月7日 04:43:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76632426.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定