clover.distribution.DensityDistributor

class clover.distribution.DensityDistributor(filtering_threshold=1.0, distances_exponent=0.0, sparsity_based=True, distribution_ratio=1.0)[source]

Class to perform density based distribution.

Samples are distributed based on the density of clusters.

Parameters:
filtering_threshold : float or ‘auto’, optional (default=1.0)

The threshold of a cluster. It can be any non-negative number. If 'auto', the filtering threshold is calculated from the imbalance ratio of the target for the binary case or the maximum imbalance ratio of the target for the multiclass case. Any cluster that has an imbalance ratio smaller than the filtering threshold is identified as a filtered cluster and can be potentially used to generate minority class instances. Higher values increase the number of filtered clusters.

distances_exponent : float or ‘auto’, optional (default=0.0)

The exponent of the mean distance in the density calculation. It can be any non-negative number. If 'auto' then it is set equal to the number of features. Higher values make the calculation of density more sensitive to the cluster’s size i.e. clusters with large mean euclidean distance between samples are penalized.

sparsity_based : bool, optional (default=True)

When True clusters receive generated samples that are inversly proportional to their density. When False clusters receive generated samples that are proportional to their density.

distribution_ratio : float, optional (default=1.0)

The ratio of intra-cluster to inter-cluster generated samples. It is a number in the [0.0, 1.0] range. As the number increases more intra-cluster samples are generated. Inter-cluster generation, i.e. when distribution_ratio is less than 1.0, requires a neighborhood structure for the clusters and it will raise an error when it is not found.

Attributes:
majority_class_label_ : int

The majority class label.

class_labels_ : array, shape (n_classes, )

An array of unique class labels.

n_samples_ : int

The number of samples.

labels_ : array, shape (n_samples,)

Labels of each sample.

neighbors_ : array, (n_neighboring_pairs, 2)

An array that contains all neighboring pairs. Each row is a unique neighboring pair.

intra_distribution_ : dict

Each dict key is a multi-label tuple of shape (cluster_label, class_label)

inter_distribution_ : dict

Each dict key is a multi-label tuple of shape ((cluster_label1, cluster_label2), class_label)

__init__(self, filtering_threshold=1.0, distances_exponent=0.0, sparsity_based=True, distribution_ratio=1.0)[source]

Initialize self. See help(type(self)) for accurate signature.

fit(self, X, y, labels=None, neighbors=None)

Generate the intra-label and inter-label distribution.

Parameters:
X : {array-like, sparse matrix}, shape (n_samples, n_features)

Matrix containing the data which have to be sampled.

y : array-like, shape (n_samples,)

Corresponding label for each sample in X.

labels : array-like, shape (n_samples,)

Labels of each sample.

neighbors : array-like, (n_neighboring_pairs, 2)

An array that contains all neighboring pairs. Each row is a unique neighboring pair.

Returns:
self : object,

Return self.

fit_distribute(self, X, y, labels=None, neighbors=None)

Return the intra-label and inter-label distribution.

Parameters:
X : {array-like, sparse matrix}, shape (n_samples, n_features)

Matrix containing the data which have to be sampled.

y : array-like, shape (n_samples,)

Corresponding label for each sample in X.

labels : array-like, shape (n_samples,)

Labels of each sample.

neighbors : array-like, shape (n_neighboring_pairs, 2)

An array that contains all neighboring pairs. Each row is a unique neighboring pair.

Returns:
distributions : tuple of (intra_distribution, inter_distribution) arrays

A tuple with the two distributions.

get_params(self, deep=True)

Get parameters for this estimator.

Parameters:
deep : boolean, optional

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
params : mapping of string to any

Parameter names mapped to their values.

set_params(self, **params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns:
self