22#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
23#include <numpy/arrayobject.h>
70 fMinWeightFractionLeaf(0),
71 fMaxFeatures("'sqrt'"),
72 fMaxLeafNodes("None"),
91 fMinWeightFractionLeaf(0),
92 fMaxFeatures(
"'sqrt'"),
93 fMaxLeafNodes(
"None"),
125 The function to measure the quality of a split. Supported criteria are \
126 'gini' for the Gini impurity and 'entropy' for the information gain. \
127 Note: this parameter is tree-specific.");
130 The maximum depth of the tree. If None, then nodes are expanded until \
131 all leaves are pure or until all leaves contain less than \
132 min_samples_split samples. \
133 Ignored if ``max_leaf_nodes`` is not None.");
136 The minimum number of samples required to split an internal node.");
139 The minimum number of samples in newly created leaves. A split is \
140 discarded if after the split, one of the leaves would contain less then \
141 ``min_samples_leaf`` samples.");
143 The minimum weighted fraction of the input samples required to be at a \
148 Grow trees with ``max_leaf_nodes`` in best-first fashion.\
149 Best nodes are defined as relative reduction in impurity.\
150 If None then unlimited number of leaf nodes.\
151 If not None then ``max_depth`` will be ignored.");
154 Whether bootstrap samples are used when building trees.");
157 the generalization error.");
160 The number of jobs to run in parallel for both `fit` and `predict`. \
161 If -1, then the number of jobs is set to the number of cores.");
164 If int, random_state is the seed used by the random number generator;\
165 If RandomState instance, random_state is the random number generator;\
166 If None, the random number generator is the RandomState instance used\
170 Controls the verbosity of the tree building process.");
173 When set to ``True``, reuse the solution of the previous call to fit\
174 and add more estimators to the ensemble, otherwise, just fit a whole\
178 Weights associated with classes in the form ``{class_label: weight}``.\
179 If not given, all classes are supposed to have weight one. For\
180 multi-output problems, a list of dicts can be provided in the same\
181 order as the columns of y.\
182 The \"auto\" mode uses the values of y to automatically adjust\
183 weights inversely proportional to class frequencies in the input data.\
184 The \"subsample\" mode is the same as \"auto\" except that weights are\
185 computed based on the bootstrap sample for every tree grown.\
186 For multi-output, the weights of each column of y will be multiplied.\
187 Note that these weights will be multiplied with sample_weight (passed\
188 through the fit method) if sample_weight is specified.");
191 "Store trained classifier in this file");
199 Log() << kFATAL <<
" NEstimators <=0... that does not work !! " <<
Endl;
206 <<
" The options are `gini` or `entropy`." <<
Endl;
215 <<
" The options are None or integer." <<
Endl;
219 Log() << kFATAL <<
" MinSamplesSplit < 0... that does not work !! " <<
Endl;
225 Log() << kFATAL <<
" MinSamplesLeaf < 0... that does not work !! " <<
Endl;
231 Log() << kERROR <<
" MinWeightFractionLeaf < 0... that does not work !! " <<
Endl;
245 <<
"int, float, string or None, optional (default='auto')"
246 <<
"The number of features to consider when looking for the best split:"
247 <<
"If int, then consider `max_features` features at each split."
248 <<
"If float, then `max_features` is a percentage and"
249 <<
"`int(max_features * n_features)` features are considered at each split."
250 <<
"If 'auto', then `max_features=sqrt(n_features)`."
251 <<
"If 'sqrt', then `max_features=sqrt(n_features)`."
252 <<
"If 'log2', then `max_features=log2(n_features)`."
253 <<
"If None, then `max_features=n_features`." <<
Endl;
259 <<
" The options are None or integer." <<
Endl;
266 <<
"If int, random_state is the seed used by the random number generator;"
267 <<
"If RandomState instance, random_state is the random number generator;"
268 <<
"If None, the random number generator is the RandomState instance used by `np.random`." <<
Endl;
275 <<
"dict, list of dicts, 'auto', 'subsample' or None, optional" <<
Endl;
280 Log() << kFATAL <<
Form(
" NJobs = %i... that does not work !! ",
fNjobs)
281 <<
"Value has to be greater than zero." <<
Endl;
355 PyRunString(
"classifier = sklearn.ensemble.RandomForestClassifier(bootstrap=bootstrap, class_weight=classWeight, criterion=criterion, max_depth=maxDepth, max_features=maxFeatures, max_leaf_nodes=maxLeafNodes, min_samples_leaf=minSamplesLeaf, min_samples_split=minSamplesSplit, min_weight_fraction_leaf=minWeightFractionLeaf, n_estimators=nEstimators, n_jobs=nJobs, oob_score=oobScore, random_state=randomState, verbose=verbose, warm_start=warmStart)",
356 "Failed to setup classifier");
360 PyRunString(
"dump = classifier.fit(trainData, trainDataClasses, trainDataWeights)",
"Failed to train classifier");
365 Log() << kFATAL <<
"Can't create classifier object from RandomForestClassifier" <<
Endl;
402 <<
" sample (" << nEvents <<
" events)" <<
Endl;
425 for (
int i = 0; i < nEvents; ++i) {
434 <<
"Elapsed time for evaluation of " << nEvents <<
" events: "
435 <<
timer.GetElapsedTime() <<
" " <<
Endl;
535 if(
pRanking == 0)
Log() << kFATAL <<
"Failed to get ranking from classifier" <<
Endl;
554 Log() <<
"A random forest is a meta estimator that fits a number of decision" <<
Endl;
555 Log() <<
"tree classifiers on various sub-samples of the dataset and use" <<
Endl;
556 Log() <<
"averaging to improve the predictive accuracy and control over-fitting." <<
Endl;
558 Log() <<
"Check out the scikit-learn documentation for more information." <<
Endl;
#define REGISTER_METHOD(CLASS)
for example
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
long long Long64_t
Portable signed long integer 8 bytes.
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
OptionBase * DeclareOptionRef(T &ref, const TString &name, const TString &desc="")
Class that contains all the data information.
UInt_t GetNClasses() const
const Event * GetEvent() const
returns event without transformations
Types::ETreeType GetCurrentType() const
Long64_t GetNEvents(Types::ETreeType type=Types::kMaxTreeType) const
Long64_t GetNTrainingEvents() const
void SetCurrentEvent(Long64_t ievt) const
const Event * GetTrainingEvent(Long64_t ievt) const
PyGILState_STATE m_GILState
const char * GetName() const override
virtual void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility they are hence without any...
Bool_t IsModelPersistence() const
const TString & GetWeightFileDir() const
const TString & GetMethodName() const
DataSetInfo & DataInfo() const
virtual void TestClassification()
initialization
UInt_t GetNVariables() const
void NoErrorCalc(Double_t *const err, Double_t *const errUpper)
const TString & GetInputLabel(Int_t i) const
PyObject * pMinWeightFractionLeaf
Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets) override
void DeclareOptions() override
MethodPyRandomForest(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="")
std::vector< Double_t > GetMvaValues(Long64_t firstEvt=0, Long64_t lastEvt=-1, Bool_t logProgress=false) override
get all the MVA values for the events of the current Data type
std::vector< Float_t > & GetMulticlassValues() override
~MethodPyRandomForest(void)
std::vector< Float_t > classValues
PyObject * pMinSamplesLeaf
TString fFilenameClassifier
std::vector< Double_t > mvaValues
void GetHelpMessage() const override
void TestClassification() override
initialization
const Ranking * CreateRanking() override
Double_t fMinWeightFractionLeaf
Double_t GetMvaValue(Double_t *errLower=nullptr, Double_t *errUpper=nullptr) override
void ReadModelFromFile() override
void ProcessOptions() override
PyObject * pMinSamplesSplit
Virtual base class for all TMVA method based on Python.
static int PyIsInitialized()
Check Python interpreter initialization status.
PyObject * Eval(TString code)
Evaluate Python code.
static void PyInitialize()
Initialize Python interpreter.
static void Serialize(TString file, PyObject *classifier)
Serialize Python object.
static Int_t UnSerialize(TString file, PyObject **obj)
Unserialize Python object.
void PyRunString(TString code, TString errorMessage="Failed to run python code", int start=256)
Execute Python code from string.
Ranking for variables in method (implementation)
virtual void AddRank(const Rank &rank)
Add a new rank take ownership of it.
Timing information for training and evaluation of MVA methods.
Singleton class for Global types used by TMVA.
@ kSignal
Never change this number - it is elsewhere assumed to be zero !
const char * Data() const
create variable transformations
MsgLogger & Endl(MsgLogger &ml)