Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Classification of zero-crossings bat calls using machine learning
#Open call library (needs name (eg. MYLU), and parameters)
setwd = ("Dropbox/Anabat files/Dave's Florida Bat Calls/")
callsamplesALLNNET=read.csv(file="Dropbox/Anabat files/FloridaBatsALL.csv",header=T,sep=",")
callsamplesALLNNET[,-1]=scale(callsamplesALLNNET[,-1], center = T, scale = T)
fitControl <- trainControl(method = "cv", number = 10, returnResamp = "all", verboseIter = FALSE)
#train ANN on voucher calls
nnet1 <- train(Name ~., data = callsamplesALLNNET, method = "nnet", tuneLength = 10,
trControl = fitControl)
#open table of unknown calls (Filename = analook file with date and time) parameters must be identical to voucher calls above.
#test calls here are output of Analook scan of particular night's folder
testNNET = read.csv("Dropbox/Anabat files/test.csv", head = T, sep = ",")
testNNET$facName = factor(testNNET$Filename)
levels(testNNET$facName) = 1:1000
samp = testNNET$facName
testNNET[,2:12] = scale(testNNET[,2:12], center = TRUE, scale = TRUE)
#predict identity of unknown calls using NNET
nnetpred <- predict(nnet1, newdata = testNNET[,2:12])
species = data.frame(nnetpred)
res = cbind(samp, species)
#return a consensus (i.e. mode) of call assignments for each sequence
df.list <-vector("list",max(as.numeric(res$samp)))
for (i in 1:max(as.numeric(res$samp))) {
set = subset(res, samp==i)
consensus = names(sort(-table(set$nnetpred)))[1]
df.list[[i]] = consensus }
results = cbind(levels(testNNET[,1]),as.matrix(df.list))
colnames(results) = c("sequence", "consensus ID")
write.csv(results, file = "Dropbox/Anabat files/results.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.