def cross_validate(self, nfolds, outputfile): '''Run cross validation with the given number of folds.''' crossval = TMVA.CrossValidation(self.dataloader.dataloader) crossval.SetNumFolds(nfolds) methods = self.book_methods(crossval, self.dataloader.dataloader) crossval.Evaluate() results = crossval.GetResults() return crossval, results
signal = f1.Get('NOMINAL') background = f2.Get('NOMINAL') # In[5]: loader.AddSignalTree(signal, 1.0) loader.AddBackgroundTree(background, 1.0) loader.PrepareTrainingAndTestTree( TCut(""), "nTrain_Signal=86203 :nTrain_Background=412573 :SplitMode=Random:NormMode=NumEvents:!V" ) # In[6]: cv = TMVA.CrossValidation( "TMVACrossValidation", loader, outputFile, "!V:!Silent:ModelPersistence:AnalysisType=Classification:NumFolds=3:SplitExpr=" ) # In[7]: cv.BookMethod( TMVA.Types.kMLP, "MLP", "H:!V:NeuronType=tanh:VarTransform=N:NCycles=600:HiddenLayers=N+1:TestRate=5:!UseRegulator" ) # In[8]: cv.Evaluate() # In[9]: