这是更新的代码。我的问题是"结果"的输出。我将在下面发布可读性格式。
library("neuralnet")
library("ggplot2")
setwd("C:/Users/Aaron/Documents/UMUC/R/Data For Assignments")
trainset <- read.csv("SOTS.csv")
head(trainset)
## val data classification
str(trainset)
## building the neural network
risknet <- neuralnet(Overall.Risk.Value ~ Finance + Personnel + Information.Dissemenation.C, trainset, hidden = 10, lifesign = "minimal", linear.output = FALSE, threshold = 0.1)
##plot nn
plot(risknet, rep="best")
##import scoring set
score_set <- read.csv("SOSS.csv")
##select subsets-training and scoring match
score_test <- subset(score_set, select = c("Finance", "Personnel", "Information.Dissemenation.C"))
##display values of score_test
head(score_test)
##neural network compute function score_test and the neural net "risknet"
risknet.results <- compute(risknet, score_test)
##Actual value of Overall.Risk.Value variable wanting to predict. net.result = a matrix containing the overall result of the neural network
results <- data.frame(Actual = score_set$Overall.Risk.Value, Prediction = risknet.results$net.result)
results[1:14, ]
结果的输出不符合预期。例如,实际数据是5到8之间的数字,而&#34;预测&#34;显示每个结果的.9995 ...输出。
再次感谢您的帮助。
答案 0 :(得分:0)
这是你训练和预测的方式:
risknet
)Here是一个非常类似于你的例子,它解释了这是如何完成的。
答案 1 :(得分:0)
Neuralnet中的默认激活功能是“逻辑”。当linear.output设置为FALSE时,它确保输出由激活函数映射到区间[0,1]。(R_Journal(neuralnet) - FraukeGünther)
我刚刚在代码中更新了linear.output = TRUE,最终结果看起来好多了。
感谢您的帮助!