Download Machine Learning

Transcript
and load(), which essentially wrap the more complex write() and read() functions into
an interface that writes and reads XML and YAML to and from disk. Beyond that, for
learning from data the two most important functions, predict() and train(), vary by
algorithm and will be discussed next.
Table 13-3. Base class methods for the machine learning (ML) library
CvStatModel:: Methods
Description
save(
const char* filename,
const char* name
= 0
)
Saves learned model in XML or YMAL. Use this method
for storage.
load(
const char* filename,
const char* name=0
);
Calls clear() and then loads XML or YMAL model. Use
this method for recall.
clear()
De-allocates all memory. Ready for reuse.
bool train(
—data points—,
[flags]
—responses—,
[flags etc]
) ;
The training function to learn a model of the dataset.
Training is specific to the algorithm and so the input
parameters will vary.
float predict(
const CvMat* sample
[,<prediction_params>]
) const;
After training, use this function to predict the label or
value of a new training point or points.
Constructor, Destructor:
CvStatModel();
CvStatModel(
const CvMat* train_data ...
);
Default constructor and constructor that allows creation
and training of the model in one shot.
CvStatModel::~CvStatModel();
The destructor of the ML model.
Write/Read support (but use save/load above instead):
write(
CvFileStorage* storage,
const char*
name
);
Generic CvFileStorage structured write to disk,
located in the cvcore library (discussed in Chapter 3) and
called by save().
read(
CvFileStorage* storage,
CvFileNode*
node
);
Generic file read to CvFileStorage structure, located
in the cvcore library and called by load().
Training
The training prototype is as follows:
bool CvStatModel::train(
const CvMat* train_data,
[int tflag,]
const CvMat* responses,
472
|
Chapter 13: Machine Learning
...,
...,