VersatileClassificationTutorial-RF.cpp
Go to the documentation of this file.
1 
2 #include <shark/Data/Dataset.h>
3 #include <shark/Data/Csv.h>
5 
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 
24 
25  trainer.train(model, traindata);
26 
27  auto prediction = model(testdata.inputs());
28 
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 }