yasa.EpochByEpochAgreement.get_confusion_matrix#
- EpochByEpochAgreement.get_confusion_matrix(sleep_id=None, agg_func=None, **kwargs)[source]#
Return a
ref_hyp/obs_hypconfusion matrix from either a single session or all sessions concatenated together.- Parameters:
- sleep_idNone or a valid sleep ID
If None (default), cross-tabulation is derived from the entire group dataset. If a valid sleep ID, cross-tabulation is derived using only the reference and observed scored hypnograms from that sleep session.
- agg_funcNone or str
If None (default), group results returns a
DataFramecomplete with all individual session results. If not None, group results returns aDataFrameaggregated across sessions whereagg_funcis passed asfuncparameter inpandas.DataFrame.groupby.agg. For example, setagg_func="sum"to get a single confusion matrix across all epochs that does not take session into account.- **kwargskey, value pairs
Additional keyword arguments are passed to
sklearn.metrics.confusion_matrix.
- Returns:
- conf_matr
pandas.DataFrame A confusion matrix with stages from the reference scorer as indices and stages from the observed scorer as columns.
- conf_matr
Examples
>>> import yasa >>> ref_hyps = [yasa.simulate_hypnogram(tib=90, scorer="Rater1", seed=i) for i in range(3)] >>> obs_hyps = [h.simulate_similar(scorer="Rater2", seed=i) for i, h in enumerate(ref_hyps)] >>> ebe = yasa.EpochByEpochAgreement(ref_hyps, obs_hyps) >>> ebe.get_confusion_matrix(sleep_id=2) Rater2 WAKE N1 N2 N3 REM Rater1 WAKE 1 2 23 0 0 N1 0 9 13 0 0 N2 0 6 71 0 0 N3 0 13 42 0 0 REM 0 0 0 0 0
>>> ebe.get_confusion_matrix() Rater2 WAKE N1 N2 N3 REM sleep_id Rater1 1 WAKE 30 0 3 0 35 N1 3 2 7 0 0 N2 21 12 7 0 4 N3 0 0 0 0 0 REM 2 8 29 0 17 2 WAKE 1 2 23 0 0 N1 0 9 13 0 0 N2 0 6 71 0 0 N3 0 13 42 0 0 REM 0 0 0 0 0 3 WAKE 16 0 7 19 19 N1 0 7 2 0 5 N2 0 10 12 7 5 N3 0 0 16 11 0 REM 0 15 11 18 0
>>> ebe.get_confusion_matrix(agg_func="sum") Rater2 WAKE N1 N2 N3 REM Rater1 WAKE 47 2 33 19 54 N1 3 18 22 0 5 N2 21 28 90 7 9 N3 0 13 58 11 0 REM 2 23 40 18 17