quickstartTutorial.cpp
Go to the documentation of this file.
1#include <shark/Data/Csv.h>
4using namespace shark;
5
6
7#include <iostream>
8using namespace std;
9
10
11int main(int argc, char **argv){
12 //create a Dataset from the file "quickstartData"
13 if(argc < 2) {
14 cerr << "usage: " << argv[0] << " (filename)" << endl;
15 exit(EXIT_FAILURE);
16 }
18 try {
19 importCSV(data, argv[1], LAST_COLUMN, ' ');
20 }
21 catch (...) {
22 cerr << "unable to read data from file " << argv[1] << endl;
23 exit(EXIT_FAILURE);
24 }
25
26 //create a test and training partition of the data
27 ClassificationDataset test = splitAtElement(data,static_cast<std::size_t>(0.8*data.numberOfElements()));
28
29 //create a classifier for the problem
30 LinearClassifier<> classifier;
31 //create the lda trainer
32 LDA lda;
33 //train the classifier using the training portion of the Data
34 lda.train(classifier,data);
35
36 ZeroOneLoss<> loss;
37 Data<unsigned int> predictions = classifier(test.inputs());
38 double error = loss(test.labels(),predictions);
39
40 //print results
41 cout << "RESULTS: " << endl;
42 cout << "========\n" << endl;
43 cout << "test data size: " << test.numberOfElements() << endl;
44 cout << "error rate: " << error << endl;
45}