[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-sig-geo
Subject:    [R-sig-Geo] Error in image classification (raster stack) with random forest (ranger) and GLM (glmnet
From:       Hugo Costa <hugoagcosta () gmail ! com>
Date:       2017-09-26 20:48:52
Message-ID: CADvFi5r_2PyT0ompGxstOgyuPSxexSy2iybSFF77-xuXhnk8Lw () mail ! gmail ! com
[Download RAW message or body]

Dear list

I'm fitting some models to classify a raster image. The prediction function
produces an error for RF (package ranger) and a GLM (package glmnet).

The error given by RF is:
Error in v[cells, ] <- predv : incorrect number of subscripts on matrix
(see reproducible example at the end)

although the error with my real data is:
Error in p[-naind, ] <- predv : number of items to replace is not a
multiple of replacement length

The error given by GLM is:
Error in cbind2(1, newx) %*% (nbeta[[i]]) :
  not-yet-implemented method for <data.frame> %*% <dgCMatrix>

I'm interested in using these specific packages due to specific
circumstances of my work. Any solution to solve this issue would be highly
appreciated.
Thanks
Hugo

library(raster)
library(ranger)
library(glmnet)
library(nnet)
data(iris)

# put iris data into a raster stack
r<-list()
for(i in 1:4){
  r[[i]]<-raster(nrows=10, ncols=15)
  r[[i]][]<-iris[,i]
}
r<-stack(r)
names(r)<-names(iris)[1:4]

# ranger
m1<-ranger(Species ~ ., data=iris)
p1<-predict(r,m1)

# glmnet
m2 <- glmnet(as.matrix(iris[,1:4]),iris[,5],family=c("multinomial"))
p2<-predict(r,m2,type="class",s=0)

# multinom (this works)
m3 <- multinom(Species ~ ., data=iris, trace=F)
p3<-predict(r,m3)
plot(p3)

	[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic