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-LDA.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/LinearClassifier.h
>
7
#include <
shark/Algorithms/Trainers/LDA.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
// TODO: define a model and a trainer
23
24
LinearClassifier<>
model;
25
LDA
trainer;
26
27
trainer.
train
(model, traindata);
28
29
Data<unsigned int>
prediction = model(testdata.
inputs
());
30
31
ZeroOneLoss<unsigned int>
loss;
32
double
error_rate = loss(testdata.
labels
(), prediction);
33
34
std::cout <<
"model: "
<< model.
name
() << std::endl
35
<<
"trainer: "
<< trainer.
name
() << std::endl
36
<<
"test error rate: "
<< error_rate << std::endl;
37
}
38
//