imbalanced_svr.SPBaDF#

class imbalanced_spdf.SPBaDF(n_trees=40, weight=1, pen=0, maximal_leaves=None, random_state=23)[source]#

Shape Penalty Bagging Decision Forest (SPBaDF)

Implements a bagging ensemble using Shape Penalty Regularized Trees for imbalanced_spdf classification. Each tree is trained on a bootstrap sample and uses a subset of non-constant features.

Parameters:
  • n_trees (int, default=40) – Number of trees in the ensemble.

  • weight (int, default=1) – Weight for the minority class, denoted as λ in the associated research paper.

  • pen (int, default=0) – Regularization penalty for controlling the complexity of the decision boundary.

  • maximal_leaves (int or float, default=None) – Maximum number of leaves allowed for each tree. If None, it defaults to 2 * np.sqrt(n_samples) * 0.3333 dynamically for each tree.

  • random_state (int, default=23) – Random seed for reproducibility.

trees[source]#

List of trained tree estimators.

Type:

list

considered_features[source]#

List of feature subsets used for each tree.

Type:

list of lists

classes_[source]#

Unique class labels observed during training.

Type:

ndarray of shape (n_classes,)

__init__(n_trees=40, weight=1, pen=0, maximal_leaves=None, random_state=23)[source]#

Methods

__init__([n_trees, weight, pen, ...])

fit(X, y)

Fits the SPBaDF ensemble on the training data.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

predict(X)

Predicts labels for input samples using the trained ensemble.

score(X, y[, sample_weight])

Return the mean accuracy on the given test data and labels.

set_params(**params)

Set the parameters of this estimator.

set_score_request(*[, sample_weight])

Request metadata passed to the score method.

fit(X, y)[source]#

Fits the SPBaDF ensemble on the training data.

Parameters:
  • X (ndarray of shape (n_samples, n_features)) – Feature matrix for training.

  • y (ndarray of shape (n_samples,)) – Target labels for training.

Returns:

self – The fitted ensemble instance.

Return type:

SPBaDF

get_metadata_routing()[source]#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

get_params(deep=True)[source]#

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

predict(X)[source]#

Predicts labels for input samples using the trained ensemble.

Parameters:

X (ndarray of shape (n_samples, n_features)) – Input features for prediction.

Returns:

y_pred – Predicted labels.

Return type:

ndarray of shape (n_samples,)

score(X, y, sample_weight=None)[source]#

Return the mean accuracy on the given test 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:
  • X (array-like of shape (n_samples, n_features)) – Test samples.

  • y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True labels for X.

  • sample_weight (array-like of shape (n_samples,), default=None) – Sample weights.

Returns:

score – Mean accuracy of self.predict(X) w.r.t. y.

Return type:

float

set_params(**params)[source]#

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:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') SPBaDF[source]#

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • 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.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:

sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in score.

Returns:

self – The updated object.

Return type:

object