C语言十折交叉验证,R随机森林交叉验证 + 进度条

library(data.table)

library(randomForest)

data

str(data)

#交叉验证,使用rf预测sepal.length

k = 5

data$id

list

# 每次迭代的预测用数据框,测试用数据框

# the folds

prediction

testsetCopy

# 写一个进度条,用来了解CV的进度

progress.bar

progress.bar$init(k)

#k层的函数

for(i in 1:k){

# 删除id为i的行,创建训练集

# 选id为i的行,创建训练集

trainingset

testset

#运行一个随机森林模型

mymodel

#去掉回应列1, Sepal.Length

temp

# 将迭代出的预测结果添加到预测数据框的末尾

prediction

# 将迭代出的测试集结果添加到测试集数据框的末尾

# 只保留Sepal Length一列

testsetCopy

progress.bar$step()

}

# 将预测和实际值放在一起

result

names(result)

result$Difference

# 用误差的绝对平均值作为评估

summary(result$Difference)

交叉验证伪代码

for each epoch

for each training data instance

propagate error through the network

adjust the weights

calculate the accuracy over training data

for each validation data instance

calculate the accuracy over the validation data

if the threshold validation accuracy is met

exit training

else

continue training

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值