Trains a decision tree
status = model.train(samples, responses)
status = model.train(csvFilename, [])
[...] = model.train(..., 'OptionName', optionValue, ...)
Input
- samples Row vectors of feature.
- responses Output of the corresponding feature vectors.
- csvFilename The input CSV file name from which to load
dataset. In this variant, you should set the second argument
to an empty array.
Output
Options
- Data Training data options, specified as a cell array of
key/value pairs of the form
{'key',val, ...}
. See below.
- Flags The optional training flags, model-dependent.
Not used. default 0
Options for Data
(first variant with samples and reponses)
- Layout Sample types. Default 'Row'. One of:
- Row each training sample is a row of samples.
- Col each training sample occupies a column of samples.
- VarIdx vector specifying which variables to use for
training. It can be an integer vector (
int32
) containing
0-based variable indices or logical vector (uint8
or
logical
) containing a mask of active variables. Not set by
default, which uses all variables in the input data.
- SampleIdx vector specifying which samples to use for
training. It can be an integer vector (
int32
) containing
0-based sample indices or logical vector (uint8
or
logical
) containing a mask of training samples of interest.
Not set by default, which uses all samples in the input data.
- SampleWeights optional floating-point vector with weights
for each sample. Some samples may be more important than
others for training. You may want to raise the weight of
certain classes to find the right balance between hit-rate and
false-alarm rate, and so on. Not set by default, which
effectively assigns an equal weight of 1 for all samples.
- VarType optional vector of type
uint8
and size
<num_of_vars_in_samples> + <num_of_vars_in_responses>
,
containing types of each input and output variable. By default
considers all variables as numerical (both input and output
variables). In case there is only one output variable of
integer type, it is considered categorical. You can also
specify a cell-array of strings (or as one string of single
characters, e.g 'NNNC'). Possible values:
- Numerical, N same as 'Ordered'
- Ordered, O ordered variables
- Categorical, C categorical variables
- MissingMask Indicator mask for missing observation (not
currently implemented). Not set by default
- TrainTestSplitCount divides the dataset into train/test
sets, by specifying number of samples to use for the test set.
By default all samples are used for the training set.
- TrainTestSplitRatio divides the dataset into train/test
sets, by specifying ratio of samples to use for the test set.
By default all samples are used for the training set.
- TrainTestSplitShuffle when splitting dataset into
train/test sets, specify whether to shuffle the samples.
Otherwise samples are assigned sequentially (first train then
test). default true
Options for Data
(second variant for loading CSV file)
- HeaderLineCount The number of lines in the beginning to
skip; besides the header, the function also skips empty lines
and lines staring with '#'. default 1
- ResponseStartIdx Index of the first output variable. If
-1, the function considers the last variable as the response.
If the dataset only contains input variables and no responses,
use
ResponseStartIdx = -2
and ResponseEndIdx = 0
, then the
output variables vector will just contain zeros. default -1
- ResponseEndIdx Index of the last output variable + 1. If
-1, then there is single response variable at
ResponseStartIdx
. default -1
- VarTypeSpec The optional text string that specifies the
variables' types. It has the format
ord[n1-n2,n3,n4-n5,...]cat[n6,n7-n8,...]
. That is, variables
from n1
to n2
(inclusive range), n3
, n4
to n5
...
are considered ordered and n6
, n7
to n8
... are
considered as categorical. The range
[n1..n2] + [n3] + [n4..n5] + ... + [n6] + [n7..n8]
should
cover all the variables. If VarTypeSpec
is not specified,
then algorithm uses the following rules:
- all input variables are considered ordered by default. If
some column contains has non- numerical values, e.g.
'apple', 'pear', 'apple', 'apple', 'mango', the
corresponding variable is considered categorical.
- if there are several output variables, they are all
considered as ordered. Errors are reported when
non-numerical values are used.
- if there is a single output variable, then if its values are
non-numerical or are all integers, then it's considered
categorical. Otherwise, it's considered ordered.
- Delimiter The character used to separate values in each
line. default ','
- Missing The character used to specify missing
measurements. It should not be a digit. Although it's a
non-numerical value, it surely does not affect the decision of
whether the variable ordered or categorical. default '?'
- TrainTestSplitCount same as above.
- TrainTestSplitRatio same as above.
- TrainTestSplitShuffle same as above.
The method trains the cv.DTrees model.
The method follow the generic train conventions. Both data
layouts ('Row' and 'Col') are supported, as well as sample and
variable subsets, missing measurements, arbitrary combinations
of input and output variable types, and so on.
Depending on the responses
data type (or the specified
VarType
for the response), the method solves a classification
problem for categorical labels, otherwise the training is
treated as a regression problem for numerical responses.
The function is parallelized with the TBB library.