A class that represents a RandomForest factory, for training and saving. The training can be done multiple times if epoch is strictly greater than 1, but it is not relevant since it resets the trees.
Data must be 2d arrays, so the code reshapes data to have bigger chunks and remove one dimension.

Hierarchy

Constructors

Properties

batchSize: number
consoleInfo: boolean
epoch: number
nameToLoad: string
nameToSave: string
randomForest: RandomForestClassifier
useTfjsVis: boolean

Methods

  • Gets a sample of test data and returns the model output, with some basic operations to reshape the output as 1d tensor.

    Returns

    A list of two elements that are 1d tensors corresponding to a list [b1, b2, ...]. These two list are 0-1 lists for each batch element to be a bot trajectory (1 means bot).

    Parameters

    • size: number = 1000

      The batch size for the sample.

    Returns Tensor1D[]

  • Get prediction and labels and return the accuracy per class.

    Parameters

    • predicts: Tensor1D

      The model prediction reshaped as 1D tensor of 0 (human) or 1 (bot).

    • labels: Tensor1D

      The true labels, 1d tensor of 0 or 1.

    Returns Promise<{
        accuracy: number;
        count: number;
    }[]>

  • Get prediction and labels and return the confusion matrix.

    Parameters

    • predicts: Tensor1D

      The model prediction reshaped as 1D tensor of 0 (human) or 1 (bot).

    • labels: Tensor1D

      The true labels, 1d tensor of 0 or 1.

    Returns Promise<number[][]>

  • Run the entire model logic, including loading (if nameToLoad is not null), load all data, train the model, save it (if nameToSave is not null), test it and show all additional information with tfjs-vis or in the console.

    Returns Promise<void>

  • Get the model prediction batch and its corresponding labels as 1D tensors and show with tfjs-vis or in console (according to useTfjsVis and consoleInfo) the accuracy of each class and the confusion matrix.

    Parameters

    • predicts: Tensor1D

      The model prediction reshaped as 1D tensor of 0 (human) or 1 (bot).

    • labels: Tensor1D

      The true labels, 1d tensor of 0 or 1.

    • name: string = "validation"

      Default to "validation", used in the container name of tfjs-vis.

    Returns Promise<void>

Generated using TypeDoc