pyepilepsy.metrics.compute_ioc
- pyepilepsy.metrics.compute_ioc(y_true: Series, y_pred: Series, threshold: float, epoch_size: float, overlap: float, preictal_duration: float, groups: Series, label_to_num: dict)
Compute the Improvement Over Chance.
The chance is a random process poisson based classifier that uses the same amount of time in warning. See notes.
- Parameters:
- y_truepd.Series
The true values.
- y_predpd.Series
The predicted values, output of the classifier/postprocessing stage.
- thresholdfloat
The threshold to use to consider a prediction as 0 or 1.
- epoch_sizefloat
The epoch size in seconds.
- overlapfloat
The overlap in seconds.
- preictal_durationfloat
The preictal duration in minutes.
- groupspd.Series
A pandas Series that has the same length as y_true and y_pred that contains the group number of each sample.
- label_to_numdict
A dictionary containing the string labels as keys and corresponding integer values.
- Returns:
- float
Improvement Over Chance
Notes
See The Statistics of a Practical Seizure Warning System for more detail. (doi:10.1088/1741-2560/5/4/004)
Examples
>>> import pandas as pd >>> import numpy as np >>> from pyepilepsy.metrics import compute_ioc >>> from datetime import datetime
>>> y_true_arr = [0, 0, 0, 0, 0, 1, 1, 7, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 7] >>> y_pred_arr = [0.1, 0.12, 0.13, 0.56, 0.7, 0.8, 0.6, 0.9, 0.2, 0.1, 0.8, 0.1, 0.2, 0.1, 0.2, 0.7, 0.6, 0.7, 0.9]
>>> datetime_index = np.hstack([ ... pd.date_range("09:00", "12:30", freq="30min", tz="Europe/Paris").to_numpy(), ... pd.date_range("14:00", "19:00", freq="30min", tz="Europe/Paris").to_numpy() ... ]) >>> y_true = pd.Series( ... data=y_true_arr, ... index=datetime_index ... ) >>> y_pred = pd.Series( ... data=y_pred_arr, ... index=datetime_index ... ) >>> groups = pd.Series( ... data=[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], ... index=datetime_index ... ) >>> compute_ioc( ... y_true=y_true, ... y_pred=y_pred, ... threshold=0.58, ... epoch_size=60*30, ... overlap=60*10, ... preictal_duration=60, ... groups=groups, ... label_to_num= {'ictal': 7, 'preictal': 1, 'interictal': 0} ... ) 0.4736842105263158