You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The MNLTrainTest function is not doing as described. The function inputs dictates a percent_cross but then k-fold cross validation occurs- with 6 folds hard coded in.
If you would like my rewrite, I have rewritten the function to repeat lines 21-41 nboot times and save the return the mean output.
MNLTrainTest<-function(mnl_input="mnl_input_0.csv",percent_cross=0.7,nboot=100)
{
library(nnet)
set.seed(123)
#Read in data
data<-read.table(mnl_input,sep=",",header = TRUE)
#data <- subset(data, select = -c(NA.) )
data2<-subset(data,select=-1)
accuracy=c()
for(i in seq(1,nboot)){
trainingRows <- sample(1:nrow(data2), percent_cross*nrow(data))
training <- data2[trainingRows, ]
testing <- data2[-trainingRows, ]
multinomModel <- multinom(Source ~ ., data=training, maxit=1000) # multinom Model
# predicted_scores <- predict (multinomModel, testing, "probs")
predicted_class <- predict (multinomModel, testing)
# table(predicted_class, testing2$Source)
# Calculate the number of correctly predicted sources.
accuracy<-c(accuracy,mean(as.character(predicted_class) == as.character(testing$Source)))
}
return(mean(accuracy))
}
The text was updated successfully, but these errors were encountered:
The MNLTrainTest function is not doing as described. The function inputs dictates a percent_cross but then k-fold cross validation occurs- with 6 folds hard coded in.
If you would like my rewrite, I have rewritten the function to repeat lines 21-41 nboot times and save the return the mean output.
The text was updated successfully, but these errors were encountered: