I trying to make a filled contour plot, but seem to have some issues doing so.
I firstly tried to do it with ´plotly´which worked without any problems,I ran into problems, as i had to save the images. Now i am trying some other way.
This is function that outputs the data matrix
knn_tester <-function(max_smooth, maxK){
output = data.frame(k=numeric((maxK*max_smooth/2)-1), error =numeric((maxK*max_smooth/2)-1), kernel_size=numeric((maxK*max_smooth/2)-1), stringsAsFactors = FALSE)
#output = as.data.frame(matrix(ncol= 3))
#output = output[-1,]
number = 0
for(smooth in 1:max_smooth){
if(smooth%%2 != 0){
message("Smoothing level: " , smooth)
fullDataList[[1]] = loadSinglePersonsData(DPI,2,1,smooth); gc();
fullDataList[[2]] = loadSinglePersonsData(DPI,2,2,smooth); gc();
data<- dataset_extracter(fullDataList)
# data[1] = training
# data[2] = trainClass
# data[3] = testing
# data[4] = testClass
for(i in 1:maxK){
#print(data)
message("iteration: " , i)
output$kernel_size[number]= smooth
#z = smooth
output$k[number]=i
#x = i
predicted = knn(data$training,data[3]$testing,data[2]$trainClass,k = 1)
#message("done")
Error = mean(predicted == data[4]$testClass)
output$error[number] = Error
#y = Error
#print(z)
#print(x)
#print(y)
#rbind(output,data.frame(z,x,y))
#print(output)
number = number + 1
}
}
}
return(output)
}
output = knn_tester(12,10)
When i then tries to plot it:
filled.contour3(output)
I get this error
error in plot.window(xlim = c(0,1), ylim = range(levels), xaxs ="i", :
need finite 'ylim' values:
in addition: warning messages
1: in min(x,na.rm = na.rm): no non-missing arguments to min; returning Inf
2: in max(x,na.rm = na.rm): no non-missing argument to max; returning -Inf
3: in min(x): no non-missing arguments to min; returning Inf
4: in max(x): no non-missing arguments to max; returning -Inf
I am not sure why i get this error, as it without any problems with plotly... So I am not sure why this is happening?
`str(ouput)`
'data.frame': 59 obs. of 3 variables:
$ k : num 2 3 4 5 6 7 8 9 10 1 ...
$ error : num 0.226 0.226 0.226 0.226 0.226 ...
$ kernel_size: num 1 1 1 1 1 1 1 1 1 3 ...
data as matrix
k error kernel_size
[1,] 2 0.25500 3
[2,] 3 0.25375 3
[3,] 1 0.24825 5
[4,] 2 0.23050 5
[5,] 3 0.24275 5
[6,] 0 0.00000 0