base.base_gfmm_estimator

Base class and functions for all general fuzzy min-max neural network estimators.

class hbbrain.base.base_gfmm_estimator.BaseGFMMClassifier(theta=0.5, gamma=1, is_draw=False, V=None, W=None, C=None)[source]

Base class for all hyperbox-based estimators in the hyperbox-brain.

Note

All estimators should specify all the parameters that can be set at the class level in their __init__ as explicit keyword arguments (no *args or **kwargs). This class only initialises all common parameters for hyperbox-based estimators.

Parameters:
thetafloat or ndarray of shape (n_features,), optional, defaut = 0.5

A maximum hyperbox size parameter for each dimension.

gammafloat or ndarray of shape (n_features,), optional, default=1

A sensitivity parameter describing the speed of decreasing of the membership function in each dimension.

is_drawboolean, optional, default = False

A parameter is used to indicate whether the process of hyperbox building can be dynamically displayed on a canvas or not. This functionality displays hyperboxes in the form of 2D or 3D. In the case that the number of dimensions is higher than 3, only the three features are shown.

Varray-like of shape (n_hyperboxes, n_features), default = an empty ndarray

A matrix stores all minimal coordinates of all existing hyperboxes, in which each row is a minimal coordinate of a hyperbox.

Warray-like of shape (n_hyperboxes, n_features), default = an empty ndarray

A matrix stores all maximal coordinates of all existing hyperboxes, in which each row is a maximal coordinate of a hyperbox.

Cndarray of shape (n_hyperboxes,), default = an empty ndarray

An array contains all class lables for all existing hyperboxes.

Attributes:
n_hyperboxesint

Number of hyperboxes built during fit.

Methods

delay([delay_constant])

Delay a time period to display hyperboxes

draw_hyperbox_and_boundary([window_name, ...])

Draw the existing hyperboxes and their decision boundaries among classes

fit(X, y)

Fit the model according to the given training data.

get_n_hyperboxes()

Get number of hyperboxes in the trained hyperbox-based model

get_params([deep])

Get parameters for this estimator.

initialise_canvas_graph([n_dims, ...])

Initialise a canvas to draw hyperboxes

predict(X)

Predict class labels for samples in X.

predict_proba(X)

Predict class probabilities of the input samples X.

predict_with_membership(X)

Predict class membership values of the input samples X.

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.

show_sample_explanation(xl, xu, ...[, ...])

Show explanation for predicted results of an input pattern under the form of parallel coordinates or hyperboxes in 2D or 3D planes.

predict(X)[source]

Predict class labels for samples in X.

Note

In the case there are many winner hyperboxes representing different class labels but with the same membership value with respect to the input pattern \(X_i\), an additional criterion based on the minimum Manhattan distance between the input patter \(X_i\) and the central points of winner hyperboxes are used to find the final winner hyperbox that its class label is used for predicting the class label of the input pattern \(X_i\).

Parameters:
Xarray-like of shape (n_samples, n_features)

The data matrix for which we want to predict the targets.

Returns:
y_predndarray of shape (n_samples,)

Vector containing the predictions. In binary and multiclass problems, this is a vector containing n_samples.

predict_proba(X)[source]

Predict class probabilities of the input samples X.

The predicted class probability is the fraction of the membership value of the representative hyperbox of that class and the sum of all membership values of all representative hyperboxes of all classes.

Parameters:
Xarray-like of shape (n_samples, n_features)

The input samples.

Returns:
probandarray of shape (n_samples, n_classes)

The class probabilities of the input samples. The order of the classes corresponds to that in ascending integers of class labels.

predict_with_membership(X)[source]

Predict class membership values of the input samples X.

The predicted class membership value is the membership value of the representative hyperbox of that class.

Parameters:
Xarray-like of shape (n_samples, n_features)

The input samples.

Returns:
mem_valsndarray of shape (n_samples, n_classes)

The class membership values of the input samples. The order of the classes corresponds to that in ascending integers of class labels.

hbbrain.base.base_gfmm_estimator.convert_format_missing_input_zero_one(Xl, Xu, y=None)[source]

Convert missing values in the features and labels under the form of NaN values to the form used in the algorithms

Parameters:
Xlarray-like of shape (n_samples, n_features)

A matrix containing lower bound values of features and samples, where n_samples is the number of samples and n_features is the number of features.

Xuarray-like of shape (n_samples, n_features)

A matrix containing upper bound values of features and samples, where n_samples is the number of samples and n_features is the number of features.

yarray-like of shape (n_samples,)

Target vector relative to [Xl, Xu].

Returns:
Xl_outarray-like of shape (n_samples, n_features)

The transformed matrix of the input matrix Xl.

Xu_outarray-like of shape (n_samples, n_features)

The transformed matrix of the input matrix Xu.

y_outarray-like of shape (n_samples, n_features)

The transformed vector of the input vector y.

hbbrain.base.base_gfmm_estimator.is_contain_missing_value(X)[source]

Check whether an input vector X contains any missing values.

Parameters:
Xarray-like of shape (n_features,) or (n_samples, n_features)

A input vector for which we want to check the existence of missing values.

Returns:
bool

The output value showing whether the input vector X contains missing values or not.

hbbrain.base.base_gfmm_estimator.predict_with_manhattan(V, W, C, Xl, Xu, g=1)[source]

Predict class labels for samples in X represented in the form of invervals [Xl, Xu]. This is a common function to determine the right class labels for X wrt. a trained hyperbox-based classifier represented by [V, W, C]. It uses the winner-takes-all principle to predict class labels for each sample in X by assigning the class label of the sample to the class label of the hyperbox with the maximum membership value to that sample. It will use a Manhattan distance in the case of many hyperboxes with different classes having the same maximum membership value.

Parameters:
Varray-like of shape (n_hyperboxes, n_features)

A matrix stores all minimal points of all hyperboxes of a trained hyperbox-based model, in which each row is a minimal point of a hyperbox.

Warray-like of shape (n_hyperboxes, n_features)

A matrix stores all maximal points of all hyperboxes of a trained hyperbox-based model, in which each row is a maximal point of a hyperbox.

Cndarray of shape (n_hyperboxes,)

An array contains all class lables for all hyperboxes of a trained hyperbox-based model.

Xlarray-like of shape (n_samples, n_features)

The data matrix contains lower bounds of input patterns for which we want to predict the targets.

Xuarray-like of shape (n_samples, n_features)

The data matrix contains upper bounds of input patterns for which we want to predict the targets.

gfloat or array-like of shape (n_features,), optional, default=1

A sensitivity parameter describing the speed of decreasing of the membership function in each dimension.

Returns:
y_predndarray of shape (n_samples,)

A vector contains the predictions. In binary and multiclass problems, this is a vector containing n_samples.

hbbrain.base.base_gfmm_estimator.predict_with_probability(V, W, C, N_samples, Xl, Xu, g=1)[source]

Predict class labels for samples in X represented in the form of invervals [Xl, Xu]. This is a common function to determine the right class labels for X wrt. a trained hyperbox-based classifier represented by [V, W, C]. It uses the winner-takes-all principle to predict class labels for each sample in X by assigning the class label of the sample to the class label of the hyperbox with the maximum membership value to that sample. It will use a probability formula based on the number of samples included in each winner hyperbox in the case of many hyperboxes with different classes having the same maximum membership value.

Parameters:
Varray-like of shape (n_hyperboxes, n_features)

A matrix stores all minimal points of all hyperboxes of a trained hyperbox-based model, in which each row is a minimal point of a hyperbox.

Warray-like of shape (n_hyperboxes, n_features)

A matrix stores all maximal points of all hyperboxes of a trained hyperbox-based model, in which each row is a maximal point of a hyperbox.

Cndarray of shape (n_hyperboxes,)

An array contains all class lables for all hyperboxes of a trained hyperbox-based model.

N_samplesndarray of shape (n_hyperboxes,)

An array contains number of samples included in each hyperbox of a trained hyperbox-based model.

Xlarray-like of shape (n_samples, n_features)

The data matrix contains lower bounds of input patterns for which we want to predict the targets.

Xuarray-like of shape (n_samples, n_features)

The data matrix contains upper bounds of input patterns for which we want to predict the targets.

gfloat or array-like of shape (n_features,), optional, default=1

A sensitivity parameter describing the speed of decreasing of the membership function in each dimension.

Returns:
y_predndarray of shape (n_samples,)

A vector contains the predictions. In binary and multiclass problems, this is a vector containing n_samples.