#include "daal.h"
#include "service.h"
using namespace std;
using namespace daal;
using namespace daal::algorithms;
string trainDatasetFileName = "../data/batch/adaboost_train.csv";
string testDatasetFileName = "../data/batch/adaboost_test.csv";
const size_t nFeatures = 20;
services::SharedPtr<adaboost::training::Result> trainingResult;
services::SharedPtr<classifier::prediction::Result> predictionResult;
services::SharedPtr<NumericTable> testGroundTruth;
void trainModel();
void testModel();
void printResults();
int main(int argc, char *argv[])
{
checkArguments(argc, argv, 2, &trainDatasetFileName, &testDatasetFileName);
trainModel();
testModel();
printResults();
return 0;
}
void trainModel()
{
FileDataSource<CSVFeatureManager> trainDataSource(trainDatasetFileName,
DataSource::notAllocateNumericTable,
DataSource::doDictionaryFromContext);
services::SharedPtr<NumericTable> trainData(new HomogenNumericTable<double>(nFeatures, 0, NumericTable::notAllocate));
services::SharedPtr<NumericTable> trainGroundTruth(new HomogenNumericTable<double>(1, 0, NumericTable::notAllocate));
services::SharedPtr<NumericTable> mergedData(new MergedNumericTable(trainData, trainGroundTruth));
trainDataSource.loadDataBlock(mergedData.get());
adaboost::training::Batch<> algorithm;
algorithm.input.set(classifier::training::data, trainData);
algorithm.input.set(classifier::training::labels, trainGroundTruth);
algorithm.compute();
trainingResult = algorithm.getResult();
}
void testModel()
{
FileDataSource<CSVFeatureManager> testDataSource(testDatasetFileName,
DataSource::notAllocateNumericTable,
DataSource::doDictionaryFromContext);
services::SharedPtr<NumericTable> testData(new HomogenNumericTable<double>(nFeatures, 0, NumericTable::notAllocate));
testGroundTruth = services::SharedPtr<NumericTable>(new HomogenNumericTable<double>(1, 0, NumericTable::notAllocate));
services::SharedPtr<NumericTable> mergedData(new MergedNumericTable(testData, testGroundTruth));
testDataSource.loadDataBlock(mergedData.get());
adaboost::prediction::Batch<> algorithm;
algorithm.input.set(classifier::prediction::data, testData);
algorithm.input.set(classifier::prediction::model, trainingResult->get(classifier::training::model));
algorithm.compute();
predictionResult = algorithm.getResult();
}
void printResults()
{
printNumericTables<int, int>(testGroundTruth,
predictionResult->get(classifier::prediction::prediction),
"Ground truth", "Classification results",
"AdaBoost classification results (first 20 observations):", 20);
}