quickstartTutorial.cpp
Go to the documentation of this file.
1 #include <shark/Data/Csv.h>
4 using namespace shark;
5 
6 
7 #include <iostream>
8 using namespace std;
9 
10 
11 int 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  double error = loss(test.labels(),classifier(test.inputs()));
38 
39  //print results
40  cout << "RESULTS: " << endl;
41  cout << "========\n" << endl;
42  cout << "test data size: " << test.numberOfElements() << endl;
43  cout << "error rate: " << error << endl;
44 }