{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
\n",
"
\n",
"\n",
"# DataLoader Example"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Declare Factory"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"TMVA::Tools::Instance();\n",
"\n",
"auto inputFile = TFile::Open(\"https://raw.githubusercontent.com/iml-wg/tmvatutorials/master/inputdata.root\");\n",
"auto outputFile = TFile::Open(\"TMVAOutputCV.root\", \"RECREATE\");\n",
"\n",
"TMVA::Factory factory(\"TMVAClassification\", outputFile,\n",
" \"!V:ROC:!Correlations:!Silent:Color:!DrawProgressBar:AnalysisType=Classification\" ); "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Declare DataLoader(s)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"TMVA::DataLoader loader(\"dataset\");\n",
"\n",
"loader.AddVariable(\"var1\");\n",
"loader.AddVariable(\"var2\");\n",
"loader.AddVariable(\"var3\");"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup Dataset(s)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"TTree *tsignal, *tbackground;\n",
"inputFile->GetObject(\"Sig\", tsignal);\n",
"inputFile->GetObject(\"Bkg\", tbackground);\n",
"\n",
"TCut mycuts, mycutb;\n",
"\n",
"loader.AddSignalTree (tsignal, 1.0); //signal weight = 1\n",
"loader.AddBackgroundTree(tbackground, 1.0); //background weight = 1 \n",
"loader.PrepareTrainingAndTestTree(mycuts, mycutb,\n",
" \"nTrain_Signal=1000:nTrain_Background=1000:SplitMode=Random:NormMode=NumEvents:!V\" ); \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Booking Methods"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## First dataset"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"//Boosted Decision Trees\n",
"factory.BookMethod(&loader,TMVA::Types::kBDT, \"BDT\",\n",
" \"!V:NTrees=200:MinNodeSize=2.5%:MaxDepth=2:BoostType=AdaBoost:AdaBoostBeta=0.5:UseBaggedBoost:BaggedSampleFraction=0.5:SeparationType=GiniIndex:nCuts=20\" );\n",
"\n",
"//Multi-Layer Perceptron (Neural Network)\n",
"factory.BookMethod(&loader, TMVA::Types::kMLP, \"MLP\",\n",
" \"!H:!V:NeuronType=tanh:VarTransform=N:NCycles=100:HiddenLayers=N+5:TestRate=5:!UseRegulator\" );"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Train Methods"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"factory.TrainAllMethods();"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test and Evaluate Methods"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"factory.TestAllMethods();\n",
"factory.EvaluateAllMethods(); "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot ROC Curve\n",
"We enable JavaScript visualisation for the plots"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%jsroot on"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"auto c1 = factory.GetROCCurve(&loader);\n",
"c1->Draw();\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ROOT C++",
"language": "c++",
"name": "root"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".C",
"mimetype": " text/x-c++src",
"name": "c++"
}
},
"nbformat": 4,
"nbformat_minor": 1
}