Muhaddesa Noori
Muhaddesa Noori

Reputation: 11

I am having issue running this r code. I am trying to use ANN classification model to classify one variable using the other variables

this dataframe is about Farmers Risk attitude. I want to classify Risk Attitude, using Risk drought in Artificial Neural Network model.

x=data.frame(x$Riskdrought, x$RiskAtt)
colnames(x)=c("Riskdrought", "RiskAtt")
head(x)
#Split the data set x into training and test
s=sample(nrow(x), floor(0.8*nrow(x)))
x.train=x[s, ]
head(x.train)
x.test=x[-s, -2]## does not contain classifier
head(x.test)
x.test.y=x[-s, 2] ## contain the classifier 

head(x.test.y)
nn=neuralnet(RiskAtt~Riskdrought, data =x.train, hidden = 1,
         act.fct = "logistic", linear.output = FALSE)
plot(nn)

##Compute the error rate using test dataset 
pr.test=compute(nn, x.test)

when I want to computer the error rate using test dataset, it gives me error of length of zero. although I checked my x.test and it is fine.

Upvotes: 1

Views: 31

Answers (1)

Khan
Khan

Reputation: 11

Since you exclude the one column from x.test[-s-2] then it no longer remains a dataframe, one option is to use 3 variable in the dataframe

Upvotes: 1

Related Questions