OSCR

Benchmarking speech biomarkers of Alzheimer's against cognitive and neural measures.

Code ↔ Paper

1 match between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 1 match
  1. [1] § METHODS › Machine learning ↔ Scripts/train_models_bayes.py, lines 30–65 · score 0.89 · Bayesian optimization, outer loop, inner loop, parallel processing, cross validation, iterations

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Python · 503 lines · 28 KB · no license · 1 match

  1. import numpy as np
  2. import pandas as pd
  3. from pathlib import Path
  4. from sklearn.model_selection import StratifiedKFold, KFold, LeaveOneOut, StratifiedShuffleSplit, ShuffleSplit
  5. from sklearn.linear_model import LogisticRegression as LR
  6. from sklearn.svm import SVC, SVR
  7. from sklearn.neighbors import KNeighborsClassifier as KNNC
  8. from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
  9. from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis as QDA
  10. from sklearn.linear_model import Lasso, Ridge, ElasticNet
  11. from sklearn.neighbors import KNeighborsRegressor as KNNR
  12. from sklearn.naive_bayes import GaussianNB
  13. from sklearn.model_selection import train_test_split
  14. from sklearn.preprocessing import MinMaxScaler,StandardScaler
  15. from sklearn.impute import KNNImputer
  16. from xgboost import XGBClassifier as xgboost
  17. from xgboost import XGBRegressor as xgboostr
  18. import itertools,pickle,sys, json
  19. import logging,sys,os,argparse
  20. from psrcal.calibration import AffineCalLogLoss
  21. from sklearn.preprocessing import LabelEncoder
  22. sys.path.append(str(Path(Path.home(),'scripts_generales'))) if 'Users/gp' in str(Path.home()) else sys.path.append(str(Path(Path.home(),'user','scripts_generales')))
  23. import utils
  24. from expected_cost.ec import CostMatrix
  25. ##---------------------------------PARAMETERS---------------------------------##
  26. def parse_args():
  27. parser = argparse.ArgumentParser(
  28. description='Train models with hyperparameter optimization and feature selection'
  29. )
  30. parser.add_argument('--project_name', default='crossling_mci',type=str,help='Project name')
  31. parser.add_argument('--stats', type=str, default='', help='Stats to be considered (default = all)')
  32. parser.add_argument('--shuffle_labels', type=int, default=0, help='Shuffle labels flag (1 or 0)')
  33. parser.add_argument('--stratify', type=int, default=1, help='Stratification flag (1 or 0)')
  34. parser.add_argument('--calibrate', type=int, default=0, help='Whether to calibrate models')
  35. parser.add_argument('--n_folds_outer', type=float, default=5, help='Number of folds for cross validation (outer loop)')
  36. parser.add_argument('--n_folds_inner', type=float, default=5, help='Number of folds for cross validation (inner loop)')
  37. parser.add_argument('--n_iter', type=int, default=20, help='Number of hyperparameter iterations')
  38. parser.add_argument('--init_points', type=int, default=20, help='Number of random initial points to test during Bayesian optimization')
  39. parser.add_argument('--feature_selection',type=int,default=1,help='Whether to perform feature selection with RFE or not')
  40. parser.add_argument('--fill_na',type=int,default=0,help='Values to fill nan with. Default (=0) means no filling (imputing instead)')
  41. parser.add_argument('--n_seeds_train',type=int,default=10,help='Number of seeds for cross-validation training')
  42. parser.add_argument('--n_seeds_shuffle',type=int,default=1,help='Number of seeds for shuffling')
  43. parser.add_argument('--scaler_name', type=str, default='StandardScaler', help='Scaler name')
  44. parser.add_argument('--id_col', type=str, default='id', help='ID column name')
  45. parser.add_argument('--n_boot',type=int,default=1000,help='Number of bootstrap iterations')
  46. parser.add_argument('--n_boot_train',type=int,default=0,help='Number of bootstrap iterations for training')
  47. parser.add_argument('--n_boot_test',type=int,default=1000,help='Number of bootstrap iterations for testing')
  48. parser.add_argument('--shuffle_all',type=int,default=1,help='Whether to shuffle all models or only the best ones')
  49. parser.add_argument('--filter_outliers',type=int,default=0,help='Whether to filter outliers in regression problems')
  50. parser.add_argument('--early_fusion',type=int,default=1,help='Whether to perform early fusion')
  51. parser.add_argument('--overwrite',type=int,default=0,help='Whether to overwrite past results or not')
  52. parser.add_argument('--parallel',type=int,default=0,help='Whether to parallelize processes or not')
  53. parser.add_argument('--n_seeds_test',type=int,default=1,help='Number of seeds for testing')
  54. parser.add_argument('--bootstrap_method',type=str,default='bca',help='Bootstrap method [bca, percentile, basic]')
  55. parser.add_argument('--round_values',type=int,default=0,help='Whether to round predicted values for regression or not')
  56. parser.add_argument('--add_dem',type=int,default=0,help='Whether to add demographic features or not')
  57. parser.add_argument('--cut_values',type=float,default=-1,help='Cut values above a given threshold')
  58. parser.add_argument('--regress_out',type=str,default='',help='List of demographic variables to regress out from target variable, separated by "_"')
  59. parser.add_argument('--regress_out_method',type=str,default='linear',help='Whether to perform linear or non-linear regress-out')
  60. return parser.parse_args()
  61. def load_configuration(args):
  62. # Global configuration dictionaries
  63. config = dict(
  64. project_name = args.project_name,
  65. stats = str(args.stats),
  66. shuffle_labels = bool(args.shuffle_labels),
  67. shuffle_all = bool(args.shuffle_all),
  68. stratify = bool(args.stratify),
  69. calibrate = bool(args.calibrate),
  70. n_folds_outer = float(args.n_folds_outer),
  71. n_folds_inner = float(args.n_folds_inner),
  72. n_iter = float(args.n_iter),
  73. feature_selection = bool(args.feature_selection),
  74. fill_na = int(args.fill_na),
  75. init_points = float(args.init_points),
  76. n_seeds_train = float(args.n_seeds_train) if args.n_folds_outer!= -1 else float(1),
  77. n_seeds_shuffle = float(args.n_seeds_shuffle) if args.shuffle_labels else float(0),
  78. scaler_name = args.scaler_name,
  79. id_col = args.id_col,
  80. n_boot = float(args.n_boot),
  81. n_boot_test = float(args.n_boot_test),
  82. n_boot_train = float(args.n_boot_train),
  83. filter_outliers = bool(args.filter_outliers),
  84. early_fusion = bool(args.early_fusion),
  85. overwrite = bool(args.overwrite),
  86. parallel = bool(args.parallel),
  87. n_seeds_test = float(args.n_seeds_test) if args.n_folds_outer!= -1 else float(0),
  88. bootstrap_method = args.bootstrap_method,
  89. round_values = bool(args.round_values),
  90. add_dem = bool(args.add_dem),
  91. cut_values = float(args.cut_values),
  92. regress_out = sorted(list(args.regress_out.split('_'))),
  93. regress_out_method = str(args.regress_out_method)
  94. )
  95. return config
  96. args = parse_args()
  97. config = load_configuration(args)
  98. project_name = config['project_name']
  99. add_dem = config['add_dem']
  100. round_values = config['round_values']
  101. cut_values = config['cut_values']
  102. regress_out = config['regress_out']
  103. fill_na = config['fill_na'] if config['fill_na'] != 0 else None
  104. logging.info('Configuration loaded. Starting training...')
  105. logging.info('Training completed.')
  106. ##------------------ Configuration and Parameter Parsing ------------------##
  107. home = Path(os.environ.get('HOME', Path.home()))
  108. if 'Users/gp' in str(home):
  109. data_dir = home / 'data' / project_name
  110. else:
  111. data_dir = Path('D:/path/data', project_name)
  112. results_dir = Path(str(data_dir).replace('data', 'results'))
  113. main_config = json.load(Path(Path(__file__).parent,'main_config.json').open())
  114. y_labels = main_config['y_labels'][project_name]
  115. tasks = main_config['tasks'][project_name]
  116. single_dimensions = main_config['single_dimensions'][project_name]
  117. data_file = main_config['data_file'][project_name]
  118. try:
  119. test_size = main_config['test_size'][project_name]
  120. except:
  121. test_size = 0
  122. try:
  123. thresholds = main_config['thresholds'][project_name]
  124. except:
  125. thresholds = [None]
  126. try:
  127. cmatrix = CostMatrix(np.array(main_config["cmatrix"][project_name])) if main_config["cmatrix"][project_name] is not None else None
  128. except:
  129. cmatrix = None
  130. config['test_size'] = float(test_size)
  131. config['data_file'] = data_file
  132. config['tasks'] = tasks
  133. config['single_dimensions'] = single_dimensions
  134. config['y_labels'] = y_labels
  135. config['avoid_stats'] = list(set(['min','max','median','skewness','kurtosis','std','mean','stddev']) - set(config['stats'].split('_'))) if config['stats'] != '' else []
  136. config['stat_folder'] = '_'.join(sorted(config['stats'].split('_')))
  137. config['random_seeds_train'] = [int(3**x) for x in np.arange(1, config['n_seeds_train']+1)]
  138. config['random_seeds_test'] = [int(3**x) for x in np.arange(1, config['n_seeds_test']+1)] if config['test_size'] > 0 else ['']
  139. config['random_seeds_shuffle'] = [float(3**x) for x in np.arange(1, config['n_seeds_shuffle']+1)] if config['shuffle_labels'] else ['']
  140. config['bayes'] = True
  141. if config['calibrate']:
  142. calmethod = AffineCalLogLoss
  143. calparams = {'bias':True, 'priors':None}
  144. else:
  145. calmethod = None
  146. calparams = None
  147. models_dict = {'clf':{
  148. 'lr':LR,
  149. 'knnc':KNNC,
  150. 'xgb':xgboost,
  151. #'qda':QDA,
  152. #'lda': LDA
  153. },
  154. 'reg':{'lasso':Lasso,
  155. 'ridge':Ridge,
  156. 'elastic':ElasticNet,
  157. #'knnr':KNNR,
  158. #'svr':SVR,
  159. #'xgb':xgboostr
  160. }
  161. }
  162. hyperp = json.load(Path(Path(__file__).parent,'hyperparameters.json').open())
  163. for task in tasks:
  164. if isinstance(y_labels,dict):
  165. y_labels_ = y_labels[task]
  166. else:
  167. y_labels_ = y_labels
  168. for y_label in y_labels_:
  169. dimensions = list()
  170. if isinstance(single_dimensions,dict):
  171. single_dimensions_ = single_dimensions[task]
  172. else:
  173. single_dimensions_ = single_dimensions
  174. if isinstance(single_dimensions_,list) and config["early_fusion"]:
  175. for ndim in range(len(single_dimensions_)):
  176. for dimension in itertools.combinations(single_dimensions_,ndim+1):
  177. dimensions.append('__'.join(dimension))
  178. elif isinstance(single_dimensions_,list) and not config["early_fusion"]:
  179. dimensions = single_dimensions_
  180. else:
  181. dimensions = [single_dimensions_]
  182. for dimension in dimensions:
  183. try:
  184. all_data = pd.read_csv(Path(data_dir,data_file))
  185. except:
  186. all_data = pd.read_csv(Path(data_dir,data_file),encoding='latin1')
  187. all_data = all_data.loc[:, ~all_data.columns.str.match(r'^Unnamed')]
  188. features = [col for col in all_data.columns if any(f'{x}__{y}__' in col for x,y in itertools.product(task.split('__'),dimension.split('__'))) and 'timestamp' not in col]
  189. if len(config["avoid_stats"]) > 0:
  190. features = [col for col in features if all(f'_{x}' not in col for x in config['avoid_stats'])]
  191. covariates = list(set(regress_out).intersection(set(all_data.columns)))
  192. config['covariates'] = covariates
  193. if config['add_dem']:
  194. for col in set(['sex','age','education','handedness']).intersection(set(all_data.columns)):
  195. all_data[f'{task}__dem__{col}'] = all_data[col]
  196. demographic_features = [f'{task}__dem__{col}' for col in all_data.columns if col in ['sex','age','education','handedness']]
  197. features.extend(demographic_features)
  198. dimension = dimension + '__dem' if dimension != '' else 'dem'
  199. print(task,dimension)
  200. data = all_data[features + [y_label, config['id_col']]]
  201. data.dropna(axis=1,how='all',inplace=True)
  202. data.dropna(subset=y_label,inplace=True)
  203. if cut_values > 0:
  204. data = data[data[y_label] <= cut_values]
  205. data = data.reset_index(drop=True)
  206. if len(np.unique(data[y_label])) > 3:
  207. config['problem_type'] = 'reg'
  208. scoring_metric = 'r2'
  209. else:
  210. config['problem_type'] = 'clf'
  211. scoring_metric = 'roc_auc' if len(np.unique(data[y_label])) == 2 else 'norm_expected_cost'
  212. if config['project_name'] == 'crossling_mci':
  213. config['problem_type'] = 'reg'
  214. scoring_metric = 'r2'
  215. if config['problem_type'] == 'reg' and config['filter_outliers']:
  216. all_data = all_data[np.abs((all_data[y_label] - all_data[y_label].mean()) / all_data[y_label].std()) < 2]
  217. #convert y_label to categories
  218. y = data.pop(y_label)
  219. y = pd.Series(LabelEncoder().fit_transform(y) if config['problem_type'] == 'clf' else y,name=y_label)
  220. if data.shape[0] == 0:
  221. continue
  222. if config['shuffle_labels'] and config['problem_type'] == 'clf':
  223. np.random.seed(42)
  224. zero_indices = np.where(y == 0)[0]
  225. one_indices = np.where(y == 1)[0]
  226. # Shuffle and select half of the indices for flipping
  227. zero_to_flip = np.random.choice(zero_indices, size=len(zero_indices) // 2, replace=False)
  228. one_to_flip = np.random.choice(one_indices, size=len(one_indices) // 2, replace=False)
  229. # Flip the values at the selected indices
  230. y[zero_to_flip] = 1
  231. y[one_to_flip] = 0
  232. elif config['shuffle_labels']:
  233. np.random.seed(42)
  234. #Perform random permutations of the labels
  235. y = np.random.permutation(y)
  236. ID = data.pop(config['id_col'])
  237. if (config['problem_type'] == 'reg') & ('group' in data.columns) & (config['stratify']):
  238. strat_col = data.pop('group')
  239. elif (config['problem_type'] == 'clf') & (config['stratify']):
  240. strat_col = y
  241. else:
  242. strat_col = None
  243. for model_key, model_class in models_dict[config['problem_type']].items():
  244. print(model_key)
  245. held_out = float(config["test_size"]) > 0
  246. n_folds_outer = config['n_folds_outer']
  247. n_folds_inner = config['n_folds_inner']
  248. if held_out:
  249. n_samples_dev = int(data.shape[0] * (1 - config['test_size']))
  250. random_seeds_test = config['random_seeds_test']
  251. else:
  252. n_samples_dev = data.shape[0]
  253. random_seeds_test = ['']
  254. config["n_seeds_test"] = 0
  255. config["random_seeds_test"] = ['']
  256. if n_folds_outer== 0:
  257. n_folds_outer= int(n_samples_dev / np.unique(y).shape[0])
  258. CV_outer = (StratifiedKFold(n_splits=n_folds_outer, shuffle=True)
  259. if strat_col is not None
  260. else KFold(n_splits=n_folds_outer, shuffle=True))
  261. config["kfold_folder"] = f'l{np.unique(y).shape[0]}out'
  262. n_samples_outer = n_samples_dev - np.unique(y).shape[0]
  263. elif n_folds_outer== -1:
  264. CV_outer = LeaveOneOut()
  265. n_samples_outer = n_samples_dev - 1
  266. config["kfold_folder"] = 'loocv'
  267. elif n_folds_outer < 1:
  268. CV_outer = (StratifiedShuffleSplit(n_splits=1,test_size=n_folds_outer)
  269. if strat_col is not None
  270. else ShuffleSplit(n_splits=1,test_size=n_folds_outer))
  271. n_samples_outer = int(n_samples_dev*(1-n_folds_outer))
  272. config['kfold_folder'] = f'{int(n_folds_outer*100)}pct'
  273. else:
  274. n_folds_outer = int(n_folds_outer)
  275. CV_outer = (StratifiedKFold(n_splits=n_folds_outer, shuffle=True)
  276. if strat_col is not None
  277. else KFold(n_splits=n_folds_outer, shuffle=True))
  278. n_samples_outer = int(n_samples_dev*(1-1/n_folds_outer))
  279. config['kfold_folder'] = f'{n_folds_outer}_folds'
  280. if n_folds_inner == 0:
  281. n_folds_inner = int(n_samples_outer / np.unique(y).shape[0])
  282. CV_inner = (StratifiedKFold(n_splits=n_folds_inner, shuffle=True)
  283. if strat_col is not None
  284. else KFold(n_splits=n_folds_inner, shuffle=True))
  285. config["kfold_folder"] += f'_l{np.unique(y).shape[0]}ocv'
  286. n_max = n_samples_outer - np.unique(y).shape[0]
  287. elif n_folds_inner == -1:
  288. CV_inner = LeaveOneOut()
  289. config["kfold_folder"] += '_loocv'
  290. n_max = n_samples_outer - 1
  291. elif n_folds_inner < 1:
  292. CV_inner = (StratifiedShuffleSplit(n_splits=1,test_size=n_folds_inner)
  293. if strat_col is not None
  294. else ShuffleSplit(n_splits=1,test_size=n_folds_inner))
  295. n_max = int(n_samples_outer*(1-n_folds_inner))
  296. config["kfold_folder"] += f'_{int(n_folds_inner*100)}pct'
  297. else:
  298. n_folds_inner = int(n_folds_inner)
  299. CV_inner = (StratifiedKFold(n_splits=n_folds_inner, shuffle=True)
  300. if strat_col is not None
  301. else KFold(n_splits=n_folds_inner, shuffle=True))
  302. n_max = int(n_samples_outer*(1-1/n_folds_inner))
  303. config["kfold_folder"] += f'_{n_folds_inner}_folds'
  304. with open(Path(__file__).parent/'config.json', 'w') as f:
  305. json.dump(config, f, indent=4)
  306. subfolders = [
  307. task, dimension,
  308. config['kfold_folder'], f'{y_label}_res' if len(covariates) > 0 else y_label, config['stat_folder'],scoring_metric,
  309. 'hyp_opt' if config['n_iter'] > 0 else '','feature_selection' if config['feature_selection'] else '',
  310. 'filter_outliers' if config['filter_outliers'] and config['problem_type'] == 'reg' else '','rounded' if round_values else '','cut' if cut_values > 0 else '',
  311. 'shuffle' if config['shuffle_labels'] else ''
  312. ]
  313. path_to_save = results_dir.joinpath(*[str(s) for s in subfolders if s])
  314. if Path(path_to_save,'config.json').exists():
  315. with open(Path(path_to_save,'config.json'), 'rb') as f:
  316. old_config = json.load(f)
  317. old_config['n_boot'] = config['n_boot']
  318. if (not config['overwrite']) & (any(old_config[x] != config[x] for x in ['n_iter','init_points','n_seeds_train','n_boot'])):
  319. for key in ['n_iter','init_points','n_seeds_train','n_boot']:
  320. print(f'Warning: {key} has changed from {old_config[key]} to {config[key]}. Overwriting previous results.')
  321. config[key] = old_config[key]
  322. with open(Path(path_to_save,'config.json'),'w') as f:
  323. json.dump(config, f, indent=4)
  324. if 'scoring_metric' not in list(config.keys()):
  325. config['scoring_metric'] = scoring_metric
  326. config['add_dem'] = add_dem
  327. config['round_values'] = round_values
  328. with open(Path(Path(__file__).parent,'config.json'),'w') as f:
  329. json.dump(config, f, indent=4)
  330. for random_seed_test in random_seeds_test:
  331. Path(path_to_save,f'random_seed_{int(random_seed_test)}' if config['test_size'] else '').mkdir(exist_ok=True,parents=True)
  332. if test_size > 0:
  333. X_train_, X_test_, y_train_, y_test_, ID_train_, ID_test_ = train_test_split(
  334. data, y, ID,
  335. test_size=config['test_size'],
  336. random_state=int(random_seed_test),
  337. shuffle=True,
  338. stratify=strat_col)
  339. if strat_col is not None:
  340. strat_col_train_, strat_col_test_ = train_test_split(
  341. strat_col,
  342. test_size=config['test_size'],
  343. random_state=int(random_seed_test),
  344. shuffle=True,
  345. stratify=strat_col)
  346. # Reset indexes after split.
  347. X_train_.reset_index(drop=True, inplace=True)
  348. X_test_.reset_index(drop=True, inplace=True)
  349. y_train_ = y_train_.reset_index(drop=True)
  350. y_test_ = y_test_.reset_index(drop=True)
  351. ID_train_ = ID_train_.reset_index(drop=True)
  352. ID_test_ = ID_test_.reset_index(drop=True)
  353. if strat_col is not None:
  354. strat_col_train_ = strat_col_train_.reset_index(drop=True)
  355. else:
  356. strat_col_train_ = None
  357. else:
  358. X_train_, y_train_, ID_train_ = data.reset_index(drop=True), y.reset_index(drop=True), ID.reset_index(drop=True)
  359. if strat_col is not None:
  360. strat_col_train_ = strat_col.reset_index(drop=True)
  361. else:
  362. strat_col_train_ = None
  363. X_test_, y_test_, ID_test_ = pd.DataFrame(), pd.Series(), pd.Series()
  364. data_train = pd.concat((X_train_,y_train_,ID_train_),axis=1)
  365. data_test = pd.concat((X_test_,y_test_,ID_test_),axis=1)
  366. data_train.to_csv(Path(path_to_save,f'random_seed_{int(random_seed_test)}' if config['test_size'] else '', 'data_train.csv'),index=False)
  367. data_test.to_csv(Path(path_to_save,f'random_seed_{int(random_seed_test)}' if config['test_size'] else '', 'data_test.csv'),index=False)
  368. hyperp['knnc']['n_neighbors'] = (1,n_max)
  369. hyperp['knnr']['n_neighbors'] = (1,n_max)
  370. # Check for data leakage.
  371. assert set(ID_train_).isdisjoint(set(ID_test_)), 'Data leakage detected between train and test sets!'
  372. if (Path(path_to_save,f'random_seed_{int(random_seed_test)}' if config['test_size'] else '', f'all_models_{model_key}.csv').exists() and config['calibrate'] == False) or (Path(path_to_save,f'random_seed_{int(random_seed_test)}' if config['test_size'] else '', f'cal_outputs_{model_key}.pkl').exists() and config['calibrate']):
  373. if not bool(config['overwrite']):
  374. print(f'Results already exist for {task} - {y_label} - {model_key}. Skipping...')
  375. continue
  376. print(f'Training model: {model_key}')
  377. all_models,outputs_best,y_dev,y_pred_best,IDs_dev = utils.nestedCVT(model_class=models_dict[config['problem_type']][model_key],
  378. scaler=StandardScaler if config['scaler_name'] == 'StandardScaler' else MinMaxScaler,
  379. imputer=KNNImputer,
  380. X=X_train_,
  381. y=y_train_.values if isinstance(y_train_, pd.Series) else y_train_,
  382. n_iter=int(config['n_iter']),
  383. iterator_outer=CV_outer,
  384. iterator_inner=CV_inner,
  385. strat_col=strat_col_train_,
  386. random_seeds_outer=config['random_seeds_train'],
  387. hyperp_space=hyperp[model_key],
  388. IDs=ID_train_,
  389. init_points=int(config['init_points']),
  390. scoring=scoring_metric,
  391. problem_type=config['problem_type'],
  392. cmatrix=cmatrix,priors=None,
  393. threshold=thresholds,
  394. parallel=bool(config['parallel']),
  395. feature_selection=bool(config['feature_selection']),
  396. calmethod=calmethod,
  397. calparams=calparams,
  398. round_values=round_values,
  399. covariates=covariates if isinstance(covariates,pd.DataFrame) else None,
  400. fill_na = fill_na,
  401. regress_out_method = config['regress_out_method']
  402. )
  403. Path(path_to_save,f'random_seed_{int(random_seed_test)}' if config['test_size'] else '').mkdir(parents=True, exist_ok=True)
  404. with open(Path(path_to_save,f'random_seed_{int(random_seed_test)}' if config['test_size'] else '','config.json'),'w') as f:
  405. json.dump(config,f)
  406. all_models.to_csv(Path(path_to_save,f'random_seed_{int(random_seed_test)}' if config['test_size'] else '',f'all_models_{model_key}.csv'),index=False)
  407. result_files = {
  408. 'X_train.npy': X_train_,
  409. 'y_train.npy': y_train_,
  410. 'IDs_train.npy': ID_train_,
  411. 'y_dev.npy': y_dev,
  412. 'IDs_dev.npy': IDs_dev,
  413. f'outputs_{model_key}.npy': outputs_best}
  414. if test_size > 0:
  415. result_files.update({
  416. 'X_test.npy': X_test_,
  417. 'y_test.npy': y_test_,
  418. 'IDs_test.npy': ID_test_,
  419. })
  420. for fname, obj in result_files.items():
  421. with open(Path(path_to_save,f'random_seed_{int(random_seed_test)}' if config['test_size'] else '', fname), 'wb') as f:
  422. np.save(f, obj)
  423. with open(Path(path_to_save,f'random_seed_{int(random_seed_test)}' if config['test_size'] else '', 'config.json'), 'w') as f:
  424. json.dump(config, f, indent=4)

train_models_bayes.py, no license · at the source

Overview

Authors: Ivan Caro1,2, Gonzalo Pérez1,2,3, Joaquín Valdés Bize4, Joaquín Ponferrada1, Franco J Ferrante1,2,3, Alejandro Sosa Welford1, Lara Gauder5,6, Loreto Olavarría7,8,9,10, Fernando Henríquez9,11,12, Teresita Ramos7, Cristina Besnier7, Luciana Ferrer5, Maria Luisa Gorno‐Tempini13, Andrea Slachevsky7,9,11,14, Agustín Ibañez1,15,16,17,18,19, Adolfo M García1,16,20,19
20 affiliations
  1. Cognitive Neuroscience Center (CNC), Department of Life and Behavioral Sciences, Universidad de San Andrés, Buenos Aires, Argentina
  2. National Scientific and Technical Research Council (CONICET), Buenos Aires, Argentina
  3. School of Engineering, University of Buenos Aires, Buenos Aires, Argentina
  4. Department of Psychiatry, School of Medicine, Pontificia Universidad Católica de Chile, Santiago, Chile
  5. Instituto de Investigación en Ciencias de la Computación (ICC), CONICET‐UBA, Buenos Aires, Argentina
  6. Departamento de Computación, Faculty of Exact and Natural Sciences, University of Buenos Aires (UBA), Buenos Aires, Argentina
  7. Memory and Neuropsychiatric Center (CMYN) Neurology Department, Hospital del Salvador & Faculty of Medicine, University of Chile, Santiago, Chile
  8. Departamento de Psiquiatría Oriente, Facultad de Medicina, Universidad de Chile, Santiago, Chile
  9. Neuropsychology and Clinical Neuroscience Laboratory (LANNEC), Physiopathology Program – Institute of Biomedical Sciences (ICBM), Neuroscience and East Neuroscience Departments, Faculty of Medicine, University of Chile, Santiago, Chile
  10. Servicio de Neurología, Clínica Las Condes, Santiago, Chile
  11. Gerosciences Center for Brain Health and Metabolism, Santiago, Chile
  12. Interdisciplinary Center for Neuroscience (NeuroUC), Laboratory for Cognitive and Evolutionary Neuroscience (LANCE), Department of Psychiatry, Faculty of Medicine, Pontificia Universidad Católica de Chile, Santiago, Chile
  13. Memory and Aging Center, University of California, San Francisco, California, USA
  14. Servicio de Neurología, Departamento de Medicina, Clínica Alemana‐Universidad del Desarrollo, Santiago, Chile
  15. Latin American Brain Health Institute (BrainLat), Universidad Adolfo Ibáñez, Santiago, Chile
  16. Global Brain Health Institute, University of California San Francisco, San Francisco, California, USA
  17. Department of Biophysics, School of Medicine, Istanbul Medipol University, Istanbul, Türkiye
  18. Barcelonaβeta Brain Research Center (BBRC), Pasqual Maragall Foundation, Barcelona, Spain
  19. Trinity College Dublin, Dublin, Ireland
  20. Departamento de Lingüística y Literatura, Facultad de Humanidades, Universidad de Santiago de Chile, Santiago, Chile
Journal: Alzheimer's & dementia : the journal of the Alzheimer's Association, volume 22, issue 4, article e71365
Dates: received 21 December 2025; accepted 11 March 2026; published online 14 April 2026; in print April 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1002/alz.71365 · PMID 41979006 · PMCID PMC13077448 · OpenAlex W7154239291
Open access: hybrid, a free copy (OpenAlex)
Status: code verified
Categories: fMRI (modality), human (organism), Alzheimer's / dementia (population), cognitive (subfield)
Methods: Spectral & time-frequency, Connectivity, Statistics, Machine learning, fMRI & imaging, Preprocessing
Keywords: Alzheimer's disease, automated speech and language analysis, cognitive assessments, digital biomarkers, machine learning, magnetic resonance imaging
MeSH: Alzheimer Disease*, Biomarkers*, Cognition*, Speech*, Aged, Brain, Executive Function, Female, Humans, Machine Learning, Magnetic Resonance Imaging, Male, Memory, Episodic, Neuropsychological Tests (* major topic)
Topic: Neurobiology of Language and Bilingualism (Cognitive Neuroscience, Neuroscience), according to OpenAlex
Funding: Fondecyt Regular (1231839); National Institute on Aging (2P01AG019724, R01 AG057234, R01 AG21051, CARDS‐NIH, R01 AG083799, R01 AG075775); NIA NIH HHS (CARDS-NIH, R01 AG075775, R01 AG21051, 2P01AG019724, R01 AG083799, P01 AG019724, R01 AG057234); Alzheimer&apos;s Association (SG‐20‐725707); Global Brain Health Institute; The Bluefield project to cure FTD; ANID Fondecyt regular (1250091, 1220995, 1250317); ANID/FONDAP (15150012); BRAIN-CLIMA: Investigating the Combined Impact of Heat and Air Pollution on Blood-Brain Barrier Integrity and Brain Aging in Latin America (335293/Z/25/Z); ANID/PIA/ANILLOS (ACT210096); ANID (FONDAP ID15150012, FONDECYT Regular 1250317 1250091); Agencia Nacional de Promoción Científica y Tecnológica (01-PICTE-2022-05-00103, 01‐PICTE‐2022‐05‐00103); Wellcome Leap CARE Program (CARE-2025-0883490149); Fondo de Fomento al Desarrollo Científico y Tecnológico (ID20I10152); FIC NIH HHS; Marie Skłodowska-Curie Actions - MSCA; Agencia Nacional de Investigación y Desarrollo (FONDECYT Regular 1250091); Rainwater Charitable Foundation—The Bluefield project to cure FTD; Alzheimer's Association (SG-20-725707); Rainwater Charitable Foundation - Tau Consortium, and Global Brain Health Institute; Tau Consortium; Advancing Female-Specific Predictive Models and Risk Assessment Tools for Alzheimer's Disease in the US and Latin America, and the CliCBrain (101236426); NIA of the NIH (2P01AG019724, R01AG075775, R01AG083799); JPI JPND-Care (DISCeRN 2025); FONDEF (ID20I10152); Fogarty International Center (FIC); Health and Social Care Research with a Focus on the Moderate and Late Stages of Neurodegenerative Diseases; NIH; Rainwater Charitable Foundation; Fogarty International Center; National Institutes of Health; Wellcome Trust; PIA Anillos (ACT210096)
Citations: cited by 2 papers (Europe PMC); 75 references in the paper

Abstract

The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.

Repository

Its files are read in the Code ↔ Paper reader above, with 1 match between paragraphs and lines of code.

OSF ad8jb

License: none: the authors keep all their rights
State: the link answers, verified on 28 September 2026
Evidence: files inventoried
Languages: Python (4)
Size: 7 files, 4 scripts
Software Heritage: not checked
Found in: “DATA AVAILABILITY STATEMENT”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: NumPy (4 files), pandas (4 files), SciPy (3 files), Matplotlib (2 files), scikit-learn (2 files), seaborn (2 files), XGBoost (2 files), Pingouin (1 file), statsmodels (1 file)
Availability: 1 check, the latest on 28 September 2026: the link answers (HTTP 200)
  • 28 September 2026: the link answers (HTTP 200)
4 files

The paper's code and data availability statement is in the Data section.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 4 scripts, each with its path and the digest of its content;
  • 1 match between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Code and data availability statement

The paper has a code and data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

Read it in the paper: doi.org/10.1002/alz.71365.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 28 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 16 authors, 6 keywords, 14 MeSH terms, 33 funders, 70 references.

Cite

This paper

Caro, I., Pérez, G., Bize, J. V., Ponferrada, J., Ferrante, F. J., Welford, A. S., Gauder, L., Olavarría, L., Henríquez, F., Ramos, T., Besnier, C., Ferrer, L., Gorno‐Tempini, M. L., Slachevsky, A., Ibañez, A., & García, A. M. (2026). Benchmarking speech biomarkers of Alzheimer's against cognitive and neural measures. Alzheimer's & dementia : the journal of the Alzheimer's Association, 22(4), e71365. https://doi.org/10.1002/alz.71365

BibTeX

@article{caro2026benchmarking,
author = {Caro, Ivan and Pérez, Gonzalo and Bize, Joaquín Valdés and Ponferrada, Joaquín and Ferrante, Franco J and Welford, Alejandro Sosa and Gauder, Lara and Olavarría, Loreto and Henríquez, Fernando and Ramos, Teresita and Besnier, Cristina and Ferrer, Luciana and Gorno‐Tempini, Maria Luisa and Slachevsky, Andrea and Ibañez, Agustín and García, Adolfo M},
title = {{Benchmarking speech biomarkers of Alzheimer's against cognitive and neural measures}},
journal = {Alzheimer's \& dementia : the journal of the Alzheimer's Association},
year = {2026},
month = apr,
volume = {22},
number = {4},
pages = {e71365},
publisher = {Wiley},
issn = {1552-5260},
doi = {10.1002/alz.71365},
url = {https://doi.org/10.1002/alz.71365},
pmid = {41979006},
pmcid = {PMC13077448}
}

RIS

TY - JOUR
AU - Caro, Ivan
AU - Pérez, Gonzalo
AU - Bize, Joaquín Valdés
AU - Ponferrada, Joaquín
AU - Ferrante, Franco J
AU - Welford, Alejandro Sosa
AU - Gauder, Lara
AU - Olavarría, Loreto
AU - Henríquez, Fernando
AU - Ramos, Teresita
AU - Besnier, Cristina
AU - Ferrer, Luciana
AU - Gorno‐Tempini, Maria Luisa
AU - Slachevsky, Andrea
AU - Ibañez, Agustín
AU - García, Adolfo M
TI - Benchmarking speech biomarkers of Alzheimer's against cognitive and neural measures
T2 - Alzheimer's & dementia : the journal of the Alzheimer's Association
J2 - Alzheimers Dement
PY - 2026
DA - 2026/04/01
VL - 22
IS - 4
SP - e71365
SN - 1552-5260
PB - Wiley
DO - 10.1002/alz.71365
UR - https://doi.org/10.1002/alz.71365
LA - en
ER -

CSL-JSON

{
"id": "10.1002/alz.71365",
"type": "article-journal",
"title": "Benchmarking speech biomarkers of Alzheimer's against cognitive and neural measures",
"container-title": "Alzheimer's & dementia : the journal of the Alzheimer's Association",
"author": [
{
"family": "Caro",
"given": "Ivan"
},
{
"family": "Pérez",
"given": "Gonzalo"
},
{
"family": "Bize",
"given": "Joaquín Valdés"
},
{
"family": "Ponferrada",
"given": "Joaquín"
},
{
"family": "Ferrante",
"given": "Franco J"
},
{
"family": "Welford",
"given": "Alejandro Sosa"
},
{
"family": "Gauder",
"given": "Lara"
},
{
"family": "Olavarría",
"given": "Loreto"
},
{
"family": "Henríquez",
"given": "Fernando"
},
{
"family": "Ramos",
"given": "Teresita"
},
{
"family": "Besnier",
"given": "Cristina"
},
{
"family": "Ferrer",
"given": "Luciana"
},
{
"family": "Gorno‐Tempini",
"given": "Maria Luisa"
},
{
"family": "Slachevsky",
"given": "Andrea"
},
{
"family": "Ibañez",
"given": "Agustín"
},
{
"family": "García",
"given": "Adolfo M"
}
],
"container-title-short": "Alzheimers Dement",
"volume": "22",
"issue": "4",
"page": "e71365",
"DOI": "10.1002/alz.71365",
"PMID": "41979006",
"PMCID": "PMC13077448",
"ISSN": "1552-5260",
"publisher": "Wiley",
"URL": "https://doi.org/10.1002/alz.71365",
"language": "en",
"issued": {
"date-parts": [
[
2026,
4,
1
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1002/alz.71232
Neural embedding of frailty in cognitively unimpaired aging and dementia across Latin America.
Journal: Alzheimer's & dementia : the journal of the Alzheimer's Association
In common: Alzheimer's / dementia, 7 references
[2] doi:10.1016/j.nicl.2026.104012 [code]
Structural-functional multilayer brain network properties and outcome of combined repetitive transcranial magnetic stimulation and psychotherapy for obsessive-compulsive disorder.
Journal: NeuroImage. Clinical
In common: XGBoost, Pingouin, statsmodels, 6 other tools, fMRI, 1 reference
[3] doi:10.1002/agm2.70073 [code]
Foreign Language Learning in Older Adults Modifies Resting-State Functional Connectivity Between the Subcortical Structures and the Cortex.
Journal: Aging medicine (Milton (N.S.W))
In common: statsmodels, seaborn, scikit-learn, 4 other tools, fMRI, 3 references
[4] doi:10.1162/imag.a.1208 [code]
Brain network analysis in Alzheimer's disease and mild cognitive impairment using high-density diffuse optical tomography.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: statsmodels, seaborn, scikit-learn, 4 other tools, Alzheimer's / dementia, 3 references
[5] doi:10.1038/s41598-026-56688-y [code]
On the value of radiomics in addition to clinical measures in emotional conflict fMRI for predicting sertraline response in major depressive disorder.
Journal: Scientific reports
In common: XGBoost, statsmodels, seaborn, 5 other tools, fMRI, 1 reference
[6] doi:10.1002/acn3.70396 [code]
Memory and Resting-State Connectivity in Acute Transient Global Amnesia: A Case-Control fMRI Study.
Journal: Annals of clinical and translational neurology
In common: Pingouin, statsmodels, seaborn, 4 other tools, fMRI, cognitive, 2 references
[7] doi:10.1002/dad2.70366 [code]
Redefining the norms: an interdisciplinary perspective on language testing in multilinguals with acquired and progressive neurogenic disorders.
Journal: Alzheimer's & dementia (Amsterdam, Netherlands)
In common: pandas, SciPy, Matplotlib, 1 other tool, cognitive, 4 references
[8] doi:10.1523/eneuro.0041-26.2026 [code]
Ocular Speech Tracking Persists in Blindness, but Its Dynamics and Oculo-Cerebral Connectivity Depend on Visual Status.
Journal: eNeuro
In common: Pingouin, statsmodels, seaborn, 5 other tools, cognitive, 1 reference
[9] doi:10.1093/sleep/zsag030 [code]
Divergent disruption of brain networks following total and chronic sleep loss: a longitudinal fMRI study.
Journal: Sleep
In common: statsmodels, seaborn, scikit-learn, 4 other tools, fMRI, 3 references
[10] doi:10.1038/s41514-026-00456-9 [code]
Exploring the link between body physiology and cognition: the role of the brain and aging.
Journal: npj aging
In common: XGBoost, statsmodels, seaborn, 5 other tools, cognitive, 1 reference

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.