R语言与数据分析

K最近邻(k-Nearest Neighbor,KNN)分类算法

  R语言实现包:R语言中有kknn package实现了weighted k-nearest neighbor。

决策树:

  R语言实现决策树:rpart扩展包

iris.rp = rpart(Species~.,data = iris,method = "class")
print(iris.rp)#输出模型结果

node), split, n, loss, yval, (yprob)
    * denotes terminal node

1) root 150 100 setosa (0.33333333 0.33333333 0.33333333)
  2) Petal.Length< 2.45 50 0 setosa (1.00000000 0.00000000 0.00000000) *
  3) Petal.Length>=2.45 100 50 versicolor (0.00000000 0.50000000 0.50000000)
    6) Petal.Width< 1.75 54 5 versicolor (0.00000000 0.90740741 0.09259259) *
    7) Petal.Width>=1.75 46 1 virginica (0.00000000 0.02173913 0.97826087) *

plot(iris.rp,uniform = T,branch =  0,margin = 0.1)
test(iris.rp,use.n=T,fancy = T,col="blue")

 

  

转载于:https://www.cnblogs.com/yangk/p/4758608.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值