【R笔记】R机器学习(五)——决策树ID3算法

数据集


代码

Fold = function(Z=10, w, D, seed=7777){
n = now(w)
d = 1:n; dd = list()
e = levels(x[,D])
T = length(e); set.seed(seed)
for(i in 1:T){
d0 = d[w[,D]==e[i]]; j = length(d0)
ZT = rep(1:Z. ceiling(j/Z)[1:j]
id = cbind(sample(ZT, length(ZT)), d0); dd[[I]]=id}
mm = list(); for(I in 1:Z){u=NULL;
for(j in 1:T) u = c(u, dd[[j]][dd[[j]][,1]==I,2])
mm[[I]]=u}
return(mm)}

w = read.csv('data.csv')
library(rpart.plot)
a = rpart(NSP~., w)
rpart.plot(a, type = 2, extra = 4)


你可能感兴趣的:(Machine,Learning,R,R学习笔记)