支持向量机和决策树建模

这篇博客介绍了使用R语言的'rpart'包构建决策树模型,通过规则2和7展示了鸢尾花分类的条件。同时,也展示了支持向量机(SVM)的训练结果,包括参数设置、模型性能和训练误差。两种模型都在鸢尾花数据集上进行了应用。
摘要由CSDN通过智能技术生成
Tree as rules: 

 Rule number: 2 [Species=setosa cover=38 (36%) prob=1.00]
   Petal.Length< 2.35

 Rule number: 7 [Species=virginica cover=30 (29%) prob=0.00]
   Petal.Length>=2.35
   Petal.Width>=1.65

 Rule number: 6 [Species=versicolor cover=37 (35%) prob=0.00]
   Petal.Length>=2.35
   Petal.Width< 1.65

[1] 2 1 5 4 3

#Rattle timestamp: 2021-03-24 21:18:48 yangmenglei

# Rattle timestamp: 2021-03-24 21:18:47 x86_64-w64-mingw32 

# Decision Tree 

# The 'rpart' package provides the 'rpart' function.

library(rpart, quietly=TRUE)

# Reset the random number seed to obtain the same results each time.

set.seed(crv$seed)

# Build the Decision Tree model.

crs$rpart <- rpart(Species ~ .,
    data=crs$dataset[crs$train, c(crs$input, crs$target)],
    method="class",
    parms=list(split="information"),
    control=rpart.control(usesurrogate=0, 
        maxsurrogate=0),
    model=TRUE)

# Generate a textual view of the Decision Tree model.

print(crs$rpart)
printcp(crs$rpart)
cat("\n")

# Time taken: 0.00 secs

# List the rules from the tree using a Rattle support function.

asRules(crs$rpart)

#=======================================================================

#支持向量机
# Rattle timestamp: 2021-03-24 21:19:17 x86_64-w64-mingw32 

# Plot the resulting Decision Tree. 

# We use the rpart.plot package.

fancyRpartPlot(crs$rpart, main="Decision Tree iris2.csv $ Species")
Summary of the SVM model (built using ksvm):

Support Vector Machine object of class "ksvm" 

SV type: C-svc  (classification) 
 parameter : cost C = 1 

Gaussian Radial Basis kernel function. 
 Hyperparameter : sigma =  0.52087038345841 

Number of Support Vectors : 49 

Objective Function Value : -3.5805 -3.6993 -18.2016 
Training error : 0.019048 
Probability model included. 

Time taken: 0.83 secs

Rattle timestamp: 2021-03-24 21:25:15 yangmenglei
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱做饭的电饭煲

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值