ProfTreeClassifier#
- class empulse.models.ProfTreeClassifier(*, tp_cost=0.0, tn_cost=0.0, fn_cost=0.0, fp_cost=0.0, loss=None, alpha=0.0, patience=100, tolerance=0.0001, max_depth=10, min_samples_split=20, min_samples_leaf=7, max_iter=1000, population_size=None, crossover_rate=0.2, grow_rate=0.2, prune_rate=0.2, mutate_split_rate=0.2, mutate_value_rate=0.2, n_jobs=1, random_state=None)[source]#
Profit-driven evolutionary decision tree classifier.
The ProfTree classifier is a decision tree classifier that is trained using a genetic algorithm. The genetic algorithm is used to evolve a population of trees over multiple generations. The fitness of each tree is evaluated using a fitness function, which is used to select the best trees for crossover and mutation.
- Parameters:
- tp_costfloat or array-like, shape=(n_samples,), default=0.0
Cost of true positives. If
float, then all true positives have the same cost. If array-like, then it is the cost of each true positive classification. Is overwritten if another tp_cost is passed to thefitmethod.Note
It is not recommended to pass instance-dependent costs to the
__init__method. Instead, pass them to thefitmethod.- fp_costfloat or array-like, shape=(n_samples,), default=0.0
Cost of false positives. If
float, then all false positives have the same cost. If array-like, then it is the cost of each false positive classification. Is overwritten if another fp_cost is passed to thefitmethod.Note
It is not recommended to pass instance-dependent costs to the
__init__method. Instead, pass them to thefitmethod.- fp_costfloat or array-like, shape=(n_samples,), default=0.0
Cost of false positives. If
float, then all false positives have the same cost. If array-like, then it is the cost of each false positive classification. Is overwritten if another fp_cost is passed to thefitmethod.Note
It is not recommended to pass instance-dependent costs to the
__init__method. Instead, pass them to thefitmethod.- fn_costfloat or array-like, shape=(n_samples,), default=0.0
Cost of false negatives. If
float, then all false negatives have the same cost. If array-like, then it is the cost of each false negative classification. Is overwritten if another fn_cost is passed to thefitmethod.Note
It is not recommended to pass instance-dependent costs to the
__init__method. Instead, pass them to thefitmethod.- lossMetric or None
Fitness function for the genetic algorithm to maximize. If
None, themax_profit_scoreis used.- alphafloat, default=0.0
Complexity penalty for the fitness function. A way to control overfitting.
When
alphais 0.0, the fitness function is not penalized for the amount of nodes in the tree. Whenalphais greater than 0.0, the fitness function is penalized for the amount of nodes in the tree.- patienceint, default=100
Number of iterations to wait for improvement before stopping early.
- tolerancefloat, default=1e-4
Minimum relative improvement in fitness required to consider a solution better.
- max_iterint, default=1000
Maximum number of iterations / number of generations the GA is run.
- max_depthint or None, default=10
Maximum depth of the tree. Computation time scales exponentially with depth, be careful with higher values.
- min_samples_splitint or float, default=20
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 fraction and ceil(min_samples_split * n_samples) are the minimum number of samples for each split.
- min_samples_leafint or float, default=7
The minimum number of samples required to be at a leaf node. A split point at any depth will only be considered if it leaves at least
min_samples_leaftraining samples in each of the left and right branches. This may have the effect of smoothing the model, especially in regression.If int, then consider min_samples_leaf as the minimum number.
If float, then min_samples_leaf is a fraction and ceil(min_samples_leaf * n_samples) are the minimum number of samples for each node.
- population_sizeint or None, default=None
Number of decision trees in the population. If
None, population_size is set to10 * n_features. Will be at least 2 trees.- crossover_ratefloat, default=0.2
Probability of crossover. Must be in [0, 1].
Variation operator is mutually exclusive with variation operators (
crossover_rate,grow_rate,prune_rate,mutate_split_rate,mutate_value_rate). All probabilities must sum to 1.- grow_ratefloat, default=0.2
Probability to add a randomly generated split rule to a leaf node. Must be in [0, 1].
Variation operator is mutually exclusive with variation operators (
crossover_rate,grow_rate,prune_rate,mutate_split_rate,mutate_value_rate). All probabilities must sum to 1.- prune_ratefloat, default=0.2
Probability to remove a randomly selected split rule from an internal node with two leaf nodes as children. Must be in [0, 1].
Variation operator is mutually exclusive with variation operators (
crossover_rate,grow_rate,prune_rate,mutate_split_rate,mutate_value_rate). All probabilities must sum to 1.- mutate_split_ratefloat, default=0.2
Probability to change the feature and feature value of a random split in the tree. Must be in [0, 1].
Variation operator is mutually exclusive with variation operators (
crossover_rate,grow_rate,prune_rate,mutate_split_rate,mutate_value_rate). All probabilities must sum to 1.- mutate_value_ratefloat, default=0.2
Probability to change only the feature value of a random split in the tree. Must be in [0, 1].
Variation operator is mutually exclusive with variation operators (
crossover_rate,grow_rate,prune_rate,mutate_split_rate,mutate_value_rate). All probabilities must sum to 1.- n_jobsint, default=1
Number of jobs to run in parallel.
- random_statenp.random.RandomState, int or None, default=None
Controls the randomness of the estimator. To obtain a deterministic behaviour during fitting,
random_statehas to be fixed to an integer. See Sklearn Glossary for details.
- fit(X, y, *, tp_cost=Parameter.UNCHANGED, fp_cost=Parameter.UNCHANGED, tn_cost=Parameter.UNCHANGED, fn_cost=Parameter.UNCHANGED, **loss_params)#
Fit the model according to the given training data.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
Training data.
- yarray-like of shape (n_samples,)
Target values.
- tp_costfloat or array-like, shape=(n_samples,), default=$UNCHANGED$
Cost of true positives. If
float, then all true positives have the same cost. If array-like, then it is the cost of each true positive classification.- fp_costfloat or array-like, shape=(n_samples,), default=$UNCHANGED$
Cost of false positives. If
float, then all false positives have the same cost. If array-like, then it is the cost of each false positive classification.- tn_costfloat or array-like, shape=(n_samples,), default=$UNCHANGED$
Cost of true negatives. If
float, then all true negatives have the same cost. If array-like, then it is the cost of each true negative classification.- fn_costfloat or array-like, shape=(n_samples,), default=$UNCHANGED$
Cost of false negatives. If
float, then all false negatives have the same cost. If array-like, then it is the cost of each false negative classification.- loss_paramsAny
Additional parameter to be passed to the loss function.
- Returns:
- self
Fitted estimator.
- get_metadata_routing()#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequestencapsulating routing information.
- get_params(deep=True)#
Get parameters for this estimator.
- Parameters:
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
- paramsdict
Parameter names mapped to their values.
- predict(X)#
Predict class labels for samples in X.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
Features.
- Returns:
- y_predndarray of shape (n_samples,)
Predicted labels for each sample.
- predict_proba(X)[source]#
Predict class probabilities of the input samples X.
The predicted class probability is the fraction of samples of the same class in a leaf.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
The input samples. Internally, it will be converted to
dtype=np.float32.
- Returns:
- probandarray of shape (n_samples, n_classes)
The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.
- score(X, y, sample_weight=None)#
Return accuracy on provided data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
Test samples.
- yarray-like of shape (n_samples,) or (n_samples, n_outputs)
True labels for X.
- sample_weightarray-like of shape (n_samples,), default=None
Sample weights.
- Returns:
- scorefloat
Mean accuracy of
self.predict(X)w.r.t. y.
- set_fit_request(*, fn_cost='$UNCHANGED$', fp_cost='$UNCHANGED$', tn_cost='$UNCHANGED$', tp_cost='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
- fn_coststr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
fn_costparameter infit.- fp_coststr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
fp_costparameter infit.- tn_coststr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
tn_costparameter infit.- tp_coststr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
tp_costparameter infit.
- Returns:
- selfobject
The updated object.
- set_params(**params)#
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline). The latter have parameters of the form<component>__<parameter>so that it’s possible to update each component of a nested object.- Parameters:
- **paramsdict
Estimator parameters.
- Returns:
- selfestimator instance
Estimator instance.
- set_score_request(*, sample_weight='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
- Returns:
- selfobject
The updated object.