【发布时间】:2016-11-05 05:54:12
【问题描述】:
我想在 R 中使用神经网络来预测汽车的价格,它有 144 个自变量。 在我的代码下面。一切正常,除了最后 2 行:AUC 和绘图。
这是我得到的错误:
roc(predNN, yTEST) 中的错误: 没有足够的不同预测来计算 ROC 曲线下的面积。
我已经计算了因变量作为一个因素,但这个错误仍然存在。 我应该如何解决这个问题?
allind <- sample(x=1:nrow(data_price2),size=nrow(data_price2))
trainind <- allind[1:round(length(allind)/3)]
valind <- allind[(round(length(allind)/3)+1):round(length(allind)*(2/3))]
testind <- allind[round(length(allind)*(2/3)+1):length(allind)]
BasetableTRAIN <- data_price2[trainind,]
BasetableVAL <- data_price2[valind,]
Basetablebig <-rbind(BasetableTRAIN,BasetableVAL)
BasetableTEST <- data_price2[testind,]
#Create a separate response variable
yTRAIN <- BasetableTRAIN$Price
BasetableTRAIN$Price <- NULL
yVAL <- BasetableVAL$Price
BasetableVAL$Price <- NULL
yTEST <- BasetableTEST$Price
BasetableTEST$Price <- NULL
yBIG <- Basetablebig$Price
Basetablebig$Price <- NULL
yTRAIN <- as.factor(yTRAIN)
yVAL <- as.factor(yVAL)
yTEST <- as.factor(yTEST)
yBIG <- as.factor(yBIG)
if (require("nnet")==FALSE) install.packages("nnet") ; library(nnet)
if (require("AUC")==FALSE) install.packages("AUC") ; library(AUC)
size <- 5 #number of units in the hidden layer
decay <- 0.1 #weight decay. Same as lambda in regularized LR. Controls for
overfitting.
rang <- 0.5 #the range of the initial random weights parameter
maxit <- 2000 #set high in order not to run into early stopping
NN <- nnet(yBIG ~ ., Basetablebig, size = size,
rang = rang, decay = decay, maxit = maxit,MaxNWts= Inf)
predNN <- as.numeric(predict(NN,BasetableTEST,type="raw"))
AUC::auc(roc(predNN,yTEST))
plot(roc(predNN,yTEST))
【问题讨论】:
标签: r neural-network roc