Benchmarking Functions

Benchmarking Functions#

benchmark_ecg()#

benchmark_ecg_preprocessing(function, ecg, rpeaks=None, sampling_rate=1000)[source]#

Benchmark ECG preprocessing pipelines

Parameters:
  • function (function) – Must be a Python function which first argument is the ECG signal and which has a sampling_rate argument.

  • ecg (pd.DataFrame or str) – The path to a folder where you have an ECGs.csv file or directly its loaded DataFrame. Such file can be obtained by running THIS SCRIPT (TO COMPLETE).

  • rpeaks (pd.DataFrame or str) – The path to a folder where you have an Rpeaks.csv fils or directly its loaded DataFrame. Such file can be obtained by running THIS SCRIPT (TO COMPLETE).

  • sampling_rate (int) – The sampling frequency of ecg_signal (in Hz, i.e., samples/second). Only used if ecgs and rpeaks are single vectors.

Returns:

pd.DataFrame – A DataFrame containing the results of the benchmarking

Examples

In [1]: import neurokit2 as nk

# Define a preprocessing routine
In [2]: def function(ecg, sampling_rate):
   ...:     signal, info = nk.ecg_peaks(ecg, method="engzeemod2012", sampling_rate=sampling_rate)
   ...:     return info["ECG_R_Peaks"]
   ...: 

# Synthetic example
In [3]: ecg = nk.ecg_simulate(duration=20, sampling_rate=200)

In [4]: true_rpeaks = nk.ecg_peaks(ecg, sampling_rate=200)[1]["ECG_R_Peaks"]

In [5]: nk.benchmark_ecg_preprocessing(function, ecg, true_rpeaks, sampling_rate=200)
Out[5]: 
   Sampling_Rate  Duration    Score  Recording_Length Error
0            200   0.03125  0.01924          0.333333  None

# Example using database (commented-out)
# nk.benchmark_ecg_preprocessing(function, r"path/to/GUDB_database")