From 53de3a23ea9226947d7633803d3a367fc32f46d2 Mon Sep 17 00:00:00 2001 From: Noel Dawe Date: Tue, 29 Nov 2016 09:35:10 +1100 Subject: [PATCH] update TMVA examples to use new DataLoader interface --- examples/tmva/plot_multiclass.py | 12 +++++++----- examples/tmva/plot_regression.py | 16 +++++++++------- examples/tmva/plot_twoclass.py | 11 ++++++----- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/examples/tmva/plot_multiclass.py b/examples/tmva/plot_multiclass.py index 319c603..c8fde5c 100644 --- a/examples/tmva/plot_multiclass.py +++ b/examples/tmva/plot_multiclass.py @@ -38,17 +38,19 @@ factory = TMVA.Factory('classifier', output, 'AnalysisType=Multiclass:' '!V:Silent:!DrawProgressBar') + +data = TMVA.DataLoader('.') for n in range(2): - factory.AddVariable('f{0}'.format(n), 'F') + data.AddVariable('f{0}'.format(n), 'F') # Call root_numpy's utility functions to add events from the arrays -add_classification_events(factory, X_train, y_train, weights=w_train) -add_classification_events(factory, X_test, y_test, weights=w_test, test=True) +add_classification_events(data, X_train, y_train, weights=w_train) +add_classification_events(data, X_test, y_test, weights=w_test, test=True) # The following line is necessary if events have been added individually: -factory.PrepareTrainingAndTestTree(TCut('1'), 'NormMode=EqualNumEvents') +data.PrepareTrainingAndTestTree(TCut('1'), 'NormMode=EqualNumEvents') # Train an MLP -factory.BookMethod('MLP', 'MLP', +factory.BookMethod(data, 'MLP', 'MLP', 'NeuronType=tanh:NCycles=200:HiddenLayers=N+2,2:' 'TestRate=5:EstimatorType=MSE') factory.TrainAllMethods() diff --git a/examples/tmva/plot_regression.py b/examples/tmva/plot_regression.py index 2007070..327b1e7 100644 --- a/examples/tmva/plot_regression.py +++ b/examples/tmva/plot_regression.py @@ -23,18 +23,20 @@ factory = TMVA.Factory('regressor', output, 'AnalysisType=Regression:' '!V:Silent:!DrawProgressBar') -factory.AddVariable('x', 'F') -factory.AddTarget('y', 'F') -add_regression_events(factory, X, y) -add_regression_events(factory, X, y, test=True) +data = TMVA.DataLoader('.') +data.AddVariable('x', 'F') +data.AddTarget('y', 'F') + +add_regression_events(data, X, y) +add_regression_events(data, X, y, test=True) # The following line is necessary if events have been added individually: -factory.PrepareTrainingAndTestTree(TCut('1'), '') +data.PrepareTrainingAndTestTree(TCut('1'), '') -factory.BookMethod('BDT', 'BDT1', +factory.BookMethod(data, 'BDT', 'BDT1', 'nCuts=20:NTrees=1:MaxDepth=4:BoostType=AdaBoostR2:' 'SeparationType=RegressionVariance') -factory.BookMethod('BDT', 'BDT2', +factory.BookMethod(data, 'BDT', 'BDT2', 'nCuts=20:NTrees=300:MaxDepth=4:BoostType=AdaBoostR2:' 'SeparationType=RegressionVariance') factory.TrainAllMethods() diff --git a/examples/tmva/plot_twoclass.py b/examples/tmva/plot_twoclass.py index d92059d..3a006e2 100644 --- a/examples/tmva/plot_twoclass.py +++ b/examples/tmva/plot_twoclass.py @@ -36,17 +36,18 @@ factory = TMVA.Factory('classifier', output, 'AnalysisType=Classification:' '!V:Silent:!DrawProgressBar') +data = TMVA.DataLoader('.') for n in range(n_vars): - factory.AddVariable('f{0}'.format(n), 'F') + data.AddVariable('f{0}'.format(n), 'F') # Call root_numpy's utility functions to add events from the arrays -add_classification_events(factory, X_train, y_train, weights=w_train) -add_classification_events(factory, X_test, y_test, weights=w_test, test=True) +add_classification_events(data, X_train, y_train, weights=w_train) +add_classification_events(data, X_test, y_test, weights=w_test, test=True) # The following line is necessary if events have been added individually: -factory.PrepareTrainingAndTestTree(TCut('1'), 'NormMode=EqualNumEvents') +data.PrepareTrainingAndTestTree(TCut('1'), 'NormMode=EqualNumEvents') # Train a classifier -factory.BookMethod('Fisher', 'Fisher', +factory.BookMethod(data, 'Fisher', 'Fisher', 'Fisher:VarTransform=None:CreateMVAPdfs:' 'PDFInterpolMVAPdf=Spline2:NbinsMVAPdf=50:' 'NsmoothMVAPdf=10')