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

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

Error: C5.0 models require a factor outcome

问题

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

我的代码:

require(C50) # 包含C5.0决策树的包
require(gmodels) # 用于绘制图表和图形的包

print("选择提示时的数据文件")
dataset = read.table(file.choose(), header = T, sep=",")

# 排除DayNo列(第1列)
dataset = dataset[,-1]
# 对训练数据的特征列和类别列(输出)应用决策树算法,并生成DT模型。
model = C5.0(dataset[, -4], dataset[, 4])
# 绘制生成的决策树的图表
plot(model, type="s", main="决策树 1\n[用于训练模型的100%数据]")

输入数据:

Day,Outlook,Humidity,Wind,Play
D1,Sunny,High,Weak,No
D2,Sunny,High,Strong,No
D3,Overcast,High,Weak,Yes
D4,Rain,High,Weak,Yes
D5,Rain,Normal,Weak,Yes
D6,Rain,Normal,Strong,No
D7,Overcast,Normal,Strong,Yes
D8,Sunny,High,Weak,No
D9,Sunny,Normal,Weak,Yes
D10,Rain,Normal,Weak,Yes
D11,Sunny,Normal,Strong,Yes
D12,Overcast,High,Strong,Yes
D13,Overcast,Normal,Weak,Yes
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:

require(C50) # the package that has the C5.0 decision tree
require(gmodels) # a package used draw diagrams and 
#graphs

print("Choose the data file when prompted")
dataset = read.table(file.choose(), header = T, sep=",")

# to exclude the DayNo column (column #1) 
dataset = dataset[,-1]
# apply the decision tree algorithm to the training data 
#feature columns, and class column (output), and generate a 
#DT Model.
model = C5.0(dataset[, -4], dataset[, 4])
# we plot the diagram of the generated decision tree
plot(model, type="s", main="Decision Tree 1\n[%100 data 
used to train the model]")

Input data:

Day,Outlook,Humidity,Wind,Play
D1,Sunny,High,Weak,No
D2,Sunny,High,Strong,No
D3,Overcast,High,Weak,Yes
D4,Rain,High,Weak,Yes
D5,Rain,Normal,Weak,Yes
D6,Rain,Normal,Strong,No
D7,Overcast,Normal,Strong,Yes
D8,Sunny,High,Weak,No
D9,Sunny,Normal,Weak,Yes
D10,Rain,Normal,Weak,Yes
D11,Sunny,Normal,Strong,Yes
D12,Overcast,High,Strong,Yes
D13,Overcast,Normal,Weak,Yes
D14,Rain,High,Strong,No

答案1

得分: 1

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

text <-
"
Day,Outlook,Humidity,Wind,Play
D1,Sunny,High,Weak,No
D2,Sunny,High,Strong,No
D3,Overcast,High,Weak,Yes
D4,Rain,High,Weak,Yes
D5,Rain,Normal,Weak,Yes
D6,Rain,Normal,Strong,No
D7,Overcast,Normal,Strong,Yes
D8,Sunny,High,Weak,No
D9,Sunny,Normal,Weak,Yes
D10,Rain,Normal,Weak,Yes
D11,Sunny,Normal,Strong,Yes
D12,Overcast,High,Strong,Yes
D13,Overcast,Normal,Weak,Yes
D14,Rain,High,Strong,No
"
dataset <- read.table(text = text, header = TRUE, sep = ',')

require(C50) # 包含C5.0决策树的包
require(gmodels) # 用于绘制图表的包

# 数据从文本字符串加载到此答案中
# 打印“在提示时选择数据文件”
# dataset = read.table(file.choose(), header = T, sep=",")

# 排除DayNo列(第1列)
dataset = dataset[, -1]

# 结果必须是'factor'(类别)
dataset$Play <- as.factor(dataset$Play)

# 将决策树算法应用于训练数据
# 特征列和类别列(输出),并生成
# DT模型。
model = C5.0(dataset[,-4], dataset[, 4])
# 绘制生成的决策树的图表
plot(model, type = "s", main = "Decision Tree 1\n[%100 data
used to train the model]")

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

英文:

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

text <-
"
Day,Outlook,Humidity,Wind,Play
D1,Sunny,High,Weak,No
D2,Sunny,High,Strong,No
D3,Overcast,High,Weak,Yes
D4,Rain,High,Weak,Yes
D5,Rain,Normal,Weak,Yes
D6,Rain,Normal,Strong,No
D7,Overcast,Normal,Strong,Yes
D8,Sunny,High,Weak,No
D9,Sunny,Normal,Weak,Yes
D10,Rain,Normal,Weak,Yes
D11,Sunny,Normal,Strong,Yes
D12,Overcast,High,Strong,Yes
D13,Overcast,Normal,Weak,Yes
D14,Rain,High,Strong,No
"
dataset <- read.table(text = text, header = TRUE, sep = ',')


require(C50) # the package that has the C5.0 decision tree
require(gmodels) # a package used draw diagrams and
#graphs

# Data is loaded from text string in this answer
# print("Choose the data file when prompted")
# dataset = read.table(file.choose(), header = T, sep=",")

# to exclude the DayNo column (column #1)
dataset = dataset[, -1]

# The outcome must be a 'factor' (category)
dataset$Play <- as.factor(dataset$Play)

# apply the decision tree algorithm to the training data
#feature columns, and class column (output), and generate a
#DT Model.
model = C5.0(dataset[,-4], dataset[, 4])
# we plot the diagram of the generated decision tree
plot(model, type = "s", main = "Decision Tree 1\n[%100 data
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:

确定