Quick Start
Let's demonstrate basic use of Shark with very few lines of code.
This is C++, so we start with includes.
#include <shark/Data/Download.h>
#include <shark/Algorithms/Trainers/LDA.h>
#include <shark/ObjectiveFunctions/Loss/ZeroOneLoss.h>
using namespace shark;
Let's load some data for learning.
ClassificationDataset traindata;
downloadCsvData(traindata,
"https://raw.githubusercontent.com/Shark-ML/Shark/master/docs/data/quickstart-train.csv",
LAST_COLUMN,
' ');
The next step is to create a predictive model. Here we use a simple linear classifier.
LinearClassifier<> classifier;
The core step of learning is to train the model on data using a trainer.
In Shark, the trainer is not glued to the model. Instead it is a separate object.
Here, good old Linear Discriminant Analysis (LDA) suits our needs.
LDA lda;
lda.train(classifier, traindata);
Congrats! We have a readily trained classifier.
Let's try it out by applying it to new data.
ClassificationDataset testdata;
downloadCsvData(testdata,
"https://raw.githubusercontent.com/Shark-ML/Shark/master/docs/data/quickstart-test.csv",
LAST_COLUMN,
' ');
ZeroOneLoss<> loss;
double error = loss(testdata.labels(), classifier(testdata.inputs()));
Further reading: