monoensemble.MonoRandomForestClassifier¶
-
class
monoensemble.MonoRandomForestClassifier(incr_feats=[], decr_feats=[], coef_calc_type='bayes', n_estimators=10, criterion='gini', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features='auto', max_leaf_nodes=None, min_impurity_split=1e-07, bootstrap=True, oob_score=False, n_jobs=1, random_state=None, verbose=0, warm_start=False, class_weight=None)¶ A fast and perfect monotone random forest classifier. This is a high performance implementation of monotone random forest classifier proposed in Bartley et al. 2017. It behaves identically to sci-kit learn’s GradientBoostingClassifier with the following exceptions:
1. The interface has three additional parameters for the constructor:incr_feats,decr_feats, andcoef_calc_type. The first two simply define which features are required to be monotone increasing (decreasing), and the last defines which solution to use for coefficient recalculation. See below for more details. 2. After fitting each tree, the tree leaf rules are made ‘monotone compliant’, and the coefficients re-calculated are constrained to ensure monotonicity (see paper for details). 3. Three coefficient re-calculation methods are offered: Logistic regression, Naive Bayesian techniques, and gradient boosting’s single Newton step. 4. Multi-class capability is implemented using the monotone compliant ensembling method described in Kotlowski and Slowinski 2013.Parameters: incr_feats : array-like
The one-based array indices of the columns in X that should only have a monotone increasing impact on the resulting class.
decr_feats : array-like
The one-based array indices of the columns in X that should only have a monotone decreasing impact on the resulting class.
coef_calc_type : string
Determines how the rule coefficients are calculated. Allowable values: ‘logistic’: L2 regularised logistic regression. Slower. ‘boost’ DEFAULT: A single Newton step approximation is used. Fast, and generally best. ‘bayesian’: Assumes conditional indpendence between rules and calculates coefficients as per Naive bayesian classification. Fast with good results.
n_estimators : integer, optional (default=10)
The number of trees in the forest.
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.
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) (same as “auto”).
- 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_featuresfeatures.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 min_samples_split samples.
min_samples_split : int, float, optional (default=2)
The minimum number of samples required to split an internal node:
- If int, then consider min_samples_split as the minimum number.
- If float, then min_samples_split is a percentage and ceil(min_samples_split * n_samples) are the minimum number of samples for each split.
Changed in version 0.18: Added float values for percentages.
min_samples_leaf : int, float, optional (default=1)
The minimum number of samples required to be at a leaf node:
- If int, then consider min_samples_leaf as the minimum number.
- If float, then min_samples_leaf is a percentage and ceil(min_samples_leaf * n_samples) are the minimum number of samples for each node.
Changed in version 0.18: Added float values for percentages.
min_weight_fraction_leaf : float, optional (default=0.)
The minimum weighted fraction of the input samples required to be at a leaf node.
max_leaf_nodes : int or None, optional (default=None)
Grow trees with
max_leaf_nodesin best-first fashion. Best nodes are defined as relative reduction in impurity. If None then unlimited number of leaf nodes.min_impurity_split : float, optional (default=1e-7)
Threshold for early stopping in tree growth. A node will split if its impurity is above the threshold, otherwise it is a leaf.
New in version 0.18.
bootstrap : boolean, optional (default=True)
Whether bootstrap samples are used when building trees.
oob_score : bool (default=False)
Whether to use out-of-bag samples to estimate the generalization accuracy.
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.
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.
verbose : int, optional (default=0)
Controls the verbosity of the tree building process.
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.class_weight : dict, list of dicts, “balanced”,
“balanced_subsample” or None, optional (default=None) 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 “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as
n_samples / (n_classes * np.bincount(y))The “balanced_subsample” mode is the same as “balanced” 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.
See also
DecisionTreeClassifier,ExtraTreesClassifierReferences
[R5] - Breiman, “Random Forests”, Machine Learning, 45(1), 5-32, 2001.
[R6] http://arogozhnikov.github.io/2016/07/12/secret-of-ml.html: Note that using mono_gradient_boosting works even though it uses MSE rather than gini, because for binary 0/1 classification the results are the same! [R7] C. Bartley, W. Liu, and M. Reynolds., Fast & Perfect Monotone Random Forest Classication, 2017 [R8] W. Kotlowskiand R. Slowinski., On Nonparametric Ordinal Classification with Monotonicity Constraints, 2013 Attributes