This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
mva:mva [2016/08/06 11:58] – Simple example iwn | mva:mva [2023/06/01 13:29] (current) – [Other information] iwn | ||
---|---|---|---|
Line 1: | Line 1: | ||
| | ||
- | **TMVA** is a tool to run a multivariate analysis | + | **TMVA** is a tool to run a multivariate analysis in ROOT. Among many other methods, it includes boosted decision tree (BDT) and neural network (MLP). More information can be found at: |
* [[http:// | * [[http:// | ||
Line 7: | Line 7: | ||
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
- | When using the neural netwerk method MLP, you might need ROOT 34.0.0 or newer, to have larger buffer for the xml reader, for example: | + | When using the neural netwerk method MLP, you might need ROOT 5.34.0.0 or newer, to have larger buffer for the xml reader, for example: |
- | < | + | < |
. / | . / | ||
</ | </ | ||
- | + | ===== Training | |
- | ===== Simple example | + | |
To run the MVA in python on a signal tree '' | To run the MVA in python on a signal tree '' | ||
- | < | + | < |
- | from ROOT import TFile, TMVA, TCut | + | from ROOT import TFile, TTree, TMVA, TCut |
f_out = TFile(" | f_out = TFile(" | ||
TMVA.Tools.Instance() | TMVA.Tools.Instance() | ||
Line 33: | Line 34: | ||
</ | </ | ||
- | In the empty quote marks you can add cuts or options. More information on can be found on the [[https:// | + | In the empty quote marks you can add cuts or options. More information on can be found in section 3.1 in the [[http:// |
- | Then you can book multiple methods like the BDT and MLP: | + | Then you can book multiple methods like the BDT and MLP for different parameters: |
- | < | + | < |
factory.BookMethod( TMVA.Types.kBDT, | factory.BookMethod( TMVA.Types.kBDT, | ||
factory.BookMethod( TMVA.Types.kBDT, | factory.BookMethod( TMVA.Types.kBDT, | ||
Line 49: | Line 50: | ||
Finally train, test and evaluate all the booked methods: | Finally train, test and evaluate all the booked methods: | ||
- | < | + | < |
factory.TrainAllMethods() | factory.TrainAllMethods() | ||
factory.TestAllMethods() | factory.TestAllMethods() | ||
factory.EvaluateAllMethods() | factory.EvaluateAllMethods() | ||
f_out.Close() | f_out.Close() | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Applying the output to a tree ===== | ||
+ | |||
+ | The factory will output weights in a XML file you can use to apply to a tree that contains the same variable. | ||
+ | |||
+ | <code python> | ||
+ | reader = TMVA.Reader() | ||
+ | vars = [ ] | ||
+ | for name in config.varNames: | ||
+ | vars.append(array(' | ||
+ | reader.AddVariable(name, | ||
+ | reader.BookMVA(" | ||
+ | for i in range(len(config.varNames)): | ||
+ | tree.SetBranchAddress(config.varNames[i], | ||
+ | for evt in range(tree.GetEntries()): | ||
+ | tree.GetEntry(evt) | ||
+ | hist.Fill( reader.EvaluateMVA(method) ) | ||
</ | </ | ||
Line 60: | Line 80: | ||
===== Parameters to tune ===== | ===== Parameters to tune ===== | ||
- | The parameters and options of the MVA method can be optimized from the default settings for better a performance, | + | The parameters and options of the MVA method can be optimized from the default settings for better a performance, |
- | For the **BDT** important parameters are the the learning rate, number of boost steps and maximal tree depth: | + | In particular, for the **BDT**, important parameters are the the learning rate, number of boost steps and maximal tree depth: |
- | * '' | + | * '' |
* '' | * '' | ||
* '' | * '' | ||
* '' | * '' | ||
- | * '' | + | |
+ | | ||
Important **MLP** | Important **MLP** | ||
Line 76: | Line 97: | ||
* '' | * '' | ||
* '' | * '' | ||
- | * '' | + | * '' |
+ | * '' | ||
+ | ===== Tutorials and examples ===== | ||
- | ===== Tutorial | + | * [[https:// |
+ | * [[https:// | ||
+ | * [[mva: | ||
+ | * [[https:// | ||
- | | + | |
- | * [[https://aholzner.wordpress.com/2011/08/27/a-tmva-example-in-pyroot/|PyRoot example]] | + | ===== Other information ===== |
+ | |||
+ | | ||
+ | * [[https://arogozhnikov.github.io/2016/07/05/gradient_boosting_playground.html|Gradient Boosting Interactive Playground]] with interactive visuals | ||
+ | * TMVA BibTex reference: | ||
+ | <code latex> | ||
+ | @article{TMVA, | ||
+ | title = {TMVA: Toolkit for Multivariate Data Analysis}, | ||
+ | author | ||
+ | | ||
+ | von Toerne, Eckhard and Voss, Helge}, | ||
+ | journal | ||
+ | volume | ||
+ | year = {2007}, | ||
+ | month = {Mar}, | ||
+ | pages = {040}, | ||
+ | url = {http:// | ||
+ | reportNumber | ||
+ | eprint | ||
+ | archivePrefix = {arXiv}, | ||
+ | primaryClass | ||
+ | SLACcitation | ||
+ | } | ||
+ | </ |