biosppy.ml.utils_ml

biosppy.ml.utils

This module provides utility classes and functions for Keras-based models, which can be used for various machine learning tasks with biosignals, such as classification, segmentation and anomaly detection.

copyright:
  1. 2015-2026 by Instituto de Telecomunicacoes

license:

BSD 3-clause, see LICENSE for more details.

Classes

KerasClassifier(model_path, details_path[, ...])

A wrapper for Keras models to perform classification tasks.

class biosppy.ml.utils_ml.KerasClassifier(model_path, details_path, scaler_path=None)[source]

Bases: ABC

A wrapper for Keras models to perform classification tasks.

This class loads a Keras model and an optional scaler, and provides methods for preprocessing input signals and making predictions. It also supports loading additional details such as label mappings and sampling rates from a JSON file.

Parameters:
  • model_path (str) – Path to the Keras model file.

  • details_path (str) – Path to a JSON file containing the model details such as label map and sampling rate.

  • scaler_path (str, optional) – Path to a scaler file (e.g., joblib file) for scaling input data. Default is None.

predict(signal, sampling_rate=1000.0, **kwargs)[source]
preprocess_signal(signal, sampling_rate=1000.0)[source]

Preprocess the input signal based on the model’s requirements, such as scaling and resampling.

Parameters:
  • signal (array-like) – The input signal to preprocess.

  • sampling_rate (float, optional) – The sampling rate of the input signal. Default is 1000.0 Hz.

Returns:

X (array-like) – The preprocessed signal ready for prediction.