base.base_estimator
Base class for all hyperbox-based estimators.
- class hbbrain.base.base_estimator.BaseHyperboxClassifier(theta=0.5, 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 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
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.
- delay(delay_constant=0.01)[source]
Delay a time period to display hyperboxes
- Parameters:
- delay_constantfloat
Delay time period to display hyperboxes on the canvas
- draw_hyperbox_and_boundary(window_name='Hyperbox-based classifier and its decision boundaries', min_range=0, max_range=1)[source]
Draw the existing hyperboxes and their decision boundaries among classes
Note
This function only works on 2-dimensional datasets
- Parameters:
- window_namestr, optional, default=”Hyperbox-based classifier and its decision boundaries”
Name of plotting window showing hyperboxes and their decision boundaries.
- min_rangefloat, optional, default=0
Minimum value in each axis.
- max_rangefloat, optional, default=1
Maximum value in each axis.
- Returns:
- None.
- fit(X, y)[source]
Fit the model according to the given training data.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
Training vector, 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 X.
- Returns:
- self
Fitted estimator.
- get_n_hyperboxes()[source]
Get number of hyperboxes in the trained hyperbox-based model
- Returns:
- int
Number of hyperboxes in the trained hyperbox-based classifier.
- initialise_canvas_graph(n_dims=2, figure_name='A trained hyperbox-based learning model', min_range=0, max_range=1)[source]
Initialise a canvas to draw hyperboxes
- Parameters:
- n_dimsint, optional, default=2
The number of dimensions of hyperboxes shown in the canvas (2D or 3D).
- figure_namestr, optional, default=’A trained hyperbox-based learning model’
Title name of the window containing hyperboxes.
- fig_numint, optional, default=1
Index of canvas.
- min_rangefloat, optional, default=0
Minimum value in each axis.
- max_rangefloat, optional, default=1
Maximum value in each axis.
- Returns:
- drawing_canvasaxes.SubplotBase, or another subclass of Axes in the matplotlib library
Plotting object of matplotlib.
- show_sample_explanation(xl, xu, dict_min_point_classes, dict_max_point_classes, y_pred, type_plot='par_cord', plot_width=800, plot_height=480, min_range=0, max_range=1, file_path='par_cord.html')[source]
Show explanation for predicted results of an input pattern under the form of parallel coordinates or hyperboxes in 2D or 3D planes.
Note
This function only works on numerical features.
- Parameters:
- xlarray-like of shape (n_features,)
Lower bound of numerical features of the input pattern which needs to show explanation.
- xuarray-like of shape (n_features,)
Upper bound of numerical features of an input pattern which needs to show explanation.
- 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.
- y_predint
The predicted class of the input pattern.
- type_plotstr, optional, default=”par_cord”
Type of graph to show explanation. If the value is par_cord, a parallel coordinate is used. Otherwise, hyperboxes in 2D or 3D planes are shown.
- plot_widthint, optional, default=800
Width of the window to show parallel coordinates.
- plot_heightint, optional, default=480
Height of the window to show parallel coordinates.
- min_rangefloat, optional, default=0
Minimum value in the axes to show hyperboxes in 2D or 3D planes.
- max_rangefloat, optional, default=1
Maximum value in the axes to show hyperboxes in 2D or 3D planes.
- file_pathstr, optional, default=”par_cord.html”
Path including a file name to the location storing the parallel coordinates graph.
- Returns:
- None.