【问题标题】:Getting Incorrect Results with R Neuralnet packages使用 R Neuralnet 包获得不正确的结果
【发布时间】:2015-11-06 06:18:54
【问题描述】:

在 R 中运行以下代码来训练神经网络对笔迹进行分类。共有63列,其中第63列是从0到9的分类

library(neuralnet)
data <- read.csv("handwriting.csv")
index <- sample(1:nrow(data),round(0.75*nrow(data)))
train <- data[index,]
test <- data[-index,]
n <- names(train)
f <- as.formula(paste("a63 ~", paste(n[!n %in% "a63"], collapse = " + ")))
nn <- neuralnet(f,data=train, hidden=2, linear.output=F, act.fct = "logistic", err.fct="ce")
plot(nn)
pr.nn <- compute(nn,test[, -63])
predicted <- pr.nn$net.result
results <- cbind(predicted, test$a63)
results

我在最后一步得到的输出如下

4480 0.9999991455    0
4482 0.9999991455    2
4490 0.9999991455    0
4492 0.9999991455    2
4494 0.9999991455    4

带小数的第一列是预测结果,但这不是我所期望的,因为结果应该是分类的,就像最后一列不是小数一样,当我更改 linear.output = TRUE 时,我得到更接近的值但是这不是正确的解释,因为我的意图是分类

【问题讨论】:

  • “不正确的结果”是一个煽动性的问题标题,与“不是我所期望的”有很大不同。

标签: r machine-learning neural-network


【解决方案1】:

R 不知道 csv 中的 0-9 是一个分类变量。你必须强迫它成为一个因素。现在,您正在预测一个连续值。在直接跳到预测建模之前进行一些探索性分析会有所帮助,包括确保您在调用 class() 函数时使用了正确的数据类型。

【讨论】:

    猜你喜欢
    • 2020-11-09
    • 1970-01-01
    • 2021-10-11
    • 2020-01-13
    • 2023-03-17
    • 2014-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多