Logo ROOT   6.08/07
Reference Guide
MethodPyGTB.h
Go to the documentation of this file.
1 // @(#)root/tmva/pymva $Id$
2 // Authors: Omar Zapata, Lorenzo Moneta, Sergei Gleyzer 2015
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : MethodPyGTB *
8  * Web : http://oproject.org *
9  * *
10  * Description: *
11  * scikit-learn Package GradientBoostingClassifier method based on python *
12  * *
13  **********************************************************************************/
14 
15 #ifndef ROOT_TMVA_MethodPyGTB
16 #define ROOT_TMVA_MethodPyGTB
17 
18 //////////////////////////////////////////////////////////////////////////
19 // //
20 // MethodPyGTB //
21 // //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #ifndef ROOT_TMVA_PyMethodBase
26 #include "TMVA/PyMethodBase.h"
27 #endif
28 
29 namespace TMVA {
30 
31  class Factory; // DSMTEST
32  class Reader; // DSMTEST
33  class DataSetManager; // DSMTEST
34  class Types;
35  class MethodPyGTB : public PyMethodBase {
36 
37  public :
38 
39  // constructors
40  MethodPyGTB(const TString &jobName,
41  const TString &methodTitle,
42  DataSetInfo &theData,
43  const TString &theOption = "");
44 
46  const TString &theWeightFile);
47 
48 
49  ~MethodPyGTB(void);
50  void Train();
51  // options treatment
52  void Init();
53  void DeclareOptions();
54  void ProcessOptions();
55  // create ranking
57  {
58  return NULL; // = 0;
59  }
60 
61 
62  Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets);
63 
64  // performs classifier testing
65  virtual void TestClassification();
66 
67 
68  Double_t GetMvaValue(Double_t *errLower = 0, Double_t *errUpper = 0);
69 
70  virtual void ReadModelFromFile();
71 
73  // the actual "weights"
74  virtual void AddWeightsXMLTo(void * /* parent */ ) const {} // = 0;
75  virtual void ReadWeightsFromXML(void * /*wghtnode*/) {} // = 0;
76  virtual void ReadWeightsFromStream(std::istream &) {} //= 0; // backward compatibility
77  private :
78 
79 
81  friend class Factory; // DSMTEST
82  friend class Reader; // DSMTEST
83  protected:
84 
85  //GTB options
86  TString loss;// {'deviance', 'exponential'}, optional (default='deviance')
87  //loss function to be optimized. 'deviance' refers to
88  //deviance (= logistic regression) for classification
89  //with probabilistic outputs. For loss 'exponential' gradient
90  //boosting recovers the AdaBoost algorithm.
91  Double_t learning_rate;//float, optional (default=0.1)
92  //learning rate shrinks the contribution of each tree by `learning_rate`.
93  //There is a trade-off between learning_rate and n_estimators.
94 
95  Int_t n_estimators;//integer, optional (default=10)
96  //The number of trees in the forest.
97  Double_t subsample;//float, optional (default=1.0)
98  //The fraction of samples to be used for fitting the individual base
99  //learners. If smaller than 1.0 this results in Stochastic Gradient
100  //Boosting. `subsample` interacts with the parameter `n_estimators`.
101  //Choosing `subsample < 1.0` leads to a reduction of variance
102  //and an increase in bias.
103  Int_t min_samples_split;// integer, optional (default=2)
104  //The minimum number of samples required to split an internal node.
105  Int_t min_samples_leaf;//integer, optional (default=1)
106  //The minimum number of samples required to be at a leaf node.
107  Double_t min_weight_fraction_leaf;//float, optional (default=0.)
108  //The minimum weighted fraction of the input samples required to be at a leaf node.
109  Int_t max_depth;//integer, optional (default=3)
110  //maximum depth of the individual regression estimators. The maximum
111  //depth limits the number of nodes in the tree. Tune this parameter
112  //for best performance; the best value depends on the interaction
113  //of the input variables.
114  //Ignored if ``max_leaf_nodes`` is not None.
115 
116  TString init;//BaseEstimator, None, optional (default=None)
117  //An estimator object that is used to compute the initial
118  //predictions. ``init`` has to provide ``fit`` and ``predict``.
119  //If None it uses ``loss.init_estimator``.
120  TString random_state;//int, RandomState instance or None, optional (default=None)
121  //If int, random_state is the seed used by the random number generator;
122  //If RandomState instance, random_state is the random number generator;
123  //If None, the random number generator is the RandomState instance used
124  //by `np.random`.
125  TString max_features;//int, float, string or None, optional (default="auto")
126  //The number of features to consider when looking for the best split:
127  //- If int, then consider `max_features` features at each split.
128  //- If float, then `max_features` is a percentage and
129  //`int(max_features * n_features)` features are considered at each split.
130  //- If "auto", then `max_features=sqrt(n_features)`.
131  //- If "sqrt", then `max_features=sqrt(n_features)`.
132  //- If "log2", then `max_features=log2(n_features)`.
133  //- If None, then `max_features=n_features`.
134  // Note: the search for a split does not stop until at least one
135  // valid partition of the node samples is found, even if it requires to
136  // effectively inspect more than ``max_features`` features.
137  // Note: this parameter is tree-specific.
138  Int_t verbose;//Controls the verbosity of the tree building process.
139  TString max_leaf_nodes;//int or None, optional (default=None)
140  //Grow trees with ``max_leaf_nodes`` in best-first fashion.
141  //Best nodes are defined as relative reduction in impurity.
142  //If None then unlimited number of leaf nodes.
143  //If not None then ``max_depth`` will be ignored.
144 
145  Bool_t warm_start;//bool, optional (default=False)
146  //When set to ``True``, reuse the solution of the previous call to fit
147  //and add more estimators to the ensemble, otherwise, just fit a whole
148  //new forest.
149  // get help message text
150  void GetHelpMessage() const;
151 
152 
154  };
155 } // namespace TMVA
156 #endif
virtual void ReadWeightsFromStream(std::istream &)
Definition: MethodPyGTB.h:76
Double_t GetMvaValue(Double_t *errLower=0, Double_t *errUpper=0)
EAnalysisType
Definition: Types.h:129
Basic string class.
Definition: TString.h:137
const Ranking * CreateRanking()
Definition: MethodPyGTB.h:56
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Double_t min_weight_fraction_leaf
Definition: MethodPyGTB.h:107
TString max_leaf_nodes
Definition: MethodPyGTB.h:139
#define ClassDef(name, id)
Definition: Rtypes.h:254
void GetHelpMessage() const
Double_t subsample
Definition: MethodPyGTB.h:97
Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
unsigned int UInt_t
Definition: RtypesCore.h:42
TString random_state
Definition: MethodPyGTB.h:120
double Double_t
Definition: RtypesCore.h:55
DataSetManager * fDataSetManager
Definition: MethodPyGTB.h:80
int type
Definition: TGX11.cxx:120
Double_t learning_rate
Definition: MethodPyGTB.h:91
virtual void ReadModelFromFile()
TString max_features
Definition: MethodPyGTB.h:125
virtual void AddWeightsXMLTo(void *) const
Definition: MethodPyGTB.h:74
virtual void ReadWeightsFromXML(void *)
Definition: MethodPyGTB.h:75
Abstract ClassifierFactory template that handles arbitrary types.
#define NULL
Definition: Rtypes.h:82
virtual void ReadWeightsFromStream(std::istream &)=0
MethodPyGTB(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="")
Definition: MethodPyGTB.cxx:59
virtual void TestClassification()
initialization