Shark machine learning library
Installation
Tutorials
Benchmarks
Documentation
Quick references
Class list
Global functions
examples
Benchmark
shark
random_forrest.cpp
Go to the documentation of this file.
1
#include <iostream>
2
#include <
shark/Data/SparseData.h
>
3
#include <
shark/ObjectiveFunctions/Loss/ZeroOneLoss.h
>
4
#include <
shark/ObjectiveFunctions/Loss/SquaredLoss.h
>
5
#include <
shark/Algorithms/Trainers/RFTrainer.h
>
6
#include <
shark/Models/Kernels/GaussianRbfKernel.h
>
7
8
#include <
shark/Core/Timer.h
>
9
10
using namespace
shark
;
11
using namespace
std;
12
13
int
main
(
int
argc,
char
**argv) {
14
LabeledData<RealVector,unsigned int>
data;
15
importSparseData
(data,
"covtype"
);
16
data.
shuffle
();
17
ClassificationDataset
test =
splitAtElement
(data,400000);
18
19
RFClassifier<unsigned int>
model;
20
RFTrainer<unsigned int>
trainer(
true
,
true
);
21
22
Timer
time;
23
trainer.train(model, data);
24
double
time_taken = time.
stop
();
25
26
ZeroOneLoss<>
loss;
27
cout << time_taken <<
" "
<< 1.0 - loss(data.
labels
(),model(data.
inputs
()))<<
" "
<< 1.0 - loss(test.
labels
(),model(test.
inputs
()))<<std::endl;
28
}