Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tmva/pymva/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ set(PY_HEADERS ${CMAKE_SOURCE_DIR}/tmva/pymva/inc/TMVA/PyMethodBase.h
${CMAKE_SOURCE_DIR}/tmva/pymva/inc/TMVA/MethodPyRandomForest.h
${CMAKE_SOURCE_DIR}/tmva/pymva/inc/TMVA/MethodPyAdaBoost.h
${CMAKE_SOURCE_DIR}/tmva/pymva/inc/TMVA/MethodPyGTB.h
${CMAKE_SOURCE_DIR}/tmva/pymva/inc/TMVA/MethodPyKeras.h)
${CMAKE_SOURCE_DIR}/tmva/pymva/inc/TMVA/MethodPyKeras.h
${CMAKE_SOURCE_DIR}/tmva/pymva/inc/TMVA/MethodPyRFOneVsRest.h)

ROOT_GENERATE_DICTIONARY(G__PyMVA ${PY_HEADERS} MODULE ${libname} LINKDEF LinkDef.h)
# ROOT_GENERATE_ROOTMAP(RInterface LINKDEF LinkDef.h)
Expand Down
1 change: 1 addition & 0 deletions tmva/pymva/inc/LinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#pragma link C++ class TMVA::MethodPyAdaBoost+;
#pragma link C++ class TMVA::MethodPyGTB+;
#pragma link C++ class TMVA::MethodPyKeras+;
#pragma link C++ class TMVA::MethodPyRFOneVsRest + ;

#endif

156 changes: 156 additions & 0 deletions tmva/pymva/inc/TMVA/MethodPyRFOneVsRest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// @(#)root/tmva/pymva $Id$
// Authors: Omar Zapata, Lorenzo Moneta, Sergei Gleyzer 2015

/**********************************************************************************
* Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
* Package: TMVA *
* Class : MethodPyRFOneVsRest *
* Web : http://oproject.org *
* *
* Description: *
* scikit-learn Package RandomForestClassifier method based on python *
* *
**********************************************************************************/

#ifndef ROOT_TMVA_MethodPyRFOneVsRest
#define ROOT_TMVA_MethodPyRFOneVsRest

//////////////////////////////////////////////////////////////////////////
// //
// MethodPyRFOneVsRest //
// //
// //
//////////////////////////////////////////////////////////////////////////

#include "TMVA/PyMethodBase.h"

namespace TMVA {

class Factory; // DSMTEST
class Reader; // DSMTEST
class DataSetManager; // DSMTEST
class Types;
class MethodPyRFOneVsRest : public PyMethodBase {

public:
// constructors
MethodPyRFOneVsRest(const TString &jobName, const TString &methodTitle, DataSetInfo &theData,
const TString &theOption = "");

MethodPyRFOneVsRest(DataSetInfo &dsi, const TString &theWeightFile);

~MethodPyRFOneVsRest(void);
void Train();
// options treatment
void Init();
void DeclareOptions();
void ProcessOptions();
// create ranking
const Ranking *CreateRanking()
{
return NULL; // = 0;
}

Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets);

// performs classifier testing
virtual void TestClassification();

Double_t GetMvaValue(Double_t *errLower = 0, Double_t *errUpper = 0);

using MethodBase::ReadWeightsFromStream;
// the actual "weights"
virtual void AddWeightsXMLTo(void * /* parent */) const {} // = 0;
virtual void ReadWeightsFromXML(void * /* wghtnode */) {} // = 0;
virtual void ReadWeightsFromStream(std::istream &) {} //= 0; // backward compatibility

void ReadModelFromFile();

private:
DataSetManager *fDataSetManager; // DSMTEST
friend class Factory; // DSMTEST
friend class Reader; // DSMTEST
protected:
// RandromForest options
Int_t n_estimators; // integer, optional (default=10)
// The number of trees in the forest.
TString criterion; // string, optional (default="gini")
// The function to measure the quality of a split. Supported criteria are
//"gini" for the Gini impurity and "entropy" for the information gain.
// Note: this parameter is tree-specific.

TString max_depth; // integer or None, optional (default=None)
// The maximum depth of the tree. If None, then nodes are expanded until
// all leaves are pure or until all leaves contain less than
Int_t min_samples_split; // integer, optional (default=2)
// The minimum number of samples required to split an internal node.

Int_t min_samples_leaf; // integer, optional (default=1)
// The minimum number of samples in newly created leaves. A split is
// discarded if after the split, one of the leaves would contain less then
//``min_samples_leaf`` samples.
// Note: this parameter is tree-specific.
Double_t min_weight_fraction_leaf; // float, optional (default=0.)
// The minimum weighted fraction of the input samples required to be at a
// leaf node.
// Note: this parameter is tree-specific.
TString max_features; // int, float, string or None, optional (default="auto")
// The number of features to consider when looking for the best split:
//- If int, then consider `max_features` features at each split.
//- If float, then `max_features` is a percentage and
//`int(max_features * n_features)` features are considered at each split.
//- If "auto", then `max_features=sqrt(n_features)`.
//- If "sqrt", then `max_features=sqrt(n_features)`.
//- If "log2", then `max_features=log2(n_features)`.
//- If None, then `max_features=n_features`.
// Note: the search for a split does not stop until at least one
// valid partition of the node samples is found, even if it requires to
// effectively inspect more than ``max_features`` features.
// Note: this parameter is tree-specific.
TString max_leaf_nodes; // int or None, optional (default=None)
// Grow trees with ``max_leaf_nodes`` in best-first fashion.
// Best nodes are defined as relative reduction in impurity.
// If None then unlimited number of leaf nodes.
// If not None then ``max_depth`` will be ignored.
Bool_t bootstrap; // boolean, optional (default=True)
// Whether bootstrap samples are used when building trees.
Bool_t oob_score; // Whether to use out-of-bag samples to estimate
// the generalization error.
Int_t n_jobs; // : integer, optional (default=1)
// The number of jobs to run in parallel for both `fit` and `predict`.
// If -1, then the number of jobs is set to the number of cores.
TString random_state; // int, RandomState instance or None, optional (default=None)
// If int, random_state is the seed used by the random number generator;
// If RandomState instance, random_state is the random number generator;
// If None, the random number generator is the RandomState instance used
// by `np.random`.
Int_t verbose; // Controls the verbosity of the tree building process.
Bool_t warm_start; // bool, optional (default=False)
// When set to ``True``, reuse the solution of the previous call to fit
// and add more estimators to the ensemble, otherwise, just fit a whole
// new forest.
TString class_weight; // dict, list of dicts, "auto", "subsample" or None, optional
// Weights associated with classes in the form ``{class_label: weight}``.
// If not given, all classes are supposed to have weight one. For
// multi-output problems, a list of dicts can be provided in the same
// order as the columns of y.
// The "auto" mode uses the values of y to automatically adjust
// weights inversely proportional to class frequencies in the input data.
// The "subsample" mode is the same as "auto" except that weights are
// computed based on the bootstrap sample for every tree grown.
// For multi-output, the weights of each column of y will be multiplied.
// Note that these weights will be multiplied with sample_weight (passed
// through the fit method) if sample_weight is specified.
Int_t n_jobsOVR; // int, optional, default: 1
// The number of jobs to use for the computation. If -1 all CPUs are used.
// If 1 is given, no parallel computing code is used at all, which is
// useful for debugging. For n_jobs below -1, (n_cpus + 1 + n_jobs)
// are used. Thus for n_jobs = -2, all CPUs but one are used.

// get help message text
void GetHelpMessage() const;

ClassDef(MethodPyRFOneVsRest, 0)
};
} // namespace TMVA
#endif
Loading