machine learning - Picture classification with Neural Network in R -


i want try neural network classification of data got out of pictures. code use getting pictures , turning them data, have idea of data looks like.

folder<-'.' file_list <- dir(folder, pattern="png") data <- mclapply(file_list, readpng)  # extract subject id + img nr names subject_ids <- lapply(file_list, function(file_name) as.numeric(unlist(strsplit(file_name, "_"))[1])) # rename subject id's subject_ids[subject_ids==0]='circle' subject_ids[subject_ids!='circle']='line' img_ids <- lapply(file_list, function(file_name) as.numeric(unlist(strsplit(unlist(strsplit(file_name, "_"))[2], "\\."))[1]))  # specify data should used test , train img nrs  nritems <- length(img_ids)/2 nrtest <- nritems*0.7 testitems <- sample(1:nritems, nrtest)  # split data train , test train_in <- t(array(unlist(data[img_ids %in% testitems]), dim=c(length(unlist(data[1])),sum(img_ids %in% testitems)))) train_out <- unlist(subject_ids[img_ids %in% testitems]) test_in <- t(array(unlist(data[!img_ids %in% testitems]), dim=c(length(unlist(data[1])),sum(!img_ids %in% testitems)))) test_out <- unlist(subject_ids[!img_ids %in% testitems]) 

i've got svm, k-nn , naivebayes working , code looks this:

#svm svm_model <- svm(train_in, train_out, type='c', kernel='linear') p <- predict(svm_model, test_in) table(test_out, p)  #k-nn knn_model <- knn(train = train_in, test = test_in, cl = train_out, k=2) table(test_out,knn_model)  #naivebayes nb_model <- naivebayes(train_in, factor(train_out), laplace = 0) nb_p <- predict(nb_model, test_in) table(test_out, nb_p) 

now i'm trying nn work don't know how. tried far, when run code rstudio keeps freezing.

nn_model <- train(train_in,                factor(train_out),                method = "nnet",                trcontrol = traincontrol(method = "cv", number = 10)) 

does know did wrong, or have better method me?


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -