Shark machine learning library
About Shark
News!
Contribute
Credits and copyright
Downloads
Getting Started
Installation
Using the docs
Documentation
Tutorials
Quick references
Class list
Global functions
FAQ
Showroom
obj-x86_64-linux-gnu
examples
Supervised
VersatileClassificationTutorial-RF.cpp
Go to the documentation of this file.
1
2
#include <
shark/Data/Dataset.h
>
3
#include <
shark/Data/Csv.h
>
4
#include <
shark/ObjectiveFunctions/Loss/ZeroOneLoss.h
>
5
6
#include <
shark/Models/Trees/RFClassifier.h
>
7
#include <
shark/Algorithms/Trainers/RFTrainer.h
>
8
9
10
using namespace
shark
;
11
12
int
main
()
13
{
14
// Load data, use 70% for training and 30% for testing.
15
// The path is hard coded; make sure to invoke the executable
16
// from a place where the data file can be found. It is located
17
// under [shark]/examples/Supervised/data.
18
ClassificationDataset
traindata, testdata;
19
importCSV
(traindata,
"data/quickstartData.csv"
,
LAST_COLUMN
,
' '
);
20
testdata =
splitAtElement
(traindata, 70 * traindata.
numberOfElements
() / 100);
21
22
RFClassifier
model;
23
RFTrainer
trainer;
24
25
trainer.
train
(model, traindata);
26
27
Data<RealVector>
prediction = model(testdata.
inputs
());
28
29
ZeroOneLoss<unsigned int, RealVector>
loss;
30
double
error_rate = loss(testdata.
labels
(), prediction);
31
32
std::cout <<
"model: "
<< model.
name
() << std::endl
33
<<
"trainer: "
<< trainer.
name
() << std::endl
34
<<
"test error rate: "
<< error_rate << std::endl;
35
}