R 中不带插入符号的交叉验证
由于我使用的模型(fastNaiveBayes 包)不在 caret 包的内置库中,因此我尝试在 R 中进行 k 折交叉验证而不使用 caret 包。有人有解决办法吗?
编辑: 这是迄今为止我学到的如何在没有插入符号的情况下进行简历的代码。我非常确定这里出了问题。
library(fastNaiveBayes)
k<- 10
outs <- NULL
proportion <- 0.8
for (i in 1:10)
{
split <- sample(1:nrow(data), round(proportion*nrow(data)))
traindata <- data[split,]
testdata <- data[-split,]
y <- traindata$Label
x <- traindata[,0 - 15:ncol(traindata)]
model <- fnb.train(x, y=y, priors = NULL, laplace=0,
distribution = fnb.detect_distribution(x, nrows = nrow(x)))
model
test1 <- testdata[,0 - 15:ncol(testdata)]
pred <- predict(model, newdata = test1)
cm<- table(testdata$Label, pred)
print(confusionMatrix(cm))
}
它给了我 10 个不同的结果,我认为这不是交叉验证应该如何工作的。我是一名入门级 R 学习者,非常感谢从中获得启发
Since the model (package fastNaiveBayes) that I am using is not in the built-in library of the caret package, I am trying to make a k-fold cross validation in R without using the caret package. Does anyone have a solution to this?
Edit:
Here is my code so far from what I learned on how to do cv without caret. I am very certain something is wrong here.
library(fastNaiveBayes)
k<- 10
outs <- NULL
proportion <- 0.8
for (i in 1:10)
{
split <- sample(1:nrow(data), round(proportion*nrow(data)))
traindata <- data[split,]
testdata <- data[-split,]
y <- traindata$Label
x <- traindata[,0 - 15:ncol(traindata)]
model <- fnb.train(x, y=y, priors = NULL, laplace=0,
distribution = fnb.detect_distribution(x, nrows = nrow(x)))
model
test1 <- testdata[,0 - 15:ncol(testdata)]
pred <- predict(model, newdata = test1)
cm<- table(testdata$Label, pred)
print(confusionMatrix(cm))
}
It gave me 10 different results and I think that's not how it cross validation is supposed to work. I'm an entry-level R learner and I appreciate so much to receive enlightenment from this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论