[R] svm with GRASS GIS
giuseppe calamita
calamita_giuseppe at yahoo.it
Sat Feb 18 19:06:05 CET 2012
Dear Etienne, I'm a colleauge of Gabriele and I'm more into R (but he is
more into GRASS).
I'll try to explain you what we didi so far
1) Our ASTER images, (B1, B2 and B3) have 8363134 pixels; we made a subset
in order to have training data sets: that is, for each band (B1,B2 and B3)
916 pixels were extracted (through QGIS and GRASS-gis command line) so that
we finally had three images with 916 pixels and the rest were NA. We called
them as follow: B1_train; B2_train; B3_train
in R they were imported as SpatialGridDataFrame (SGDF) and they have:
8363134 obs. of 1 variable (with 8362218 NA's and 916 values)
2) then, we created a data frame containing the above mentioned SGDFs
>training <- data.frame(TL_training_2006_id,
B1_train, B2_train, B3_train)
where the first variables contains the classes for he classification
names(training)
[1] "TL_training_2006_id" "x" "y"
[4] "B1_train" "x.1" "y.1"
[7] "B2_train" "x.2" "y.2"
[10] "B3_train" "x.3" "y.3"
str(training)
'data.frame': 916 obs. of 12 variables:
$ TL_training_2006_id: int 7 7 7 7 7 7 7 7 7 7 ...
$ x : num 680239 680254 680269 680254 680269 ...
$ y : num 4545534 4545519 4545519 4545504 4545504 ...
$ B1_train : int 110 110 110 110 110 108 109 110 109 111 ...
$ x.1 : num 680239 680254 680269 680254 680269 ...
$ y.1 : num 4545534 4545519 4545519 4545504 4545504 ...
$ B2_train : int 64 65 64 64 64 65 65 65 65 65 ...
$ x.2 : num 680239 680254 680269 680254 680269 ...
$ y.2 : num 4545534 4545519 4545519 4545504 4545504 ...
$ B3_train : int 42 43 43 43 42 42 42 43 43 42 ...
$ x.3 : num 680239 680254 680269 680254 680269 ...
$ y.3 : num 4545534 4545519 4545519 4545504 4545504 ...
3) then we applied the svm() function to calibrate the model on the training
data set
model_ASTER3 <- svm(TL_training_2006_id ~ B1_train + B2_train + B3_train,
data = training)
4) we created a data frame containing the three complete images for each
band (that we want to classify)
composition <- data.frame(B1, B2, B3)
names(composition)
[1] "B1" "x" "y" "B2" "x.1" "y.1" "B3" "x.2" "y.2"
I removed the column containing coordinates and then I tried this
pred <- predict(model_ASTER3, composition)
but I got this error message :
Error in model.frame.default(object, data, xlev = xlev) : object is not a
matrix
Thank you for your help! :)
PS: dput(training[1:10, ])
structure(list(TL_training_2006_id = c(7L, 7L, 7L, 7L, 7L, 7L,7L, 7L, 7L,
7L),
x = c(680239.441714673, 680254.438325991, 680269.434937309,
680254.438325991, 680269.434937309, 680284.431548628, 680299.428159946,
680254.438325991, 680269.434937309, 680284.431548628),
y = c(4545534.08962597, 4545519.09315455, 4545519.09315455,
4545504.09668313, 4545504.09668313, 4545504.09668313, 4545504.09668313,
4545489.10021171, 4545489.10021171, 4545489.10021171),
AST_L1B_2008_05_2009_area_giusta_1_training = c(110L, 110L, 110L, 110L,
110L, 108L, 109L, 110L, 109L, 111L),
x.1 = c(680239.441714673, 680254.438325991, 680269.434937309,
680254.438325991, 680269.434937309, 680284.431548628, 680299.428159946,
680254.438325991, 680269.434937309, 680284.431548628),
y.1 = c(4545534.08962597, 4545519.09315455, 4545519.09315455,
4545504.09668313, 4545504.09668313, 4545504.09668313, 4545504.09668313,
4545489.10021171, 4545489.10021171, 4545489.10021171),
AST_L1B_2008_05_2009_area_giusta_2_training = c(64L, 65L, 64L, 64L, 64L,
65L, 65L, 65L, 65L, 65L),
x.2 = c(680239.441714673, 680254.438325991, 680269.434937309,
680254.438325991, 680269.434937309, 680284.431548628, 680299.428159946,
680254.438325991, 680269.434937309, 680284.431548628),
y.2 = c(4545534.08962597, 4545519.09315455, 4545519.09315455,
4545504.09668313, 4545504.09668313, 4545504.09668313, 4545504.09668313,
4545489.10021171, 4545489.10021171, 4545489.10021171),
AST_L1B_2008_05_2009_area_giusta_3N_training = c(42L, 43L, 43L, 43L, 42L,
42L, 42L, 43L, 43L, 42L),
x.3 = c(680239.441714673, 680254.438325991, 680269.434937309,
680254.438325991, 680269.434937309, 680284.431548628, 680299.428159946,
680254.438325991, 680269.434937309, 680284.431548628),
y.3 = c(4545534.08962597, 4545519.09315455, 4545519.09315455,
4545504.09668313, 4545504.09668313, 4545504.09668313, 4545504.09668313,
4545489.10021171, 4545489.10021171, 4545489.10021171)),
.Names = c("TL_training_2006_id", "x", "y",
"AST_L1B_2008_05_2009_area_giusta_1_training", "x.1", "y.1",
"AST_L1B_2008_05_2009_area_giusta_2_training",
"x.2", "y.2", "AST_L1B_2008_05_2009_area_giusta_3N_training", "x.3", "y.3"),
row.names = c(1328853L, 1331805L, 1331806L, 1334756L, 1334757L, 1334758L,
1334759L, 1337707L, 1337708L, 1337709L), class = "data.frame")
--
View this message in context: http://r.789695.n4.nabble.com/svm-with-GRASS-GIS-tp4388006p4400175.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list