23#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
24#include <numpy/arrayobject.h>
67 fBaseEstimator(
"None"),
79 fBaseEstimator(
"None"),
106 The base estimator from which the boosted ensemble is built.\
107 Support for sample weighting is required, as well as proper `classes_`\
108 and `n_classes_` attributes.");
111 The maximum number of estimators at which boosting is terminated.\
112 In case of perfect fit, the learning procedure is stopped early.");
115 Learning rate shrinks the contribution of each classifier by\
116 ``learning_rate``. There is a trade-off between ``learning_rate`` and\
120 If 'SAMME.R' then use the SAMME.R real boosting algorithm.\
121 ``base_estimator`` must support calculation of class probabilities.\
122 If 'SAMME' then use the SAMME discrete boosting algorithm.\
123 The SAMME.R algorithm typically converges faster than SAMME,\
124 achieving a lower test error with fewer boosting iterations.\
125 'SAME.R' is deprecated since version 1.4 and removed since 1.6");
128 If int, random_state is the seed used by the random number generator;\
129 If RandomState instance, random_state is the random number generator;\
130 If None, the random number generator is the RandomState instance used\
134 "Store trained classifier in this file");
144 <<
" The options are Object or None." <<
Endl;
149 Log() << kFATAL <<
"NEstimators <=0 ... that does not work!" <<
Endl;
155 Log() << kFATAL <<
"LearningRate <=0 ... that does not work!" <<
Endl;
162 <<
" The options are SAMME of SAMME.R." <<
Endl;
170 <<
"If int, random_state is the seed used by the random number generator;"
171 <<
"If RandomState instance, random_state is the random number generator;"
172 <<
"If None, the random number generator is the RandomState instance used by `np.random`." <<
Endl;
204 npy_intp dimsData[2];
205 dimsData[0] = fNrowsTraining;
207 PyArrayObject * fTrainData = (PyArrayObject *)PyArray_SimpleNew(2, dimsData, NPY_FLOAT);
209 float *TrainData = (
float *)(PyArray_DATA(fTrainData));
211 npy_intp dimsClasses = (npy_intp) fNrowsTraining;
212 PyArrayObject * fTrainDataClasses = (PyArrayObject *)PyArray_SimpleNew(1, &dimsClasses, NPY_FLOAT);
213 PyDict_SetItemString(
fLocalNS,
"trainDataClasses", (
PyObject*)fTrainDataClasses);
214 float *TrainDataClasses = (
float *)(PyArray_DATA(fTrainDataClasses));
216 PyArrayObject * fTrainDataWeights = (PyArrayObject *)PyArray_SimpleNew(1, &dimsClasses, NPY_FLOAT);
217 PyDict_SetItemString(
fLocalNS,
"trainDataWeights", (
PyObject*)fTrainDataWeights);
218 float *TrainDataWeights = (
float *)(PyArray_DATA(fTrainDataWeights));
220 for (
int i = 0; i < fNrowsTraining; i++) {
228 TrainDataClasses[i] =
e->GetClass();
231 TrainDataWeights[i] =
e->GetWeight();
235 PyRunString(
"classifier = sklearn.ensemble.AdaBoostClassifier(estimator=baseEstimator, n_estimators=nEstimators, learning_rate=learningRate, algorithm=algorithm, random_state=randomState)",
236 "Failed to setup classifier");
240 PyRunString(
"dump = classifier.fit(trainData, trainDataClasses, trainDataWeights)",
"Failed to train classifier");
245 Log() << kFATAL <<
"Can't create classifier object from AdaBoostClassifier" <<
Endl;
271 if (firstEvt > lastEvt || lastEvt > nEvents) lastEvt = nEvents;
272 if (firstEvt < 0) firstEvt = 0;
273 nEvents = lastEvt-firstEvt;
282 <<
" sample (" << nEvents <<
" events)" <<
Endl;
288 PyArrayObject *pEvent= (PyArrayObject *)PyArray_SimpleNew(2, dims, NPY_FLOAT);
289 float *pValue = (
float *)(PyArray_DATA(pEvent));
291 for (
Int_t ievt=0; ievt<nEvents; ievt++) {
300 PyArrayObject *
result = (PyArrayObject *)PyObject_CallMethod(
fClassifier,
const_cast<char *
>(
"predict_proba"),
const_cast<char *
>(
"(O)"), pEvent);
301 double *proba = (
double *)(PyArray_DATA(
result));
305 for (
int i = 0; i < nEvents; ++i) {
314 <<
"Elapsed time for evaluation of " << nEvents <<
" events: "
335 PyArrayObject *pEvent= (PyArrayObject *)PyArray_SimpleNew(2, dims, NPY_FLOAT);
336 float *pValue = (
float *)(PyArray_DATA(pEvent));
337 for (
UInt_t i = 0; i <
fNvars; i++) pValue[i] =
e->GetValue(i);
340 PyArrayObject *
result = (PyArrayObject *)PyObject_CallMethod(
fClassifier,
const_cast<char *
>(
"predict_proba"),
const_cast<char *
>(
"(O)"), pEvent);
341 double *proba = (
double *)(PyArray_DATA(
result));
364 PyArrayObject *pEvent= (PyArrayObject *)PyArray_SimpleNew(2, dims, NPY_FLOAT);
365 float *pValue = (
float *)(PyArray_DATA(pEvent));
366 for (
UInt_t i = 0; i <
fNvars; i++) pValue[i] =
e->GetValue(i);
369 PyArrayObject *
result = (PyArrayObject *)PyObject_CallMethod(
fClassifier,
const_cast<char *
>(
"predict_proba"),
const_cast<char *
>(
"(O)"), pEvent);
370 double *proba = (
double *)(PyArray_DATA(
result));
411 PyArrayObject* pRanking = (PyArrayObject*) PyObject_GetAttrString(
fClassifier,
"feature_importances_");
414 if(pRanking == 0)
return NULL;
433 Log() <<
"An AdaBoost classifier is a meta-estimator that begins by fitting" <<
Endl;
434 Log() <<
"a classifier on the original dataset and then fits additional copies" <<
Endl;
435 Log() <<
"of the classifier on the same dataset but where the weights of incorrectly" <<
Endl;
436 Log() <<
"classified instances are adjusted such that subsequent classifiers focus" <<
Endl;
437 Log() <<
"more on difficult cases." <<
Endl;
439 Log() <<
"Check out the scikit-learn documentation for more information." <<
Endl;
#define REGISTER_METHOD(CLASS)
for example
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
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
PyGILState_STATE m_GILState
virtual void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility they are hence without any...
const char * GetName() const
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
std::vector< Double_t > GetMvaValues(Long64_t firstEvt=0, Long64_t lastEvt=-1, Bool_t logProgress=false)
get all the MVA values for the events of the current Data type
PyObject * pBaseEstimator
std::vector< Double_t > mvaValues
TString fFilenameClassifier
void GetHelpMessage() const
Double_t GetMvaValue(Double_t *errLower=nullptr, Double_t *errUpper=nullptr)
const Ranking * CreateRanking()
std::vector< Float_t > classValues
MethodPyAdaBoost(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="")
Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
virtual void TestClassification()
initialization
virtual void ReadModelFromFile()
std::vector< Float_t > & GetMulticlassValues()
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.
TString GetElapsedTime(Bool_t Scientific=kTRUE)
returns pretty string with elapsed time
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)