Description Usage Arguments Details Value Classification methods References See Also Examples
View source: R/classifyRasclass.R
Classifies data stored rasclass objects with one of five different classification algorithms. Also predicts the resulting output grid and calculates accuracy measures (accuray matrix, overall accuracy and kappa coefficient).
1 | classifyRasclass(rasclassObj, splitfraction = 1, method = 'logit', ...)
|
rasclassObj |
A |
method |
An optional argument to choose the classification algorithm. The default is ‘logit’, other options are ‘maximumLikelihood’, ‘neuralNetwork’, ‘randomForest’ or ‘supportVector’. |
splitfraction |
An optional |
... |
Optional additional arguments passed on to the classification functions. This can be used to run the classification algorithms with settings that are different from the default. |
With this function, data is classified using one out of the following five classification algorithms: Maximum Likelihood Classification, Multinomial Logistic Regression, Neural Networks, Random Forests or Support Vector Machines (see section ‘Classification methods’ for details of each algorithm). The algorithm can be specified using the method
argument, with ‘logit’ as default. Most classification algoritms are imported from other packages. To choose specific settings for the chosen algorithm, additional arguments specified in ‘...’ will be passed on to the classification function.
The optional argument ‘splitfraction’ can be used for in-sample verfication. If ‘splitfraction’ differs from zero, the data will be randomly split into two parts with the fraction specified. The classification model will then be trained on one fraction and the other fraction will be used for prediction. The accuracy measures are then calculated as an in-sample verification, only comparing accuracy in data that was not used for training the model. The ‘training’ slot of the rasclass object stores the splitting information as a logical vector.
Details of each classification algortithm are described below.
A rasclass-class
object, containing the classified raster, the classification object itself and standard accuracy measures: accuracy matrix, user and producer accuracies, overall accuracy and the kappa coefficient. All the outputs are stored in their corresponding slots of the output object.
The classification methods used here are mostly imported from other packages. The description of the details of the classifiers can be found in the documentation files of the imported functions. An algorithm can be chosen using the method
argument. To pass arguments to the chosen classifier, additional arguments can be given that are passed on to the classifier functions.
Gaussian Maximum Likelihood Classifier
The maximum likelihood classifier is implemented directly in this package. It is a parametric classifier and assumes normal probability distributions in each class. Detailed descriptions of the classifier can be found in the paper by Paola (2005) or in standard textbooks. Specify 'maximumLikelihood' in the methods argument to use this algorithm.
Multinomial Logistic Regression
The logit algorithm is imported from the multinom
function in the nnet
package. Details can be found in the documentation of the functions. Specify 'logit' in the methods argument to use this algorithm.
Neural Networks
Neural networks are implemented in the R Stuttgart Neural Network Simulator package. The function used for classification is the mlp
function from the RSNNS
package. Specify 'neuralNetwork' in the methods argument to use this algorithm.
Random Forests
The Random Forest classifier is imported from the randomForest
package using the
randomForest
function. Specify 'randomForest' in the methods argument to use this algorithm.
Support Vector Machines
Support Vector Machines are implemented in R in the e1071
package, which is an interface for the external C library libsvm
. The function used for claassification is svm
. Specify 'supportVector' in the methods argument to use this algorithm.
Paola, J. D., Schowengerdt, R. A. (1995). A detailed comparison of backpropagation neural network and maximum-likelihood classifiers for urban land use classification. IEEE Transactions on Geoscience and Remote Sensing, 33(4), 981-996.
rasclass-package
,
rasclass-class
,
rasclassRaster-class
,
readRasterFolder
,
setRasclassData
,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | ## Not run:
# If available, load data from external folder
object <- readRasterFolder(path = "mypath", samplename = "mysample",
filenames = c('myvar1.asc', 'myvar2.asc'))
## End(Not run)
# For this example, create artificial data
mysample <- c(rep(rep(c(1,2), each = 25), 25), rep(rep(c(3,4), each = 25), 25))
mysample <- mysample + sample(c(0, NA), 2500, replace = TRUE, prob = c(1, 50))
myvar1 <- rep(1:50, each = 50) + rnorm(2500, 0, 5)
myvar2 <- rep(rep(1:50), 50) + rnorm(2500, 0, 5)
newdata <- data.frame(mysample, myvar1, myvar2)
# Prepare a rasclass object using the dataframe and specifying raster properties
object <- new('rasclass')
object <- setRasclassData(newdata, ncols = 50, nrows = 50,
xllcorner = 0, yllcorner = 0, cellsize = 1, NAvalue = -9999,
samplename = 'mysample')
# Classify using each algorithm once
outlist <- list()
outlist[['maximumLikelihood']] <- classifyRasclass(object, method = 'maximumLikelihood')
summary(outlist[['maximumLikelihood']])
outlist[['logit']] <- classifyRasclass(object, method = 'logit')
summary(outlist[['logit']])
outlist[['neuralNetwork']] <- classifyRasclass(object, method = 'neuralNetwork')
summary(outlist[['neuralNetwork']])
outlist[['randomForest']] <- classifyRasclass(object, method = 'randomForest')
summary(outlist[['randomForest']])
outlist[['supportVector']] <- classifyRasclass(object, method = 'supportVector')
summary(outlist[['supportVector']])
# Store sample data as a rasclassRaster for display purposes
mysample.ras <- new('rasclassRaster')
mysample.ras@grid <- mysample
mysample.ras@nrows <- 50
mysample.ras@ncols <- 50
mysample.ras@xllcorner <- 0
mysample.ras@yllcorner <- 0
mysample.ras@cellsize <- 1
mysample.ras@NAvalue <- -9999
# Plot results of each classifier
opar <- par(mfrow = c(2, 3))
image(mysample.ras)
title('Sample data')
for(i in 1:length(outlist)) {
image(outlist[[i]]@predictedGrid)
title(names(outlist)[[i]])
}
par(opar)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.