.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_revalidation/full_pipeline/_03_pipeline_sl.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_revalidation_full_pipeline__03_pipeline_sl.py: .. _pipeline_val_results: Stride length estimation ======================== .. warning:: On this page you will find preliminary results for a standardized revalidation of the pipeline and all of its algorithm. The current state, **TECHNICAL EXPERIMENTATION**. Don't use these results or make any assumptions based on them. We will update this page incrementally and provide further information, as soon as the state of any of the validation steps changes. The following provides an analysis and comparison of the Mobilise-D algorithm pipeline on the `Mobilise-D Technical Validation Study (TVS) dataset `_ for the estimation of stride length (free-living). In this example, we look into the performance of the Python implementation of the pipeline compared to the reference data. We also compare the actual performance to that obtained by the original Matlab-based implementation [1]_. .. [1] Kirk, C., Küderle, A., Micó-Amigo, M.E. et al. Mobilise-D insights to estimate real-world walking speed in multiple conditions with a wearable device. Sci Rep 14, 1754 (2024). https://doi.org/10.1038/s41598-024-51766-5 .. note:: If you are interested in how these results are calculated, head over to the :ref:`processing page `. .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. code-block:: Python from typing import Optional .. GENERATED FROM PYTHON SOURCE LINES 32-35 Below the list of pipelines that are compared is shown. Note, that we use "MobGap" to refer to the reimplemented python algorithms, and the "Original Implementation" to refer to the original Matlab-based implementation. .. GENERATED FROM PYTHON SOURCE LINES 35-43 .. code-block:: Python algorithms = { "Official_MobiliseD_Pipeline": ("Mobilise-D Pipeline", "MobGap"), "EScience_MobiliseD_Pipeline": ( "Mobilise-D Pipeline", "Original Implementation", ), } .. GENERATED FROM PYTHON SOURCE LINES 44-51 The code below loads the data and prepares it for the analysis. By default, the data will be downloaded from an online repository (and cached locally). If you want to use a local copy of the data, you can set the `MOBGAP_VALIDATION_DATA_PATH` environment variable. and the `MOBGAP_VALIDATION_USE_LOCA_DATA` to `1`. The file download will print a couple log information, which can usually be ignored. You can also change the `version` parameter to load a different version of the data. .. GENERATED FROM PYTHON SOURCE LINES 51-184 .. code-block:: Python from pathlib import Path import pandas as pd from mobgap.data.validation_results import ValidationResultLoader from mobgap.utils.misc import get_env_var def format_loaded_results( values: dict[tuple[str, str], pd.DataFrame], index_cols: list[str], col_prefix_filter: Optional[str], convert_rel_error: bool = False, ) -> pd.DataFrame: formatted = ( pd.concat(values, names=["algo", "version", *index_cols]) .pipe( lambda df: df.filter(like=col_prefix_filter) if col_prefix_filter else df ) .reset_index() .assign( algo_with_version=lambda df: df["algo"] + " (" + df["version"] + ")", _combined="combined", ) ) if col_prefix_filter: formatted.columns = formatted.columns.str.removeprefix( col_prefix_filter ) if convert_rel_error: rel_cols = [c for c in formatted.columns if "rel_error" in c] formatted[rel_cols] = formatted[rel_cols] * 100 return formatted local_data_path = ( Path(get_env_var("MOBGAP_VALIDATION_DATA_PATH")) / "results" if int(get_env_var("MOBGAP_VALIDATION_USE_LOCAL_DATA", 0)) else None ) __RESULT_VERSION = "v0.11.0" loader = ValidationResultLoader( "full_pipeline", result_path=local_data_path, version=__RESULT_VERSION ) # Loading free-living data free_living_index_cols = [ "cohort", "participant_id", "time_measure", "recording", "recording_name", "recording_name_pretty", ] _free_living_results = { # Matched and aggregate/combined per-recording results for the 2.5 h free-living recordings v: loader.load_single_results(k, "free_living") for k, v in algorithms.items() } _free_living_results_raw = { # Matched per-WB results for the 2.5 h free-living recordings v: loader.load_single_csv_file(k, "free_living", "raw_matched_errors.csv") for k, v in algorithms.items() } free_living_results_combined = format_loaded_results( _free_living_results, free_living_index_cols, "combined__", convert_rel_error=True, ) free_living_results_matched = format_loaded_results( _free_living_results, free_living_index_cols, "matched__", convert_rel_error=True, ) free_living_results_matched_raw = format_loaded_results( values=_free_living_results_raw, index_cols=free_living_index_cols, col_prefix_filter=None, convert_rel_error=True, ) del _free_living_results, _free_living_results_raw # Loading laboratory data laboratory_index_cols = [ "cohort", "participant_id", "time_measure", "test", "trial", "test_name", "test_name_pretty", ] _laboratory_results = { # Matched and aggregate/combined per-recording results for the laboratory recordings v: loader.load_single_results(k, "laboratory") for k, v in algorithms.items() } _laboratory_results_raw = { # Matched per-WB results for the laboratory recordings v: loader.load_single_csv_file(k, "laboratory", "raw_matched_errors.csv") for k, v in algorithms.items() } laboratory_results_combined = format_loaded_results( _laboratory_results, laboratory_index_cols, "combined__", convert_rel_error=True, ) laboratory_results_matched = format_loaded_results( _laboratory_results, laboratory_index_cols, "matched__", convert_rel_error=True, ) laboratory_results_matched_raw = format_loaded_results( values=_laboratory_results_raw, index_cols=laboratory_index_cols, col_prefix_filter=None, convert_rel_error=True, ) del _laboratory_results, _laboratory_results_raw cohort_order = ["HA", "CHF", "COPD", "MS", "PD", "PFF"] .. GENERATED FROM PYTHON SOURCE LINES 185-193 Performance metrics ------------------- Below you can find the setup for all performance metrics that we will calculate. We only use the `single__` results for the comparison. .. note:: For the evaluation of the full pipeline performance, two types of aggregation are performed, which will be described later on in the example. .. GENERATED FROM PYTHON SOURCE LINES 193-356 .. code-block:: Python from functools import partial from mobgap.pipeline.evaluation import CustomErrorAggregations as A from mobgap.utils.df_operations import ( CustomOperation, apply_aggregations, apply_transformations, multilevel_groupby_apply_merge, ) from mobgap.utils.tables import FormatTransformer as F from mobgap.utils.tables import RevalidationInfo, revalidation_table_styles from mobgap.utils.tables import StatsFunctions as S custom_aggs_combined = [ CustomOperation( identifier=None, function=A.n_datapoints, column_name=[("n_datapoints", "all")], ), ("stride_length_m__detected", ["mean", A.conf_intervals]), ("stride_length_m__reference", ["mean", A.conf_intervals]), ("stride_length_m__error", ["mean", A.loa]), ("stride_length_m__abs_error", ["mean", A.conf_intervals]), ("stride_length_m__rel_error", ["mean", A.conf_intervals]), ("stride_length_m__abs_rel_error", ["mean", A.conf_intervals]), CustomOperation( identifier=None, function=partial( A.icc, reference_col_name="stride_length_m__reference", detected_col_name="stride_length_m__detected", icc_type="icc2", # For the lab data, some trials have no results for the old algorithms. nan_policy="omit", ), column_name=[("icc", "all"), ("icc_ci", "all")], ), ] custom_aggs_matched = [ CustomOperation( identifier=None, function=lambda df_: df_["n_matched_wbs"].sum(), column_name=[("n_wbs_matched", "all")], ), *custom_aggs_combined, ] stats_transform = [ CustomOperation( identifier=None, function=partial( S.pairwise_tests, value_col=c, between="version", reference_group_key="Original Implementation", ), column_name=[("stats_metadata", c)], ) for c in [ "stride_length_m__abs_error", "stride_length_m__abs_rel_error", ] ] format_transforms_combined = [ CustomOperation( identifier=None, function=lambda df_: df_[("n_datapoints", "all")].astype(int), column_name="n_datapoints", ), *( CustomOperation( identifier=None, function=partial( F.value_with_metadata, value_col=("mean", c), other_columns={ "range": ("conf_intervals", c), "stats_metadata": ("stats_metadata", c), }, ), column_name=c, ) for c in [ "stride_length_m__reference", "stride_length_m__detected", "stride_length_m__abs_error", "stride_length_m__rel_error", "stride_length_m__abs_rel_error", ] ), CustomOperation( identifier=None, function=partial( F.value_with_metadata, value_col=("mean", "stride_length_m__error"), other_columns={"range": ("loa", "stride_length_m__error")}, ), column_name="stride_length_m__error", ), CustomOperation( identifier=None, function=partial( F.value_with_metadata, value_col=("icc", "all"), other_columns={"range": ("icc_ci", "all")}, ), column_name="icc", ), ] format_transforms_matched = [ CustomOperation( identifier=None, function=lambda df_: df_[("n_wbs_matched", "all")].astype(int), column_name="n_wbs_matched", ), *format_transforms_combined, ] final_names_combined = { "n_datapoints": "# participants", "stride_length_m__detected": "WD mean and CI [m]", "stride_length_m__reference": "INDIP mean and CI [m]", "stride_length_m__error": "Bias and LoA [m]", "stride_length_m__abs_error": "Abs. Error [m]", "stride_length_m__rel_error": "Rel. Error [%]", "stride_length_m__abs_rel_error": "Abs. Rel. Error [%]", "icc": "ICC", } final_names_matched = { **final_names_combined, "n_wbs_matched": "# Matched WBs", } validation_thresholds = { "Abs. Error [m]": RevalidationInfo(threshold=None, higher_is_better=False), "Abs. Rel. Error [%]": RevalidationInfo( threshold=20, higher_is_better=False ), "ICC": RevalidationInfo(threshold=0.7, higher_is_better=True), } def format_tables_combined(df: pd.DataFrame) -> pd.DataFrame: return ( df.pipe(apply_transformations, format_transforms_combined) .rename(columns=final_names_combined) .loc[:, list(final_names_combined.values())] ) def format_tables_matched(df: pd.DataFrame) -> pd.DataFrame: return ( df.pipe(apply_transformations, format_transforms_matched) .rename(columns=final_names_matched) .loc[:, list(final_names_matched.values())] ) .. GENERATED FROM PYTHON SOURCE LINES 357-374 Free-living dataset ------------------- Combined/Aggregated Evaluation ****************************** To mimic actual use of wearable device where actual decisions are made on aggregated measures over a longer measurement period and not WB per WB, our primary comparison is based on the median gait metrics over the entire recording. We call this combined or aggregated evaluation. For this we combined all WBs for a datapoint by taking the median of the calculated stride length. These combined values were then compared between the systems. .. note:: In the free-living dataset, each datapoint represents one 2.5h recording. All results across all cohorts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The results below represent the average performance across all participants independent of the cohort in terms of error, relative error, absolute error, and absolute relative error. .. GENERATED FROM PYTHON SOURCE LINES 374-413 .. code-block:: Python import matplotlib.pyplot as plt import seaborn as sns sns.set_context("talk") metrics = { "abs_rel_error": "Abs. Rel. Error (%)", "error": "Error (m)", "rel_error": "Rel. Error (%)", "abs_error": "Abs. Error (m)", } def multi_metric_plot(data, metrics, nrows, ncols): fig, axs = plt.subplots( nrows, ncols, sharex=True, figsize=(ncols * 6, nrows * 4 + 2) ) for ax, (metric, metric_label) in zip(axs.flatten(), metrics.items()): overall_df = data[["version", f"stride_length_m__{metric}"]].rename( columns={f"stride_length_m__{metric}": metric_label} ) sns.boxplot( data=overall_df, x="version", hue="version", y=metric_label, ax=ax ) ax.set_title(metric_label) ax.set_ylabel(metric_label) ax.tick_params(axis="both", which="major") ax.tick_params(axis="both", which="minor") ax.grid(True) plt.tight_layout() plt.show() free_living_results_combined.pipe(multi_metric_plot, metrics, 2, 2) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_001.png :alt: Abs. Rel. Error (%), Error (m), Rel. Error (%), Abs. Error (m) :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 414-433 .. code-block:: Python free_living_combined_perf_metrics_all = free_living_results_combined.pipe( multilevel_groupby_apply_merge, [ ( ["algo", "version"], partial(apply_aggregations, aggregations=custom_aggs_combined), ), ( ["algo"], partial(apply_transformations, transformations=stats_transform), ), ], ).pipe(format_tables_combined) free_living_combined_perf_metrics_all.style.pipe( revalidation_table_styles, validation_thresholds, ["algo"], ) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.11.0/src/mobgap/utils/df_operations.py:703: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning. results = [df.groupby(key).apply(func, **apply_kwargs) for key, func in groupbys] /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.11.0/src/mobgap/utils/df_operations.py:703: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning. results = [df.groupby(key).apply(func, **apply_kwargs) for key, func in groupbys] .. raw:: html
    # participants WD mean and CI [m] INDIP mean and CI [m] Bias and LoA [m] Abs. Error [m] Rel. Error [%] Abs. Rel. Error [%] ICC
algo version                
Mobilise-D Pipeline MobGap 101 0.83 [0.80, 0.85] 0.80 [0.76, 0.84] 0.03 [-0.26, 0.33] 0.12 [0.11, 0.14]** 8.50 [3.92, 13.07] 17.71 [14.29, 21.12]** 0.55 [0.40, 0.67]
Original Implementation 101 0.94 [0.91, 0.97] 0.80 [0.76, 0.84] 0.14 [-0.14, 0.43] 0.17 [0.15, 0.19] 23.49 [18.01, 28.98] 26.08 [21.07, 31.10] 0.43 [-0.01, 0.69]


.. GENERATED FROM PYTHON SOURCE LINES 434-435 Residual plots .. GENERATED FROM PYTHON SOURCE LINES 435-467 .. code-block:: Python from mobgap.plotting import move_legend_outside, residual_plot def combo_residual_plot(data, name=None): name = name or data.name fig, axs = plt.subplots( ncols=2, sharey=True, sharex=True, figsize=(12, 9), constrained_layout=True, ) fig.suptitle(name) for (version, subdata), ax in zip(data.groupby("version"), axs): residual_plot( subdata, "stride_length_m__reference", "stride_length_m__detected", "cohort", "m", ax=ax, legend=ax == axs[-1], ) ax.set_title(version) move_legend_outside(fig, axs[-1]) plt.show() free_living_results_combined.query('algo == "Mobilise-D Pipeline"').pipe( combo_residual_plot, name="Aggregated Analysis - Stride Length" ) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_002.png :alt: Aggregated Analysis - Stride Length, MobGap, Original Implementation :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 468-473 Per-cohort analysis ~~~~~~~~~~~~~~~~~~~ The results below represent the average absolute error on stride length estimation across all participants within a cohort. .. GENERATED FROM PYTHON SOURCE LINES 473-486 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 6)) sns.boxplot( data=free_living_results_combined, x="cohort", y="stride_length_m__abs_error", hue="version", order=cohort_order, showmeans=True, ax=ax, ).legend().set_title(None) ax.set_ylabel("Absolute Error [m]") ax.set_title("Absolute Error - Combined Analysis") fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_003.png :alt: Absolute Error - Combined Analysis :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 487-509 .. code-block:: Python free_living_combined_perf_metrics_cohort = ( free_living_results_combined.pipe( multilevel_groupby_apply_merge, [ ( ["cohort", "algo", "version"], partial(apply_aggregations, aggregations=custom_aggs_combined), ), ( ["cohort", "algo"], partial(apply_transformations, transformations=stats_transform), ), ], ) .pipe(format_tables_combined) .loc[cohort_order] ) free_living_combined_perf_metrics_cohort.style.pipe( revalidation_table_styles, validation_thresholds, ["cohort", "algo"], ) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.11.0/src/mobgap/utils/df_operations.py:703: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning. results = [df.groupby(key).apply(func, **apply_kwargs) for key, func in groupbys] /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.11.0/src/mobgap/utils/df_operations.py:703: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning. results = [df.groupby(key).apply(func, **apply_kwargs) for key, func in groupbys] .. raw:: html
      # participants WD mean and CI [m] INDIP mean and CI [m] Bias and LoA [m] Abs. Error [m] Rel. Error [%] Abs. Rel. Error [%] ICC
cohort algo version                
HA Mobilise-D Pipeline MobGap 20 0.78 [0.75, 0.82] 0.81 [0.75, 0.87] -0.03 [-0.21, 0.16] 0.07 [0.05, 0.10]* -2.06 [-7.18, 3.07] 9.14 [5.94, 12.34]* 0.65 [0.31, 0.84]
Original Implementation 20 0.89 [0.84, 0.94] 0.81 [0.75, 0.87] 0.08 [-0.14, 0.29] 0.12 [0.09, 0.15] 11.31 [4.78, 17.84] 15.80 [11.55, 20.05] 0.50 [0.06, 0.77]
CHF Mobilise-D Pipeline MobGap 10 0.78 [0.70, 0.86] 0.88 [0.75, 1.00] -0.09 [-0.36, 0.17] 0.12 [0.06, 0.19] -8.62 [-17.96, 0.73] 13.75 [7.56, 19.94] 0.61 [0.05, 0.88]
Original Implementation 10 1.05 [0.94, 1.16] 0.88 [0.75, 1.00] 0.16 [-0.05, 0.38] 0.17 [0.10, 0.23] 21.39 [10.08, 32.70] 21.68 [10.61, 32.75] 0.63 [-0.10, 0.91]
COPD Mobilise-D Pipeline MobGap 17 0.85 [0.80, 0.90] 0.82 [0.75, 0.90] 0.03 [-0.22, 0.27] 0.11 [0.07, 0.14] 6.29 [-2.94, 15.52] 14.40 [7.70, 21.10] 0.57 [0.15, 0.82]
Original Implementation 17 0.95 [0.92, 0.99] 0.82 [0.75, 0.90] 0.13 [-0.12, 0.38] 0.14 [0.09, 0.19] 20.29 [7.18, 33.40] 21.26 [8.52, 33.99] 0.35 [-0.10, 0.70]
MS Mobilise-D Pipeline MobGap 18 0.91 [0.85, 0.96] 0.85 [0.76, 0.94] 0.06 [-0.30, 0.41] 0.15 [0.11, 0.20] 10.45 [-0.46, 21.35] 20.02 [12.73, 27.30] 0.33 [-0.12, 0.68]
Original Implementation 18 0.99 [0.93, 1.05] 0.85 [0.76, 0.94] 0.14 [-0.23, 0.51] 0.20 [0.14, 0.25] 20.85 [8.22, 33.47] 26.30 [16.24, 36.36] 0.24 [-0.13, 0.59]
PD Mobilise-D Pipeline MobGap 19 0.88 [0.82, 0.93] 0.80 [0.70, 0.90] 0.08 [-0.26, 0.41] 0.16 [0.12, 0.20] 15.80 [2.58, 29.01] 23.54 [13.06, 34.01] 0.50 [0.10, 0.77]
Original Implementation 19 0.97 [0.91, 1.03] 0.80 [0.70, 0.90] 0.17 [-0.18, 0.51] 0.19 [0.13, 0.26] 28.32 [12.11, 44.53] 30.92 [15.75, 46.08] 0.37 [-0.08, 0.70]
PFF Mobilise-D Pipeline MobGap 17 0.75 [0.69, 0.81] 0.64 [0.56, 0.73] 0.12 [-0.10, 0.33] 0.13 [0.08, 0.17]* 23.86 [12.38, 35.34] 24.87 [13.91, 35.82] 0.60 [-0.04, 0.86]
Original Implementation 17 0.85 [0.79, 0.91] 0.64 [0.56, 0.73] 0.22 [-0.01, 0.44] 0.22 [0.16, 0.27] 40.55 [26.04, 55.05] 40.55 [26.04, 55.05] 0.37 [-0.10, 0.76]


.. GENERATED FROM PYTHON SOURCE LINES 510-515 Scatter plot The results below represent the detected and reference values of stride length scattered across all participants within a cohort. Correlation factor, p-value and confidence intervals of the regression line are shown in the plot. Each datapoint represents one participant. .. GENERATED FROM PYTHON SOURCE LINES 515-574 .. code-block:: Python from mobgap.plotting import calc_min_max_with_margin, make_square, plot_regline def combo_scatter_plot(data, name=None): name = name or data.name fig, axs = plt.subplots( ncols=2, sharey=True, sharex=True, figsize=(12, 8), constrained_layout=True, ) fig.suptitle(name) min_max = calc_min_max_with_margin( data["stride_length_m__reference"], data["stride_length_m__detected"], ) for (version, subdata), ax in zip(data.groupby("version"), axs): subdata = subdata[ [ "stride_length_m__reference", "stride_length_m__detected", "cohort", ] ].dropna(how="any") sns.scatterplot( subdata, x="stride_length_m__reference", y="stride_length_m__detected", hue="cohort", ax=ax, legend=ax == axs[-1], ) plot_regline( subdata["stride_length_m__reference"], subdata["stride_length_m__detected"], ax=ax, ) make_square(ax, min_max, draw_diagonal=True) ax.set_title(version) ax.set_xlabel("Reference [m]") ax.set_ylabel("Detected [m]") ax.tick_params(axis="both", labelsize=20) move_legend_outside(fig, axs[-1]) plt.show() free_living_results_combined.query('algo == "Mobilise-D Pipeline"').pipe( combo_scatter_plot, name="Mobilise-D Pipeline - Stride Length" ) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_004.png :alt: Mobilise-D Pipeline - Stride Length, MobGap, Original Implementation :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 575-597 Matched/True Positive Evaluation ******************************** The "Matched" Evaluation directly compares the performance of stride length estimation on only the WBs that were detected in both systems (true positives). WBs were included in the true positive analysis, if there was an overlap of more than 80% between WBs detected by the two systems (details about the selection of this threshold can be found in [1]_). The threshold of 80% was selected as a trade-off to allow us: (i) to consider as much as possible a like-for-like comparison between selected WBs (INDIP vs. wearable device), and at the same time (ii) to include the minimum number of WBs to ensure sufficient statistical power for the analyses (i.e., at least 101 walking bouts for each cohort). This target was based upon the number of WBs rather than a percentage of total walking bouts that would allow us to meet criteria established by statistical experts for robust statistical analysis after sample-size re-evaluation (total WB number > 101 corresponding to ICC > 0.7 and a CI = 0.2). .. note:: compared to the results published in [1]_, the primary analysis on the matched results is performed on the average performance metrics across all matched WBs **per recording/per participant**. The original publication considered the average performance metrics across all matched WBs without additional aggregation. Results across all cohorts ~~~~~~~~~~~~~~~~~~~~~~~~~~ The results below represent the average performance across all participants independent of the cohort in terms of error, relative error, absolute error, and absolute relative error. .. GENERATED FROM PYTHON SOURCE LINES 597-599 .. code-block:: Python free_living_results_matched.pipe(multi_metric_plot, metrics, 2, 2) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_005.png :alt: Abs. Rel. Error (%), Error (m), Rel. Error (%), Abs. Error (m) :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 600-602 As each pipeline version produces different WB's, it is important to compare the number of matched WBs to put all other metrics into perspective. .. GENERATED FROM PYTHON SOURCE LINES 602-613 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 6)) sns.barplot( data=free_living_results_matched.groupby(["version"])["n_matched_wbs"] .sum() .reset_index(), x="version", y="n_matched_wbs", ax=ax, ) fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_006.png :alt: 03 pipeline sl :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 614-633 .. code-block:: Python free_living_matched_perf_metrics_all = free_living_results_matched.pipe( multilevel_groupby_apply_merge, [ ( ["algo", "version"], partial(apply_aggregations, aggregations=custom_aggs_matched), ), ( ["algo"], partial(apply_transformations, transformations=stats_transform), ), ], ).pipe(format_tables_matched) free_living_matched_perf_metrics_all.style.pipe( revalidation_table_styles, validation_thresholds, ["algo"], ) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.11.0/src/mobgap/utils/df_operations.py:703: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning. results = [df.groupby(key).apply(func, **apply_kwargs) for key, func in groupbys] /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.11.0/src/mobgap/utils/df_operations.py:703: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning. results = [df.groupby(key).apply(func, **apply_kwargs) for key, func in groupbys] .. raw:: html
    # participants WD mean and CI [m] INDIP mean and CI [m] Bias and LoA [m] Abs. Error [m] Rel. Error [%] Abs. Rel. Error [%] ICC # Matched WBs
algo version                  
Mobilise-D Pipeline MobGap 101 0.93 [0.90, 0.96] 0.88 [0.85, 0.92] 0.05 [-0.18, 0.27] 0.14 [0.12, 0.15]* 10.52 [7.23, 13.81] 18.81 [16.49, 21.13] 0.71 [0.55, 0.81] 1984
Original Implementation 101 1.02 [1.00, 1.05] 0.93 [0.89, 0.96] 0.10 [-0.17, 0.36] 0.16 [0.14, 0.18] 17.01 [12.36, 21.67] 22.54 [18.56, 26.53] 0.53 [0.18, 0.73] 1697


.. GENERATED FROM PYTHON SOURCE LINES 634-635 Residual plot .. GENERATED FROM PYTHON SOURCE LINES 635-638 .. code-block:: Python free_living_results_matched.query('algo == "Mobilise-D Pipeline"').pipe( combo_residual_plot, name="Matched WBs - Stride Length" ) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_007.png :alt: Matched WBs - Stride Length, MobGap, Original Implementation :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_007.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 639-644 Per-cohort analysis ~~~~~~~~~~~~~~~~~~~ Boxplot The results below represent the average absolute error on stride length estimation across all participants within a cohort. .. GENERATED FROM PYTHON SOURCE LINES 644-659 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 6)) sns.barplot( data=free_living_results_matched.groupby(["version", "cohort"])[ "n_matched_wbs" ] .sum() .reset_index(), hue="version", y="n_matched_wbs", x="cohort", order=cohort_order, ax=ax, ) fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_008.png :alt: 03 pipeline sl :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_008.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 660-672 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 6)) sns.boxplot( data=free_living_results_matched, x="cohort", y="stride_length_m__abs_error", hue="algo_with_version", order=cohort_order, ax=ax, ).legend().set_title(None) ax.set_ylabel("Absolute Error [m]") ax.set_title("Absolute Error - Matched Analysis") fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_009.png :alt: Absolute Error - Matched Analysis :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_009.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 673-674 Processing the per-cohort performance table .. GENERATED FROM PYTHON SOURCE LINES 674-697 .. code-block:: Python free_living_matched_perf_metrics_cohort = ( free_living_results_matched.pipe( multilevel_groupby_apply_merge, [ ( ["cohort", "algo", "version"], partial(apply_aggregations, aggregations=custom_aggs_matched), ), ( ["cohort", "algo"], partial(apply_transformations, transformations=stats_transform), ), ], ) .pipe(format_tables_matched) .loc[cohort_order] ) free_living_matched_perf_metrics_cohort.style.pipe( revalidation_table_styles, validation_thresholds, ["cohort", "algo"], ) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.11.0/src/mobgap/utils/df_operations.py:703: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning. results = [df.groupby(key).apply(func, **apply_kwargs) for key, func in groupbys] /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.11.0/src/mobgap/utils/df_operations.py:703: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning. results = [df.groupby(key).apply(func, **apply_kwargs) for key, func in groupbys] .. raw:: html
      # participants WD mean and CI [m] INDIP mean and CI [m] Bias and LoA [m] Abs. Error [m] Rel. Error [%] Abs. Rel. Error [%] ICC # Matched WBs
cohort algo version                  
HA Mobilise-D Pipeline MobGap 20 0.93 [0.86, 0.99] 0.90 [0.83, 0.97] 0.03 [-0.11, 0.17] 0.10 [0.09, 0.12] 7.13 [2.75, 11.51] 14.26 [11.33, 17.19] 0.88 [0.70, 0.95] 524
Original Implementation 20 1.03 [0.97, 1.08] 0.95 [0.89, 1.02] 0.07 [-0.09, 0.24] 0.12 [0.10, 0.14] 11.10 [6.28, 15.92] 15.86 [12.41, 19.31] 0.73 [0.21, 0.90] 410
CHF Mobilise-D Pipeline MobGap 10 0.96 [0.86, 1.07] 0.98 [0.86, 1.10] -0.01 [-0.16, 0.14] 0.12 [0.09, 0.15] 2.86 [-4.00, 9.72] 14.50 [9.61, 19.40] 0.92 [0.71, 0.98] 220
Original Implementation 10 1.05 [0.93, 1.16] 1.03 [0.89, 1.18] 0.01 [-0.23, 0.26] 0.13 [0.08, 0.18] 6.97 [-6.05, 19.98] 16.52 [5.88, 27.17] 0.84 [0.44, 0.96] 176
COPD Mobilise-D Pipeline MobGap 17 0.96 [0.91, 1.01] 0.86 [0.80, 0.93] 0.10 [-0.08, 0.28] 0.15 [0.12, 0.17] 15.85 [9.51, 22.19] 20.90 [16.38, 25.42] 0.52 [-0.06, 0.82] 410
Original Implementation 17 1.05 [1.00, 1.09] 0.89 [0.83, 0.95] 0.16 [-0.01, 0.33] 0.18 [0.15, 0.21] 22.93 [17.03, 28.84] 24.95 [19.88, 30.02] 0.36 [-0.10, 0.74] 323
MS Mobilise-D Pipeline MobGap 18 1.00 [0.94, 1.05] 0.91 [0.83, 0.98] 0.09 [-0.18, 0.35] 0.15 [0.12, 0.19] 15.82 [6.60, 25.04] 21.44 [14.10, 28.77] 0.47 [0.03, 0.76] 327
Original Implementation 18 1.07 [1.01, 1.13] 0.93 [0.85, 1.02] 0.13 [-0.16, 0.42] 0.18 [0.13, 0.23] 22.89 [9.08, 36.69] 27.00 [14.43, 39.58] 0.43 [-0.05, 0.75] 355
PD Mobilise-D Pipeline MobGap 19 0.94 [0.87, 1.01] 0.92 [0.84, 0.99] 0.02 [-0.27, 0.31] 0.15 [0.12, 0.18] 5.93 [-2.46, 14.31] 18.50 [13.83, 23.17] 0.60 [0.21, 0.82] 267
Original Implementation 19 1.02 [0.96, 1.08] 0.94 [0.85, 1.02] 0.08 [-0.28, 0.44] 0.17 [0.12, 0.23] 17.07 [0.92, 33.22] 25.39 [11.38, 39.41] 0.35 [-0.06, 0.68] 256
PFF Mobilise-D Pipeline MobGap 17 0.80 [0.74, 0.86] 0.75 [0.66, 0.85] 0.05 [-0.18, 0.27] 0.14 [0.11, 0.17] 13.56 [3.18, 23.94] 22.62 [14.80, 30.45] 0.75 [0.41, 0.91] 236
Original Implementation 17 0.91 [0.87, 0.95] 0.82 [0.74, 0.90] 0.09 [-0.15, 0.34] 0.16 [0.13, 0.19] 17.11 [7.75, 26.46] 23.51 [16.82, 30.21] 0.48 [-0.03, 0.80] 177


.. GENERATED FROM PYTHON SOURCE LINES 698-706 Deep dive investigation: Do errors depend on WB duration or walking speed? ************************************************************************** Effect of WB duration ~~~~~~~~~~~~~~~~~~~~~ We investigate the dependency of the absolute stride length error of all true-positive WBs from the real-world recording on the WB duration reported by the reference system. In the top, WB errors are grouped by various duration bouts. In the bottom the number of bouts within each duration group is visualized. .. GENERATED FROM PYTHON SOURCE LINES 706-763 .. code-block:: Python import numpy as np from mobgap.utils.df_operations import cut_into_overlapping_bins def plot_wb_duration_analysis(df): """Generates a single figure with: - First row: Two side-by-side boxplot for "new" and "old" cases. - Second row: A grouped bar chart comparing WB counts for "new" and "old" cases. df: DataFrame containing 'version' column with values 'new' or 'old' to distinguish data """ fig, axs = plt.subplot_mosaic( [["v"], ["v"], ["v"], ["n"]], sharex=True, figsize=(12, 9) ) # Compute WB durations in seconds df_with_durations = df.assign( duration_s=lambda df_: (df_["end__reference"] - df_["start__reference"]) / 100 ) bins = { "All": (-np.inf, np.inf), "> 10 s": (10, np.inf), "<= 10 s": (0, 10), "10 - 30 s": (10, 30), "30 - 60 s": (30, 60), "60 - 120 s": (60, 120), "> 120 s": (120, np.inf), } binned_df = cut_into_overlapping_bins( df_with_durations, "duration_s", bins ).reset_index() n = sns.countplot( data=binned_df, x="bin", hue="version", ax=axs["n"], legend=False ) for container in n.containers: n.bar_label(container, size=10) sns.boxplot( data=binned_df, x="bin", y="stride_length_m__abs_error", hue="version", ax=axs["v"], ) sns.despine(fig) axs["v"].set_ylabel("Absolute Stride Length Error (m)") axs["n"].set_ylabel("WB Count") axs["n"].set_xlabel("Ref. WB Duration") fig.show() free_living_results_matched_raw.query("algo == 'Mobilise-D Pipeline'").pipe( plot_wb_duration_analysis ) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_010.png :alt: 03 pipeline sl :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_010.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 764-771 Effect of walking_speed on error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ One important aspect of the algorithm performance is the dependency on the stride length. Aka, how well do the algorithms perform at different walking speeds. For this we plot the absolute error against the stride length of the reference data. For better granularity, we use the values per WB, instead of the aggregates per participant. The overlayed dots represent the trend-line calculated by taking the median of the absolute error within bins of 0.05 m/s. .. GENERATED FROM PYTHON SOURCE LINES 771-864 .. code-block:: Python # For plotting all participants at the end free_living_combined = free_living_results_matched_raw.copy() free_living_combined["cohort"] = "Combined" ws_level_results = pd.concat( [free_living_results_matched_raw, free_living_combined] ).reset_index(drop=True) algo_names = ws_level_results["algo_with_version"].unique() cohort_names = ws_level_results["cohort"].unique() ws_level_results["cohort"] = pd.Categorical( ws_level_results["cohort"], categories=cohort_names, ordered=True ) ws_level_results["algo_with_version"] = pd.Categorical( ws_level_results["algo_with_version"], categories=algo_names, ordered=True ) # Create the figure with subplots fig = plt.figure(constrained_layout=True, figsize=(24, 5 * len(algo_names))) subfigs = fig.subfigures(len(algo_names), 1, wspace=0.1, hspace=0.1) # Define the min and max limits for x and y axes min_max_x = calc_min_max_with_margin( ws_level_results["walking_speed_mps__reference"] ) min_max_y = calc_min_max_with_margin( ws_level_results["stride_length_m__abs_error"] ) # Plotting each algorithm version for subfig, (algo, data) in zip( subfigs, ws_level_results.groupby("algo_with_version", observed=True) ): subfig.suptitle(algo) subfig.supxlabel("Walking Speed (m/s)") subfig.supylabel("Absolute Error (m)") # Create subplots for each cohort axs = subfig.subplots(1, len(cohort_names), sharex=True, sharey=True) for ax, (cohort, cohort_data) in zip( axs, data.groupby("cohort", observed=True) ): # Scatter plot for the cohort data sns.scatterplot( data=cohort_data, x="walking_speed_mps__reference", # Reference walking speed y="stride_length_m__abs_error", # Absolute error ax=ax, alpha=0.3, ) # Define bins for walking speed bins = np.arange( 0, cohort_data["walking_speed_mps__reference"].max() + 0.05, 0.05 ) cohort_data["speed_bin"] = pd.cut( cohort_data["walking_speed_mps__reference"], bins=bins ) # Calculate bin centers cohort_data["bin_center"] = cohort_data["speed_bin"].apply( lambda x: x.mid ) # Calculate median error per bin and cohort binned_data = ( cohort_data.groupby("bin_center", observed=True)[ "stride_length_m__abs_error" ] .median() .reset_index() ) # Plot the median lines for each bin sns.scatterplot( data=binned_data, x="bin_center", y="stride_length_m__abs_error", # Median error ax=ax, ) ax.set_title(cohort) ax.set_xlabel(None) ax.set_ylabel(None) # Set axis limits ax.set_xlim(*min_max_x) ax.set_ylim(*min_max_y) fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_011.png :alt: CHF, COPD, HA, MS, PD, PFF, Combined, CHF, COPD, HA, MS, PD, PFF, Combined :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_011.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 865-882 Laboratory dataset ------------------ Combined/Aggregated Evaluation ****************************** To mimic actual use of wearable device where actual decisions are made on aggregated measures over a longer measurement period and not WB per WB, our primary comparison is based on the median gait metrics over the entire recording. We call this combined or aggregated evaluation. For this we combined all WBs for a datapoint by taking the median of the calculated stride length. These combined values were then compared between the systems. .. note:: In the laboratory dataset, each datapoint represents one trial. All results across all cohorts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The results below represent the average performance across all participants independent of the cohort in terms of error, relative error, absolute error, and absolute relative error. .. GENERATED FROM PYTHON SOURCE LINES 882-921 .. code-block:: Python import matplotlib.pyplot as plt import seaborn as sns sns.set_context("talk") metrics = { "abs_rel_error": "Abs. Rel. Error (%)", "error": "Error (m)", "rel_error": "Rel. Error (%)", "abs_error": "Abs. Error (m)", } def multi_metric_plot(data, metrics, nrows, ncols): fig, axs = plt.subplots( nrows, ncols, sharex=True, figsize=(ncols * 6, nrows * 4 + 2) ) for ax, (metric, metric_label) in zip(axs.flatten(), metrics.items()): overall_df = data[["version", f"stride_length_m__{metric}"]].rename( columns={f"stride_length_m__{metric}": metric_label} ) sns.boxplot( data=overall_df, x="version", hue="version", y=metric_label, ax=ax ) ax.set_title(metric_label) ax.set_ylabel(metric_label) ax.tick_params(axis="both", which="major") ax.tick_params(axis="both", which="minor") ax.grid(True) plt.tight_layout() plt.show() laboratory_results_combined.pipe(multi_metric_plot, metrics, 2, 2) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_012.png :alt: Abs. Rel. Error (%), Error (m), Rel. Error (%), Abs. Error (m) :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_012.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 922-942 .. code-block:: Python laboratory_combined_perf_metrics_all = laboratory_results_combined.pipe( multilevel_groupby_apply_merge, [ ( ["algo", "version"], partial(apply_aggregations, aggregations=custom_aggs_combined), ), ( ["algo"], partial(apply_transformations, transformations=stats_transform), ), ], ).pipe(format_tables_combined) laboratory_combined_perf_metrics_all.style.pipe( revalidation_table_styles, validation_thresholds, ["algo"], ) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.11.0/src/mobgap/utils/df_operations.py:703: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning. results = [df.groupby(key).apply(func, **apply_kwargs) for key, func in groupbys] /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.11.0/src/mobgap/utils/df_operations.py:703: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning. results = [df.groupby(key).apply(func, **apply_kwargs) for key, func in groupbys] .. raw:: html
    # participants WD mean and CI [m] INDIP mean and CI [m] Bias and LoA [m] Abs. Error [m] Rel. Error [%] Abs. Rel. Error [%] ICC
algo version                
Mobilise-D Pipeline MobGap 1169 1.01 [0.99, 1.02] 1.02 [1.01, 1.03] -0.03 [-0.33, 0.27] 0.12 [0.12, 0.13] -0.43 [-1.50, 0.63] 12.98 [12.22, 13.74] 0.77 [0.74, 0.80]
Original Implementation 1169 1.05 [1.04, 1.06] 1.02 [1.01, 1.03] 0.02 [-0.28, 0.33] 0.12 [0.12, 0.13] 5.91 [4.69, 7.14] 14.29 [13.32, 15.26] 0.75 [0.72, 0.78]


.. GENERATED FROM PYTHON SOURCE LINES 943-944 Residual plots .. GENERATED FROM PYTHON SOURCE LINES 944-975 .. code-block:: Python def combo_residual_plot(data, name=None): name = name or data.name fig, axs = plt.subplots( ncols=2, sharey=True, sharex=True, figsize=(12, 9), constrained_layout=True, ) fig.suptitle(name) for (version, subdata), ax in zip(data.groupby("version"), axs): residual_plot( subdata, "stride_length_m__reference", "stride_length_m__detected", "cohort", "m", ax=ax, legend=ax == axs[-1], ) ax.set_title(version) move_legend_outside(fig, axs[-1]) plt.show() laboratory_results_combined.query('algo == "Mobilise-D Pipeline"').pipe( combo_residual_plot, name="Aggregated Analysis - Stride Length" ) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_013.png :alt: Aggregated Analysis - Stride Length, MobGap, Original Implementation :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_013.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 976-981 Per-cohort analysis ~~~~~~~~~~~~~~~~~~~ The results below represent the average absolute error on stride length estimation across all participants within a cohort. .. GENERATED FROM PYTHON SOURCE LINES 981-994 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 6)) sns.boxplot( data=laboratory_results_combined, x="cohort", y="stride_length_m__abs_error", hue="version", order=cohort_order, showmeans=True, ax=ax, ).legend().set_title(None) ax.set_ylabel("Absolute Error [m]") ax.set_title("Absolute Error - Combined Analysis") fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_014.png :alt: Absolute Error - Combined Analysis :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_014.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 995-1017 .. code-block:: Python laboratory_combined_perf_metrics_cohort = ( laboratory_results_combined.pipe( multilevel_groupby_apply_merge, [ ( ["cohort", "algo", "version"], partial(apply_aggregations, aggregations=custom_aggs_combined), ), ( ["cohort", "algo"], partial(apply_transformations, transformations=stats_transform), ), ], ) .pipe(format_tables_combined) .loc[cohort_order] ) laboratory_combined_perf_metrics_cohort.style.pipe( revalidation_table_styles, validation_thresholds, ["cohort", "algo"], ) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.11.0/src/mobgap/utils/df_operations.py:703: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning. results = [df.groupby(key).apply(func, **apply_kwargs) for key, func in groupbys] /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.11.0/src/mobgap/utils/df_operations.py:703: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning. results = [df.groupby(key).apply(func, **apply_kwargs) for key, func in groupbys] .. raw:: html
      # participants WD mean and CI [m] INDIP mean and CI [m] Bias and LoA [m] Abs. Error [m] Rel. Error [%] Abs. Rel. Error [%] ICC
cohort algo version                
HA Mobilise-D Pipeline MobGap 227 1.03 [1.00, 1.05] 1.08 [1.05, 1.10] -0.06 [-0.35, 0.23] 0.12 [0.11, 0.14] -4.88 [-6.77, -2.99] 11.78 [10.51, 13.06] 0.67 [0.52, 0.76]
Original Implementation 227 1.05 [1.03, 1.08] 1.08 [1.05, 1.10] -0.02 [-0.30, 0.27] 0.11 [0.10, 0.13] -0.24 [-2.14, 1.67] 11.09 [9.85, 12.34] 0.68 [0.59, 0.75]
CHF Mobilise-D Pipeline MobGap 106 1.02 [0.97, 1.06] 1.10 [1.06, 1.15] -0.11 [-0.44, 0.21] 0.14 [0.12, 0.17] -9.01 [-11.48, -6.54] 12.25 [10.37, 14.14] 0.66 [0.32, 0.82]
Original Implementation 106 1.12 [1.08, 1.16] 1.10 [1.06, 1.15] -0.03 [-0.33, 0.27] 0.12 [0.10, 0.14] -0.72 [-3.66, 2.21] 10.85 [8.77, 12.92] 0.76 [0.65, 0.84]
COPD Mobilise-D Pipeline MobGap 214 1.04 [1.02, 1.07] 1.09 [1.07, 1.12] -0.05 [-0.34, 0.23] 0.12 [0.11, 0.13] -3.82 [-5.83, -1.81] 11.42 [10.03, 12.81] 0.60 [0.47, 0.71]
Original Implementation 214 1.10 [1.08, 1.12] 1.09 [1.07, 1.12] 0.02 [-0.24, 0.28] 0.10 [0.09, 0.11] 3.04 [1.21, 4.87] 9.87 [8.55, 11.19] 0.69 [0.60, 0.77]
MS Mobilise-D Pipeline MobGap 228 1.06 [1.03, 1.09] 1.04 [1.01, 1.07] 0.01 [-0.27, 0.28] 0.11 [0.10, 0.12] 2.43 [0.36, 4.50] 11.82 [10.40, 13.24] 0.80 [0.74, 0.84]
Original Implementation 228 1.08 [1.06, 1.11] 1.04 [1.01, 1.07] 0.03 [-0.28, 0.34] 0.13 [0.11, 0.14] 5.55 [3.11, 7.99] 13.87 [12.08, 15.67] 0.70 [0.62, 0.76]
PD Mobilise-D Pipeline MobGap 225 1.01 [0.98, 1.04] 1.00 [0.97, 1.03] -0.02 [-0.31, 0.27] 0.12 [0.11, 0.13] -0.02 [-2.21, 2.17] 12.90 [11.50, 14.30] 0.77 [0.71, 0.82]
Original Implementation 225 1.06 [1.03, 1.09] 1.00 [0.97, 1.03] 0.04 [-0.28, 0.35] 0.13 [0.11, 0.14] 6.19 [3.71, 8.68] 14.20 [12.36, 16.03] 0.72 [0.64, 0.79]
PFF Mobilise-D Pipeline MobGap 169 0.85 [0.81, 0.88] 0.82 [0.78, 0.87] 0.02 [-0.27, 0.31] 0.12 [0.10, 0.13]** 8.93 [4.82, 13.04] 18.01 [14.65, 21.36]* 0.84 [0.79, 0.88]
Original Implementation 169 0.90 [0.87, 0.93] 0.82 [0.78, 0.87] 0.07 [-0.25, 0.40] 0.15 [0.13, 0.16] 17.91 [12.92, 22.89] 23.80 [19.41, 28.19] 0.77 [0.64, 0.85]


.. GENERATED FROM PYTHON SOURCE LINES 1018-1022 Scatter plot The results below represent the detected and reference values of stride length scattered across all participants within a cohort. Correlation factor, p-value and confidence intervals of the regression line are shown in the plot. Each datapoint represents one participant. .. GENERATED FROM PYTHON SOURCE LINES 1022-1081 .. code-block:: Python from mobgap.plotting import calc_min_max_with_margin def combo_scatter_plot(data, name=None): name = name or data.name fig, axs = plt.subplots( ncols=2, sharey=True, sharex=True, figsize=(12, 8), constrained_layout=True, ) fig.suptitle(name) min_max = calc_min_max_with_margin( data["stride_length_m__reference"], data["stride_length_m__detected"], ) for (version, subdata), ax in zip(data.groupby("version"), axs): subdata = subdata[ [ "stride_length_m__reference", "stride_length_m__detected", "cohort", ] ].dropna(how="any") sns.scatterplot( subdata, x="stride_length_m__reference", y="stride_length_m__detected", hue="cohort", ax=ax, legend=ax == axs[-1], ) plot_regline( subdata["stride_length_m__reference"], subdata["stride_length_m__detected"], ax=ax, ) make_square(ax, min_max, draw_diagonal=True) ax.set_title(version) ax.set_xlabel("Reference [m]") ax.set_ylabel("Detected [m]") ax.tick_params(axis="both", labelsize=20) move_legend_outside(fig, axs[-1]) plt.show() laboratory_results_combined.query('algo == "Mobilise-D Pipeline"').pipe( combo_scatter_plot, name="Mobilise-D Pipeline - Stride Length" ) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_015.png :alt: Mobilise-D Pipeline - Stride Length, MobGap, Original Implementation :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_015.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 1082-1104 Matched/True Positive Evaluation ******************************** The "Matched" Evaluation directly compares the performance of stride length estimation on only the WBs that were detected in both systems (true positives). WBs were included in the true positive analysis, if there was an overlap of more than 80% between WBs detected by the two systems (details about the selection of this threshold can be found in [1]_). The threshold of 80% was selected as a trade-off to allow us: (i) to consider as much as possible a like-for-like comparison between selected WBs (INDIP vs. wearable device), and at the same time (ii) to include the minimum number of WBs to ensure sufficient statistical power for the analyses (i.e., at least 101 walking bouts for each cohort). This target was based upon the number of WBs rather than a percentage of total walking bouts that would allow us to meet criteria established by statistical experts for robust statistical analysis after sample-size re-evaluation (total WB number > 101 corresponding to ICC > 0.7 and a CI = 0.2). .. note:: compared to the results published in [1]_, the primary analysis on the matched results is performed on the average performance metrics across all matched WBs **per trial**. The original publication considered the average performance metrics across all matched WBs without additional aggregation. Results across all cohorts ~~~~~~~~~~~~~~~~~~~~~~~~~~ The results below represent the average performance across all participants independent of the cohort in terms of error, relative error, absolute error, and absolute relative error. .. GENERATED FROM PYTHON SOURCE LINES 1104-1106 .. code-block:: Python laboratory_results_matched.pipe(multi_metric_plot, metrics, 2, 2) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_016.png :alt: Abs. Rel. Error (%), Error (m), Rel. Error (%), Abs. Error (m) :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_016.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 1107-1109 As each pipeline version produces different WB's, it is important to compare the number of matched WBs to put all other metrics into perspective. .. GENERATED FROM PYTHON SOURCE LINES 1109-1120 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 6)) sns.barplot( data=laboratory_results_matched.groupby(["version"])["n_matched_wbs"] .sum() .reset_index(), x="version", y="n_matched_wbs", ax=ax, ) fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_017.png :alt: 03 pipeline sl :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_017.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 1121-1140 .. code-block:: Python laboratory_matched_perf_metrics_all = laboratory_results_matched.pipe( multilevel_groupby_apply_merge, [ ( ["algo", "version"], partial(apply_aggregations, aggregations=custom_aggs_matched), ), ( ["algo"], partial(apply_transformations, transformations=stats_transform), ), ], ).pipe(format_tables_matched) laboratory_matched_perf_metrics_all.style.pipe( revalidation_table_styles, validation_thresholds, ["algo"], ) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.11.0/src/mobgap/utils/df_operations.py:703: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning. results = [df.groupby(key).apply(func, **apply_kwargs) for key, func in groupbys] /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.11.0/src/mobgap/utils/df_operations.py:703: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning. results = [df.groupby(key).apply(func, **apply_kwargs) for key, func in groupbys] .. raw:: html
    # participants WD mean and CI [m] INDIP mean and CI [m] Bias and LoA [m] Abs. Error [m] Rel. Error [%] Abs. Rel. Error [%] ICC # Matched WBs
algo version                  
Mobilise-D Pipeline MobGap 1169 0.99 [0.98, 1.00] 0.99 [0.98, 1.00] 0.00 [-0.24, 0.25] 0.10 [0.09, 0.10]** 2.47 [1.48, 3.47] 11.45 [10.68, 12.21] 0.83 [0.80, 0.85] 675
Original Implementation 1169 1.06 [1.05, 1.07] 1.03 [1.02, 1.04] 0.03 [-0.25, 0.31] 0.11 [0.11, 0.12] 5.29 [4.21, 6.36] 12.61 [11.75, 13.46] 0.75 [0.71, 0.78] 715


.. GENERATED FROM PYTHON SOURCE LINES 1141-1142 Residual plot .. GENERATED FROM PYTHON SOURCE LINES 1142-1145 .. code-block:: Python laboratory_results_matched.query('algo == "Mobilise-D Pipeline"').pipe( combo_residual_plot, name="Matched WBs - Stride Length" ) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_018.png :alt: Matched WBs - Stride Length, MobGap, Original Implementation :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_018.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 1146-1151 Per-cohort analysis ~~~~~~~~~~~~~~~~~~~ Boxplot The results below represent the average absolute error on stride length estimation across all participants within a cohort. .. GENERATED FROM PYTHON SOURCE LINES 1151-1166 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 6)) sns.barplot( data=laboratory_results_matched.groupby(["version", "cohort"])[ "n_matched_wbs" ] .sum() .reset_index(), hue="version", y="n_matched_wbs", x="cohort", order=cohort_order, ax=ax, ) fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_019.png :alt: 03 pipeline sl :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_019.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 1167-1179 .. code-block:: Python fig, ax = plt.subplots(figsize=(12, 6)) sns.boxplot( data=laboratory_results_matched, x="cohort", y="stride_length_m__abs_error", hue="algo_with_version", order=cohort_order, ax=ax, ).legend().set_title(None) ax.set_ylabel("Absolute Error [m]") ax.set_title("Absolute Error - Matched Analysis") fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_020.png :alt: Absolute Error - Matched Analysis :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_020.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 1180-1181 Processing the per-cohort performance table .. GENERATED FROM PYTHON SOURCE LINES 1181-1204 .. code-block:: Python laboratory_matched_perf_metrics_cohort = ( laboratory_results_matched.pipe( multilevel_groupby_apply_merge, [ ( ["cohort", "algo", "version"], partial(apply_aggregations, aggregations=custom_aggs_matched), ), ( ["cohort", "algo"], partial(apply_transformations, transformations=stats_transform), ), ], ) .pipe(format_tables_matched) .loc[cohort_order] ) laboratory_matched_perf_metrics_cohort.style.pipe( revalidation_table_styles, validation_thresholds, ["cohort", "algo"], ) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.11.0/src/mobgap/utils/df_operations.py:703: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning. results = [df.groupby(key).apply(func, **apply_kwargs) for key, func in groupbys] /home/docs/checkouts/readthedocs.org/user_builds/mobgap/checkouts/v0.11.0/src/mobgap/utils/df_operations.py:703: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning. results = [df.groupby(key).apply(func, **apply_kwargs) for key, func in groupbys] .. raw:: html
      # participants WD mean and CI [m] INDIP mean and CI [m] Bias and LoA [m] Abs. Error [m] Rel. Error [%] Abs. Rel. Error [%] ICC # Matched WBs
cohort algo version                  
HA Mobilise-D Pipeline MobGap 227 1.02 [0.99, 1.04] 1.00 [0.97, 1.03] 0.01 [-0.21, 0.24] 0.09 [0.08, 0.10] 3.95 [1.67, 6.22] 10.94 [9.09, 12.78] 0.85 [0.78, 0.91] 80
Original Implementation 227 1.07 [1.05, 1.09] 1.05 [1.02, 1.07] 0.03 [-0.22, 0.27] 0.10 [0.09, 0.11] 3.19 [1.51, 4.88] 9.85 [8.68, 11.01] 0.74 [0.64, 0.82] 102
CHF Mobilise-D Pipeline MobGap 106 0.95 [0.91, 0.99] 1.00 [0.96, 1.04] -0.05 [-0.25, 0.16] 0.08 [0.07, 0.10] -4.02 [-6.07, -1.97] 8.45 [6.93, 9.97] 0.84 [0.71, 0.91] 53
Original Implementation 106 1.09 [1.05, 1.12] 1.13 [1.09, 1.18] -0.04 [-0.35, 0.26] 0.12 [0.10, 0.14] -1.51 [-4.78, 1.75] 11.17 [8.68, 13.66] 0.73 [0.57, 0.83] 60
COPD Mobilise-D Pipeline MobGap 214 1.07 [1.05, 1.10] 1.07 [1.04, 1.09] 0.01 [-0.18, 0.19] 0.08 [0.07, 0.08] 1.40 [0.04, 2.76] 7.71 [6.80, 8.62] 0.85 [0.78, 0.90] 93
Original Implementation 214 1.13 [1.10, 1.15] 1.08 [1.06, 1.11] 0.04 [-0.16, 0.24] 0.08 [0.07, 0.09] 4.99 [3.21, 6.77] 8.47 [6.95, 9.99] 0.78 [0.66, 0.86] 106
MS Mobilise-D Pipeline MobGap 228 1.04 [1.02, 1.06] 1.02 [1.00, 1.05] 0.02 [-0.25, 0.28] 0.11 [0.10, 0.12]* 3.76 [1.18, 6.34] 12.16 [10.05, 14.26] 0.75 [0.67, 0.81] 176
Original Implementation 228 1.08 [1.06, 1.10] 1.05 [1.02, 1.07] 0.03 [-0.28, 0.34] 0.13 [0.11, 0.14] 5.27 [2.92, 7.61] 13.43 [11.72, 15.15] 0.63 [0.52, 0.71] 182
PD Mobilise-D Pipeline MobGap 225 0.98 [0.96, 1.01] 1.01 [0.98, 1.03] -0.02 [-0.29, 0.24] 0.11 [0.10, 0.12] -0.41 [-2.40, 1.57] 11.85 [10.59, 13.11] 0.77 [0.69, 0.83] 151
Original Implementation 225 1.06 [1.03, 1.08] 1.04 [1.01, 1.07] 0.02 [-0.27, 0.30] 0.12 [0.11, 0.13] 4.31 [2.01, 6.61] 12.80 [11.11, 14.50] 0.73 [0.63, 0.80] 142
PFF Mobilise-D Pipeline MobGap 169 0.86 [0.83, 0.89] 0.84 [0.80, 0.88] 0.02 [-0.23, 0.27] 0.10 [0.09, 0.11]* 6.98 [3.77, 10.18] 14.62 [12.07, 17.17] 0.85 [0.79, 0.89] 122
Original Implementation 169 0.93 [0.91, 0.96] 0.88 [0.84, 0.92] 0.05 [-0.24, 0.35] 0.13 [0.11, 0.14] 11.86 [7.80, 15.92] 18.00 [14.49, 21.50] 0.77 [0.67, 0.85] 123


.. GENERATED FROM PYTHON SOURCE LINES 1205-1213 Deep dive investigation: Do errors depend on WB duration or walking speed? ************************************************************************** Effect of WB duration ~~~~~~~~~~~~~~~~~~~~~ We investigate the dependency of the absolute stride length error of all true-positive WBs from the real-world recording on the WB duration reported by the reference system. In the top, WB errors are grouped by various duration bouts. In the bottom the number of bouts within each duration group is visualized. .. GENERATED FROM PYTHON SOURCE LINES 1213-1269 .. code-block:: Python import numpy as np def plot_wb_duration_analysis(df): """Generates a single figure with: - First row: Two side-by-side boxplot for "new" and "old" cases. - Second row: A grouped bar chart comparing WB counts for "new" and "old" cases. df: DataFrame containing 'version' column with values 'new' or 'old' to distinguish data """ fig, axs = plt.subplot_mosaic( [["v"], ["v"], ["v"], ["n"]], sharex=True, figsize=(12, 9) ) # Compute WB durations in seconds df_with_durations = df.assign( duration_s=lambda df_: (df_["end__reference"] - df_["start__reference"]) / 100 ) bins = { "All": (-np.inf, np.inf), "> 10 s": (10, np.inf), "<= 10 s": (0, 10), "10 - 30 s": (10, 30), "30 - 60 s": (30, 60), "60 - 120 s": (60, 120), "> 120 s": (120, np.inf), } binned_df = cut_into_overlapping_bins( df_with_durations, "duration_s", bins ).reset_index() n = sns.countplot( data=binned_df, x="bin", hue="version", ax=axs["n"], legend=False ) for container in n.containers: n.bar_label(container, size=10) sns.boxplot( data=binned_df, x="bin", y="stride_length_m__abs_error", hue="version", ax=axs["v"], ) sns.despine(fig) axs["v"].set_ylabel("Absolute Stride Length Error (m)") axs["n"].set_ylabel("WB Count") axs["n"].set_xlabel("Ref. WB Duration") fig.show() laboratory_results_matched_raw.query("algo == 'Mobilise-D Pipeline'").pipe( plot_wb_duration_analysis ) .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_021.png :alt: 03 pipeline sl :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_021.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 1270-1277 Effect of walking_speed on error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ One important aspect of the algorithm performance is the dependency on the stride length. Aka, how well do the algorithms perform at different walking speeds. For this we plot the absolute error against the stride length of the reference data. For better granularity, we use the values per WB, instead of the aggregates per participant. The overlayed dots represent the trend-line calculated by taking the median of the absolute error within bins of 0.05 m/s. .. GENERATED FROM PYTHON SOURCE LINES 1277-1369 .. code-block:: Python # For plotting all participants at the end laboratory_combined = laboratory_results_matched_raw.copy() laboratory_combined["cohort"] = "Combined" ws_level_results = pd.concat( [laboratory_results_matched_raw, laboratory_combined] ).reset_index(drop=True) algo_names = ws_level_results["algo_with_version"].unique() cohort_names = ws_level_results["cohort"].unique() ws_level_results["cohort"] = pd.Categorical( ws_level_results["cohort"], categories=cohort_names, ordered=True ) ws_level_results["algo_with_version"] = pd.Categorical( ws_level_results["algo_with_version"], categories=algo_names, ordered=True ) # Create the figure with subplots fig = plt.figure(constrained_layout=True, figsize=(24, 5 * len(algo_names))) subfigs = fig.subfigures(len(algo_names), 1, wspace=0.1, hspace=0.1) # Define the min and max limits for x and y axes min_max_x = calc_min_max_with_margin( ws_level_results["walking_speed_mps__reference"] ) min_max_y = calc_min_max_with_margin( ws_level_results["stride_length_m__abs_error"] ) # Plotting each algorithm version for subfig, (algo, data) in zip( subfigs, ws_level_results.groupby("algo_with_version", observed=True) ): subfig.suptitle(algo) subfig.supxlabel("Walking Speed (m/s)") subfig.supylabel("Absolute Error (m)") # Create subplots for each cohort axs = subfig.subplots(1, len(cohort_names), sharex=True, sharey=True) for ax, (cohort, cohort_data) in zip( axs, data.groupby("cohort", observed=True) ): # Scatter plot for the cohort data sns.scatterplot( data=cohort_data, x="walking_speed_mps__reference", # Reference walking speed y="stride_length_m__abs_error", # Absolute error ax=ax, alpha=0.3, ) # Define bins for walking speed bins = np.arange( 0, cohort_data["walking_speed_mps__reference"].max() + 0.05, 0.05 ) cohort_data["speed_bin"] = pd.cut( cohort_data["walking_speed_mps__reference"], bins=bins ) # Calculate bin centers cohort_data["bin_center"] = cohort_data["speed_bin"].apply( lambda x: x.mid ) # Calculate median error per bin and cohort binned_data = ( cohort_data.groupby("bin_center", observed=True)[ "stride_length_m__abs_error" ] .median() .reset_index() ) # Plot the median lines for each bin sns.scatterplot( data=binned_data, x="bin_center", y="stride_length_m__abs_error", # Median error ax=ax, ) ax.set_title(cohort) ax.set_xlabel(None) ax.set_ylabel(None) # Set axis limits ax.set_xlim(*min_max_x) ax.set_ylim(*min_max_y) fig.show() .. image-sg:: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_022.png :alt: CHF, COPD, HA, MS, PD, PFF, Combined, CHF, COPD, HA, MS, PD, PFF, Combined :srcset: /auto_revalidation/full_pipeline/images/sphx_glr__03_pipeline_sl_022.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 20.336 seconds) **Estimated memory usage:** 82 MB .. _sphx_glr_download_auto_revalidation_full_pipeline__03_pipeline_sl.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: _03_pipeline_sl.ipynb <_03_pipeline_sl.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: _03_pipeline_sl.py <_03_pipeline_sl.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: _03_pipeline_sl.zip <_03_pipeline_sl.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_