19 #pragma GCC diagnostic ignored "-Wunused-parameter"
24 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
25 #include <numpy/arrayobject.h>
58 PyMethodBase(jobName,
Types::kPyAdaBoost, methodTitle, dsi, theOption, theTargetDir),
59 base_estimator("
None"),
66 SetWeightFileDir(
gConfig().GetIONames().fWeightFileDir);
73 base_estimator(
"None"),
102 The base estimator from which the boosted ensemble is built.\
103 Support for sample weighting is required, as well as proper `classes_`\
104 and `n_classes_` attributes.");
107 The maximum number of estimators at which boosting is terminated.\
108 In case of perfect fit, the learning procedure is stopped early.");
111 Learning rate shrinks the contribution of each classifier by\
112 ``learning_rate``. There is a trade-off between ``learning_rate`` and\
116 If 'SAMME.R' then use the SAMME.R real boosting algorithm.\
117 ``base_estimator`` must support calculation of class probabilities.\
118 If 'SAMME' then use the SAMME discrete boosting algorithm.\
119 The SAMME.R algorithm typically converges faster than SAMME,\
120 achieving a lower test error with fewer boosting iterations.");
123 If int, random_state is the seed used by the random number generator;\
124 If RandomState instance, random_state is the random number generator;\
125 If None, the random number generator is the RandomState instance used\
133 if (!pobase_estimator) {
135 <<
" The options are Object or None."
138 Py_DECREF(pobase_estimator);
141 Log() <<
kERROR <<
" NEstimators <=0... that does not work !! "
142 <<
" I set it to 10 .. just so that the program does not crash"
147 Log() <<
kERROR <<
" LearningRate <=0... that does not work !! "
148 <<
" I set it to 1.0 .. just so that the program does not crash"
155 <<
" The options are SAMME of SAMME.R."
159 if (!porandom_state) {
161 <<
"If int, random_state is the seed used by the random number generator;"
162 <<
"If RandomState instance, random_state is the random number generator;"
163 <<
"If None, the random number generator is the RandomState instance used by `np.random`."
166 Py_DECREF(porandom_state);
178 PyObject *pName = PyUnicode_FromString(
"sklearn.ensemble");
180 fModule = PyImport_Import(pName);
192 int *dims =
new int[2];
193 dims[0] = fNrowsTraining;
195 fTrainData = (PyArrayObject *)PyArray_FromDims(2, dims, NPY_FLOAT);
196 float *TrainData = (
float *)(PyArray_DATA(
fTrainData));
199 fTrainDataClasses = (PyArrayObject *)PyArray_FromDims(1, &fNrowsTraining, NPY_FLOAT);
202 fTrainDataWeights = (PyArrayObject *)PyArray_FromDims(1, &fNrowsTraining, NPY_FLOAT);
205 for (
int i = 0; i < fNrowsTraining; i++) {
207 for (
UInt_t j = 0; j < fNvars; j++) {
208 TrainData[j + i * fNvars] = e->
GetValue(j);
228 PyObject_Print(args, stdout, 0);
229 std::cout << std::endl;
231 PyObject *fClassifierClass = PyDict_GetItemString(pDict,
"AdaBoostClassifier");
234 if (PyCallable_Check(fClassifierClass)) {
236 fClassifier = PyObject_CallObject(fClassifierClass , args);
243 Py_DECREF(fClassifierClass);
244 Log() <<
kFATAL <<
"Can't call function AdaBoostClassifier" <<
Endl;
281 int *dims =
new int[2];
284 PyArrayObject *pEvent= (PyArrayObject *)PyArray_FromDims(2, dims, NPY_FLOAT);
285 float *pValue = (
float *)(PyArray_DATA(pEvent));
289 PyArrayObject *
result = (PyArrayObject *)PyObject_CallMethod(
fClassifier, const_cast<char *>(
"predict_proba"),
const_cast<char *
>(
"(O)"), pEvent);
290 double *proba = (
double *)(PyArray_DATA(result));
322 Log() <<
"Decision Trees and Rule-Based Models " <<
Endl;
const TString & GetWeightFileDir() const
MsgLogger & Endl(MsgLogger &ml)
const Event * GetTrainingEvent(Long64_t ievt) const
OptionBase * DeclareOptionRef(T &ref, const TString &name, const TString &desc="")
ClassImp(MethodPyAdaBoost) MethodPyAdaBoost
virtual void TestClassification()
initialization
static void Serialize(TString file, PyObject *classifier)
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not...
PyArrayObject * fTrainDataClasses
static int PyIsInitialized()
static void PyInitialize()
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
const char * Data() const
static PyObject * Eval(TString code)
PyArrayObject * fTrainDataWeights
UInt_t GetNVariables() const
accessor to the number of variables
Double_t GetMvaValue(Double_t *errLower=0, Double_t *errUpper=0)
char * Form(const char *fmt,...)
PyArrayObject * fTrainData
void GetHelpMessage() const
const Event * GetEvent() const
Describe directory structure in memory.
UInt_t GetNVariables() const
access the number of variables through the datasetinfo
Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
#define REGISTER_METHOD(CLASS)
for example
Abstract ClassifierFactory template that handles arbitrary types.
virtual void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility they are hence without any...
void SetWeightFileDir(TString fileDir)
set directory of weight file
MethodPyAdaBoost(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="", TDirectory *theTargetDir=NULL)
Long64_t GetNTrainingEvents() const
static void UnSerialize(TString file, PyObject **obj)
virtual void TestClassification()
initialization
void NoErrorCalc(Double_t *const err, Double_t *const errUpper)