日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

R语言的决策树

發布時間:2024/10/8 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 R语言的决策树 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

# 計算商 a <- rep(0.5,2) #0.5重復兩遍 -sum(a*log2(a))

1

b <- rep(0.25,4) -sum(b*log2(b))

2

c <- rep(0.125,8) -sum(c*log2(c))

3



# r語言實現決策樹 library(rpart) iris.rp = rpart(data=iris,Species~.,method="class") iris.rp n= 150 node), split, n, loss, yval, (yprob)* denotes terminal node1) 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,main="Classification Tree") text(iris.rp,use.n =T ,fancy = T,col="blue")

# kyphosis駝背數據集 library(rpart) head(kyphosis) KyphosisAgeNumberStart
absent 71 3 5
absent 158 3 14
present128 4 5
absent 2 5 1
absent 1 4 15
absent 1 2 16
[1] 4Error in shape(kyphosis): 沒有"shape"這個函數 Traceback:

ct <- rpart.control(xval = 10,minsplit = 20,cp=0.1) fit <- rpart(Kyphosis~Age + Number +Start,data = kyphosis,method = "class",control =ct,parms = list(prior =c(0.65,0.35),split = 'information'))



# 并列畫兩張圖 ### 第一種 plot(fit) text(fit,use.n=T,all=T,cex=0.9) # 第二種 library(rpart.plot) rpart.plot(fit,branch=1,branch.type = 2,type =1, extra =102,shadow.col="gray",box.col="green",border.col="blue",split.col='red',split.cex = 1.2,main="Kyphosis 決策樹")

res <- predict(fit) result <- ifelse(res[,2]>0.5,'present','absent') table(kyphosis$Kyphosis,result) resultabsent presentabsent 53 11present 3 14 a <- table(kyphosis$Kyphosis,result) # 準確度 (a[1,1] +a[2,2 ])/sum(a)

0.827160493827161

# 召回率 a[2,2]/sum(a[2,])

0.823529411764706

# 精確度 a[2,2]/sum(a[,2])

0.56

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的R语言的决策树的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。