base.base_fmnn_estimator

Base classes for all fuzzy min-max neural network estimators and their improved versions.

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

Base class for all hyperbox-based estimators in 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.

get_sample_explanation(x)

Get useful information for explaining the reason behind the predicted result for the input pattern

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.

simple_pruning(X_val, y_val[, ...])

Simply prune low qualitied hyperboxes based on a pre-defined accuracy threshold for each hyperbox

get_sample_explanation(x)[source]

Get useful information for explaining the reason behind the predicted result for the input pattern

Parameters:
xndarray of shape (n_feature,)

The input pattern which needs to be explained.

Returns:
y_predint

The predicted class of the input pattern

dict_mem_val_classesdictionary

A dictionary stores all membership values for all classes. The key is class label and the value is the corresponding membership value.

dict_min_point_classesdictionary

A dictionary stores all mimimal points of hyperboxes having the maximum membership value for each class. The key is the class label and the value is the minimal points of all hyperboxes coressponding to each class

dict_max_point_classesdictionary

A dictionary stores all maximal points of hyperboxes having the maximum membership value for each class. The key is the class label and the value is the maximal points of all hyperboxes coressponding to each class

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.

simple_pruning(X_val, y_val, acc_threshold=0.5, keep_empty_boxes=False)[source]

Simply prune low qualitied hyperboxes based on a pre-defined accuracy threshold for each hyperbox

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

The data matrix contains validation patterns.

y_valndarray of shape (n_samples,)

A vector contains the true class label corresponding to each validation pattern.

acc_thresholdfloat, optional, default=0.5

The minimum accuracy for each hyperbox to be kept unchanged.

keep_empty_boxesboolean, optional, default=False

Whether to keep the hyperboxes which do not join the prediction process on the validation set. If True, keep them, else the decision for keeping or removing based on the classification accuracy on the validation dataset

Returns:
self

A hyperbox-based model with the low-qualitied hyperboxes pruned.

hbbrain.base.base_fmnn_estimator.predict_with_manhattan_fmnn(V, W, C, X, g=1)[source]

Predict class labels for samples in X.

Note

This is a common function to determine the right class labels for X with regard to 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.

Xarray-like of shape (n_samples, n_features)

The data matrix contains 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.