Home Reference Source ``import Boundaries from '@jsmlt/jsmlt/src/classification/boundaries.js'``
public class

# Boundaries

The decision boundary module calculates decision boundaries for a trained classifier on a 2-dimensional grid of points. It works by taking a classifier, predicting the output label for many points on a 2-D grid, and using the Marching Squares algorithm to calculate the decision boundaries.

#### Example:

Calculating the decision boundaries for a classifier
``````var Boundaries = new Boundaries();

var classIndexBoundaries = boundaries.calculateClassifierDecisionBoundaries(
classifier, // The classifier you've trained
51, // Number of points on the x- and y-axis (so 51 x 51 = 2,601 points in total)
);

// Depending on the classifier used, the output will look something like this:
{
"0":[               // Decision boundaries for class 0
[                 // First (and only, as binary classification) decision boundary or class 0
[-0.22, -0.96], // Point 1 of decision boundary
[-0.22, -1.00], // Point 2 of decision boundary
// <...23 more elements...>
[-0.24, -0.92],
[-0.26, -0.96]
]
],
"1":[               // Decision boundaries for class 1
[                 // First (and only, as binary classification) decision boundary or class 1
[-0.22, -1.00], // Point 1 of decision boundary
[-0.22, -0.96], // Point 2 of decision boundary
// <...82 more elements...>
[-0.20, -1.00],
[-0.22, -1.00]
]
]
}``````

## Constructor Summary

 Public Constructor public Constructor.

## Member Summary

 Public Members public features: Array> Feature list of the grid points. public predictions: Array List of classifier predictions for each grid point. public predictionsGrid: Array> Grid of classifier predictions for each grid point.

## Method Summary

 Public Methods public calculateClassifierDecisionBoundaries(classifier: jsmlt.Supervised.Classifier, resolution: Array | number, gridCoordinates: Array): Object>>> Determine decision boundaries for a specific classifier. public generateFeaturesFromLinSpaceGrid(pointsX: number, pointsY: number, boundsX: Array, boundsY: Array): Array.Array Generate a list of features from a grid of points with linear spacing public getFeatures(): Array> Obtain the features list corresponding with the grid coordinates of the last decision boundaries calculation public getGridDecisionBoundaries(grid: Array>): Object>>> Determine the decision boundaries for a grid of class predictions public getGridLevelBoundaries(grid: Array>, level: string): Array>> Determine the decision boundaries for a single grid level (class label) public Obtain the predictions list for the last decision boundaries calculation public Obtain the grid of predictions for the last decision bundaries calculation

## Public Constructors

### publicconstructor() source

Constructor. Initializes boundary object properties.

## Public Members

### publicfeatures: Array<Array<number>> source

Feature list of the grid points. n-by-2 array, where each row consists of the x- and y-coordinates of a point on the grid.

### publicpredictions: Array<mixed> source

List of classifier predictions for each grid point. The nth prediction is the prediction for the nth point in the `features` property. n-dimensional array.

### publicpredictionsGrid: Array<Array<mixed>> source

Grid of classifier predictions for each grid point. m-by-n array, where the array element at index (j, i) contains the prediction for the grid point at x-index i and y-index j. This is simply a 2-dimensional version of the `predictions` property

## Public Methods

### publiccalculateClassifierDecisionBoundaries(classifier: jsmlt.Supervised.Classifier, resolution: Array<number> | number, gridCoordinates: Array<number>): Object<string, Array<Array<Array<number>>>> source

Determine decision boundaries for a specific classifier.

#### Params:

 Name Type Attribute Description classifier jsmlt.Supervised.Classifier Classifier for which to generate the decision boundaries resolution Array | number Number of points on the x-axis and on the y-axis. Use integer for the same resolution on the x- and y-axis, and a 2-dimensional array to specify resolutions per axis gridCoordinates Array optional default: [-1, -1, 1, 1] 4-dimensional array containing, in order, the x1, y1, x2, and y2-coordinates of the grid

#### Return:

 Object>>> The returned object contains the boundaries per level (class label). Each boundary then consists of some coordinates (forming a path), and each coordinate is a 2-dimensional array where the first entry is the x-coordinate and the second entry is the y-coordinate

### publicgenerateFeaturesFromLinSpaceGrid(pointsX: number, pointsY: number, boundsX: Array<number>, boundsY: Array<number>): Array.Array<number> source

Generate a list of features from a grid of points with linear spacing

#### Params:

 Name Type Attribute Description pointsX number Number of points on the x-axis pointsY number Number of points on the y-axis boundsX Array 2-dimensional array of left and right bound on the points on the x-axis boundsY Array 2-dimensional array of left and right bound on the points on the y-axis

#### Return:

 Array.Array (pointsX * pointsY)-by-2 array, containing the coordinates of all grid points

### publicgetFeatures(): Array<Array<number>> source

Obtain the features list corresponding with the grid coordinates of the last decision boundaries calculation

#### Return:

 Array> Features for all data points (2-dimensional)

### publicgetGridDecisionBoundaries(grid: Array<Array<mixed>>): Object<string, Array<Array<Array<number>>>> source

Determine the decision boundaries for a grid of class predictions

#### Params:

 Name Type Attribute Description grid Array> Grid of predictions, an array of row arrays, where each row array contains the predictions for the cells in that row. For an m x n prediction grid, each of the m entries of `grid` should have n entries

#### Return:

 Object>>> The returned object contains the boundaries per level (class label). Each boundary then consists of some coordinates (forming a path), and each coordinate is a 2-dimensional array where the first entry is the x-coordinate and the second entry is the y-coordinate

### publicgetGridLevelBoundaries(grid: Array<Array<number>>, level: string): Array<Array<Array<number>>> source

Determine the decision boundaries for a single grid level (class label)

#### Params:

 Name Type Attribute Description grid Array> See this.getGridDecisionBoundaries@param:grid level string Level (class label) to calculate boundaries for

#### Return:

 Array>> Boundaries for this level (class label). See this.getGridDecisionBoundaries@return

### publicgetPredictions(): Array<number> source

Obtain the predictions list for the last decision boundaries calculation

#### Return:

 Array List of predicted class labels

### publicgetPredictionsGrid(): Array<Array<number>> source

Obtain the grid of predictions for the last decision bundaries calculation

#### Return:

 Array> Predicted class labels for each grid point. m-by-n array for m rows, n columns