Longitudinal studies invest heavily in collecting and curating their data, yet machine learning is either left aside or applied as if every wave were an unrelated feature. We built Long-Toolkit so that experts of longitudinal studies can get their data ready, and measure fairly whether conventional or longitudinal machine learning is worth it.
Generation of synthetic longitudinal cohorts with known trends, shocks or missingness, or conversion of your own study files between CSV, Parquet and Stata.
Open the toolkitCleaning, imputation, category harmonisation, and long to wide reshaping of repeated measures.
Open the toolkitStandard and longitudinal estimators ranked all against all, under one shared protocol; or train a single estimator out of conventional or longitudinal-data-aware ones.
Open the toolkitThe predictions of a saved model, e.g., the best estimator of the benchmark, explained with SHAP values.
Open the toolkitfrom long_toolkit.data_preparation import ( StataToCsv, TrendPatterns, ) # (1) Generate a synthetic cohort, in long format TrendPatterns( n_samples=300, n_waves=4, random_state=7 ).prepare().to_csv("data/cohort_long.csv", index=False) # (2) Or convert your own study from Stata to CSV StataToCsv().prepare( input_path="data/study.dta", output_path="data/study.csv", )
from long_toolkit.data_preprocessing import PivotLongToWide # One row per participant: mood_score_w1 to _w4 PivotLongToWide().fit_preprocess( input_path="data/cohort_long.csv", output_path="data/cohort_wide.csv", id_cols=["subject_id"], time_col="wave", longitudinal_columns=["mood_score"], time_label="w", separator="_", ) # Then add the outcome to predict, e.g., outcome_class
from long_toolkit.machine_learning import ( BenchStandardAndLongitudinalML, ) # Every estimator ranked against every other one bench = BenchStandardAndLongitudinalML().fit_predict( technique="run_benchmark", input_path="data/cohort_wide.csv", target_column="outcome_class", feature_columns="mood_score_w1,mood_score_w2,mood_score_w3", feature_groups_mode="suffix", feature_groups_suffix="_w", metric_keys="f1_macro,auroc", n_splits=5, )
from long_toolkit.explainability import SHAPAnalysis # The estimator ranked first by the benchmark best = bench["runs"][0]["ranked_estimators"][0] SHAPAnalysis().fit_explain( model_path=best["model_artifact"], input_path="data/cohort_wide.csv", target_column="outcome_class", feature_columns="mood_score_w1,mood_score_w2,mood_score_w3", ) # Which waves drive its predictions
Every tool is available in two modes, which run the same Python code and write the same files: in code, through the application programming interface (API), or without code, through the command-line interface (CLI).
Import a tool, pass its parameters as keyword arguments, and chain tools in a script or a Jupyter notebook. Each tool reads and writes files on disk, so that any step can be rerun on its own.
from long_toolkit.data_preprocessing import ( MissingImputation, ) MissingImputation().fit_preprocess( technique="median_imputation", input_path="data/cohort_clean.csv", output_path="data/cohort_imputed.csv", )
Launch long-toolkit, open a stage, and fill in the form of any tool, with its defaults and hints. The command palette (:) finds any tool by name.
Machine Learning Select one to configure and run. │ Standard Machine Learning Longitudinal Machine Learning Benchmark Standard ML Benchmark Longitudinal ML Command Palette ⌁ shap analysis
Several non-longitudinal conventional machine learning and longitudinal-data-aware primitives are trained on the same splits, with the same metrics and seed, and ranked all against all: every estimator is compared with every other one, not only with a single baseline such as logistic regression.
Get Started → Long-Toolkit