Random Forest Class

class machine_learning.randomForestClass.RandForest(name, model_dir)

Bases: object

A class used to represent a Random Forest model.

name

The name of the model.

Type:

str

model_dir

The directory where the model is stored.

Type:

str

__init__(name, model_dir)

Initializes the RandForest object with a model name and directory.

_load_model_object()

Loads the model object from the specified directory.

predict_probability(accel_data, max_displacement)

Predicts the probability of the input using the loaded model.

plot_prediction(data, labels=['Class 1', 'Class 2', 'Class 3', 'Class 4'], title='', fig_size=[6, 4], save=None, name=None)

Plots the prediction data.

static plot_prediction(data, labels=['Class 1', 'Class 2', 'Class 3', 'Class 4'], title='', fig_size=[6, 4], save=None, name=None)

Plots the prediction data.

Parameters:
  • data (array-like) – The prediction data to be plotted.

  • labels (list of str, optional) – The labels for the classes (default is [‘Class 1’, ‘Class 2’, ‘Class 3’, ‘Class 4’]).

  • title (str, optional) – The title of the plot (default is an empty string).

  • fig_size (list of int, optional) – The size of the figure (default is [6, 4]).

  • save (bool, optional) – Whether to save the plot as a file (default is None, which is equivalent to False).

  • name (str, optional) – The filename to save the plot as (default is None, which is equivalent to ‘output_class_plot’).

Notes

This method creates a bar plot of the prediction data and optionally saves it to a file if save is True. The filename is determined by the name parameter.

predict_probability(accel_data, max_displacement)

Predicts the probability of the input using the loaded model.

Parameters:
  • accel_data (array-like) – The acceleration data to be used for prediction.

  • max_displacement (array-like) – The maximum displacement data to be used for prediction.

Returns:

output – The predicted probabilities for each class.

Return type:

array

Notes

This method stacks the acceleration data and maximum displacement into a nested column array as expected by the trained model and then uses the model’s predict_proba method to generate predictions.