GRASS logo

NAME

v.class.mlR - Provides supervised support vector machine classification

KEYWORDS

classification, machine learning, R, classifiers

SYNOPSIS

v.class.mlR
v.class.mlR --help
v.class.mlR [-fi] [segments_map=name] [segments_layer=string] [training_map=name] [training_layer=string] [segments_file=name] [training_file=name] [separator=character] [raster_segments_map=name] [classified_map=name] train_class_column=string output_class_column=string output_prob_column=string classifiers=string[,string,...] folds=integer partitions=integer tunelength=integer [tunegrids=string] weighting_modes=string[,string,...] weighting_metric=string [classification_results=name] [accuracy_file=name] [model_details=name] [bw_plot_file=name] [r_script_file=name] [processes=integer] [--overwrite] [--help] [--verbose] [--quiet] [--ui]

Flags:

-f
Only write results to text file, do not update vector map
-i
Include individual classifier results in output
--overwrite
Allow output files to overwrite existing files
--help
Print usage summary
--verbose
Verbose module output
--quiet
Quiet module output
--ui
Force launching GUI dialog

Parameters:

segments_map=name
Vector map with areas to be classified
Vector map containing all areas and relevant attributes
segments_layer=string
Layer of the segments map where attributes are stored
Vector features can have category values in different layers. This number determines which layer to use. When used with direct OGR access this is the layer name.
Default: 1
training_map=name
Vector map with training areas
Vector map with training areas and relevant attributes
training_layer=string
Layer of the training map where attributes are stored
Vector features can have category values in different layers. This number determines which layer to use. When used with direct OGR access this is the layer name.
Default: 1
segments_file=name
File containing statistics of all segments
File containing relevant attributes for all areas
training_file=name
File containing statistics of training segments
File containing relevant attributes for training areas
separator=character
Field separator
Field separator in input text files
Default: pipe
raster_segments_map=name
Raster map with segments
Input raster map containing all segments
classified_map=name
Prefix for raster maps (one per weighting mode) with classes attributed to pixels
Output raster maps (one per weighting mode) in which all pixels are reclassed to the class attributed to the segment they belong to
train_class_column=string [required]
Name of attribute column containing training classification
output_class_column=string [required]
Prefix of column with final classification
Default: vote
output_prob_column=string [required]
Prefix of column with probability of classification
Default: prob
classifiers=string[,string,...] [required]
Classifiers to use
Options: svmRadial, svmLinear, svmPoly, rf, rpart, C5.0, knn, knn1, xgbTree
Default: svmRadial,rf
folds=integer [required]
Number of folds to use for cross-validation
Default: 5
partitions=integer [required]
Number of different partitions to use for cross-validation
Default: 10
tunelength=integer [required]
Number of levels to test for each tuning parameter
Default: 10
tunegrids=string
Python dictionary of customized tunegrids
weighting_modes=string[,string,...] [required]
Type of weighting to use
Options: smv, swv, bwwv, qbwwv
Default: smv
weighting_metric=string [required]
Metric to use for weighting
Options: accuracy, kappa
Default: accuracy
classification_results=name
File for saving results of all classifiers
accuracy_file=name
File for saving accuracy measures of classifiers
model_details=name
File for saving details about the classifier module runs
bw_plot_file=name
PNG file for saving box-whisker plot of classifier performance
r_script_file=name
File containing R script
processes=integer
Number of processes to run in parallel
Default: 1

Table of contents

DESCRIPTION

v.class.mlR is a wrapper script that uses the R caret package for machine learning in R to classify features using training features by supervised learning.

The user provides a set of objects (or segments) to be classified, including all feature variables describing these object, and a set of objects to be used as training data, including the same feature variables as those describing the unknown objects, plus one additional column indicating the class each training falls into. The training data can, but does not have to be, a subset of the set of objects to be classified.

The user can provide input either as vector maps (segments_map and training_map, or as csv files (segments_file and training file, or a combination of both. Csv files have to be formatted in line with the default output of v.db.select, i.e. with a header. The field separator can be set with the separator parameter. Output can consist of either additional columns in the vector input map of features, a text file (classification_results) or reclassed raster maps (classified_map).

The user has to provide the name of the column in the training data that contains the class values (train_class_column), the prefix of the columns that will contain the final class after classification (output_class_column) as well as the prefix of the columns that will contain the probability values linked to these classifications (output_prob_column - see below).

Different classifiers are proposed classifiers: k-nearest neighbor (knn and knn1 for k=1), support vector machine with a radial kernel (svmRadial), random forest (rf) and recursive partitioning (rpart). Each of these classifiers is tuned automatically throught repeated cross-validation. caret will automatically determine a reasonable set of values for tuning. See the caret webpage for more information about the tuning parameters for each classifier, and more generally for the information about how caret works. By default, the module creates 10 5-fold partitions for cross-validation and tests 10 possible values of the tuning parameters. These values can be changed using, repectively, the partitions, folds and tunelength parameters.

The user can define a customized tunegrid for each classifier, using the tunegrids parameter. Any customized tunegrid has to be defined as a Python dictionary, with the classifiers as keys, and the input to expand.grid() as content as defined in the caret documentation.

For example, to define customized tuning grids for svmRadial and RandomForest, the user can define the paramter as:

tunegrids="{'svmRadial': 'sigma=c(0.01,0.05,0.1), C=c(1,16,128)', 'rf': 'mtry=c(3,10,20)'}"

The module can run the model tuning using parallel processing. In order for this to work, the R-package doParallel has to be installed. The processes parameter allows to chose the number of processes to run.

The user can chose to include the individual classifiers results in the output (the attributes and/or the raster maps) using the i flag, but by default the output will be the result of a voting scheme merging the results of the different classifiers. Votes can be weighted according to a user-defined mode (weighting_mode): simple majority vote without weighting, i.e. all weights are equal (smv), simple weighted majority vote (swv), best-worst weighted vote (bwwv) and quadratic best-worst weighted vote (qbwwv). For more details about these voting modes see Moreno-Seco et al (2006). By default, the weights are calculated based on the accuracy metric, but the user can chose the kappa value as an alternative (weighting_metric).

In the output (as attribute columns or text file) each weighting schemes result is provided accompanied by a value that can be considered as an estimation of the probability of the classification after weighted vote, based on equation (2) in Moreno et al (2006), page 709. At this stage, this estimation does not, however, take into account the probabilities determined individually by each classifier.

Optional output of the module include detailed information about the different classifier models and their cross-validation results model_details (for details of these results see the train, resamples and confusionMatrix.train functions in the caret package) a box-and-whisker plot indicating the resampling variance based on the cross-validation for each classifier (bw_plot_file) and a csv file containing accuracy measures (overall accuracy and kappa) for each classifier (accuracy_file). The user can also chose to write the R script constructed and used internally to a text file for study or further modification.

NOTES

The module can be used in a tool chain together with i.segment and the addon i.segment.stats for object-based classification of satellite imagery.

WARNING: The option output files are created by R and currently no checking is done of whether files of the same name already exist. If they exist, they are silently overwritten, regardless of whether the GRASS GIS --o flag is set or not.

The module makes no effort to check the input data for NA values or anything else that might perturb the analyses. It is up to the user to proceed to relevant checks before launching the module.

DEPENDENCIES

This module uses R. It is the user's responsibility to make sure R is installed and can be called from the environment this module is running in. See the relevant wiki page for more information. The module tries to install necessary R packages automatically if necessary. These include : 'caret', 'kernlab', 'e1071', 'randomForest', and 'rpart'. Other packages can be necessary such as 'ggplot2', 'lattice' (for the plots), and 'doParallel' (if parallel processing is desired).

TODO

EXAMPLE

Using existing vector maps as input and writing the output to the attribute table of the segments map, including the individual classifier results:

v.class.mlR segments_map=seg training_map=training train_class_column=class weighting_mode=smv,swv,qbwwv -i

Using text files with segment characteristics as input and writing output to raster files and a csv file

v.class.mlR segments_file=segstats.csv training_file=training.csv train_class_column=class weighting_mode=smv,swv,qbwwv raster_segments_map=seg classified_map=vote classification_results=class_results.csv

REFERENCES

Moreno-Seco, F. et al. (2006), Comparison of Classifier Fusion Methods for Classification in Pattern Recognition Tasks. In D.-Y. Yeung et al., eds. Structural, Syntactic, and Statistical Pattern Recognition. Lecture Notes in Computer Science. Springer Berlin Heidelberg, pp. 705–713, http://dx.doi.org/10.1007/11815921_77.

SEE ALSO

i.segment, r.object.activelearning, r.learn.ml

AUTHOR

Moritz Lennert, Université Libre de Bruxelles (ULB) based on an initial R-script by Ruben Van De Kerchove, also ULB at the time

Last changed: $Date: 2018-06-07 16:15:10 +0200 (Thu, 07 Jun 2018) $

SOURCE CODE

Available at: v.class.mlR source code (history)


Main index | Vector index | Topics index | Keywords index | Graphical index | Full index

© 2003-2019 GRASS Development Team, GRASS GIS 7.4.5svn Reference Manual