robert 2.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. robert/__init__.py +9 -0
  2. robert/__main__.py +20 -0
  3. robert/_version.py +3 -0
  4. robert/api.py +646 -0
  5. robert/aqme.py +280 -0
  6. robert/argument_parser.py +98 -0
  7. robert/checkml.py +433 -0
  8. robert/checkml_score.py +50 -0
  9. robert/curate.py +217 -0
  10. robert/evaluate_bot_retrieval.py +125 -0
  11. robert/evaluate_bot_support.py +102 -0
  12. robert/evaluate_workflow_summaries.py +87 -0
  13. robert/export_bot_docs_knowledge.py +1632 -0
  14. robert/generate.py +249 -0
  15. robert/generate_utils.py +311 -0
  16. robert/gui_easyrob/__init__.py +0 -0
  17. robert/gui_easyrob/assets/gif_easyrob.gif +0 -0
  18. robert/gui_easyrob/bot/__init__.py +47 -0
  19. robert/gui_easyrob/bot/answer_metadata.py +198 -0
  20. robert/gui_easyrob/bot/bot_context.py +679 -0
  21. robert/gui_easyrob/bot/bot_engine.py +1100 -0
  22. robert/gui_easyrob/bot/bot_panel.py +1231 -0
  23. robert/gui_easyrob/bot/bot_rag.py +1178 -0
  24. robert/gui_easyrob/bot/bot_window.py +39 -0
  25. robert/gui_easyrob/bot/bot_worker.py +149 -0
  26. robert/gui_easyrob/bot/credential_store.py +143 -0
  27. robert/gui_easyrob/bot/error_parser.py +105 -0
  28. robert/gui_easyrob/bot/evidence_policy.py +164 -0
  29. robert/gui_easyrob/bot/heuristics.py +859 -0
  30. robert/gui_easyrob/bot/icons.py +56 -0
  31. robert/gui_easyrob/bot/input_csv_audit.py +212 -0
  32. robert/gui_easyrob/bot/knowledge/aqme_context.json +5907 -0
  33. robert/gui_easyrob/bot/knowledge/robert_context.json +4817 -0
  34. robert/gui_easyrob/bot/knowledge/ui_context.json +8293 -0
  35. robert/gui_easyrob/bot/knowledge_schema.py +1252 -0
  36. robert/gui_easyrob/bot/knowledge_sources/aqme_user_guidance.json +442 -0
  37. robert/gui_easyrob/bot/knowledge_sources/coverage_manifest.json +95 -0
  38. robert/gui_easyrob/bot/knowledge_sources/robert_user_guidance.json +471 -0
  39. robert/gui_easyrob/bot/knowledge_sources/ui_user_guidance.json +1312 -0
  40. robert/gui_easyrob/bot/llm_providers.py +1573 -0
  41. robert/gui_easyrob/bot/online_docs.py +105 -0
  42. robert/gui_easyrob/bot/prompt_policy.py +575 -0
  43. robert/gui_easyrob/bot/question_intent.py +562 -0
  44. robert/gui_easyrob/bot/response_quality.py +104 -0
  45. robert/gui_easyrob/bot/result_insights.py +225 -0
  46. robert/gui_easyrob/bot/token_usage.py +75 -0
  47. robert/gui_easyrob/bot/workflow_results.py +1396 -0
  48. robert/gui_easyrob/checkml_launcher.py +15 -0
  49. robert/gui_easyrob/easyrob.py +29 -0
  50. robert/gui_easyrob/easyrob_launcher.py +113 -0
  51. robert/gui_easyrob/main/__init__.py +9 -0
  52. robert/gui_easyrob/main/window.py +5152 -0
  53. robert/gui_easyrob/result_navigation.py +14 -0
  54. robert/gui_easyrob/tabs/__init__.py +23 -0
  55. robert/gui_easyrob/tabs/advanced_options.py +370 -0
  56. robert/gui_easyrob/tabs/aqme.py +1234 -0
  57. robert/gui_easyrob/tabs/checkml.py +898 -0
  58. robert/gui_easyrob/tabs/images.py +427 -0
  59. robert/gui_easyrob/tabs/interactive_predictions.py +555 -0
  60. robert/gui_easyrob/tabs/molssi.py +447 -0
  61. robert/gui_easyrob/tabs/predictions.py +484 -0
  62. robert/gui_easyrob/tabs/result_catalog.py +170 -0
  63. robert/gui_easyrob/tabs/results.py +490 -0
  64. robert/gui_easyrob/tabs/results_workspace.py +120 -0
  65. robert/gui_easyrob/test_bot_input_csv_audit.py +152 -0
  66. robert/gui_easyrob/test_bot_question_routing.py +383 -0
  67. robert/gui_easyrob/test_bot_result_analysis.py +356 -0
  68. robert/gui_easyrob/test_bot_retrieval_evaluation.py +110 -0
  69. robert/gui_easyrob/test_bot_ui_integration.py +278 -0
  70. robert/gui_easyrob/test_checkml_app_mode.py +124 -0
  71. robert/gui_easyrob/test_checkml_completion.py +57 -0
  72. robert/gui_easyrob/test_checkml_defaults.py +37 -0
  73. robert/gui_easyrob/test_checkml_result_summary.py +113 -0
  74. robert/gui_easyrob/test_checkml_web_mode.py +57 -0
  75. robert/gui_easyrob/test_dialog_layout.py +33 -0
  76. robert/gui_easyrob/test_gui_bot_regressions.py +320 -0
  77. robert/gui_easyrob/test_molssi_auto.py +569 -0
  78. robert/gui_easyrob/test_tutorial_view.py +215 -0
  79. robert/gui_easyrob/tutorials/check_model.md +25 -0
  80. robert/gui_easyrob/tutorials/chemdraw.md +49 -0
  81. robert/gui_easyrob/tutorials/csv.md +53 -0
  82. robert/gui_easyrob/tutorials/descriptors.md +21 -0
  83. robert/gui_easyrob/tutorials/overview.md +65 -0
  84. robert/gui_easyrob/tutorials/predictions.md +25 -0
  85. robert/gui_easyrob/tutorials/robbot.md +29 -0
  86. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_1.png +0 -0
  87. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_2.png +0 -0
  88. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_3.png +0 -0
  89. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_4.png +0 -0
  90. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_5.png +0 -0
  91. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_6.png +0 -0
  92. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_7.png +0 -0
  93. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_1.png +0 -0
  94. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_10.png +0 -0
  95. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_11.png +0 -0
  96. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_12.png +0 -0
  97. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_13.png +0 -0
  98. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_2.png +0 -0
  99. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_3.png +0 -0
  100. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_4.png +0 -0
  101. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_5.png +0 -0
  102. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_6.png +0 -0
  103. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_7.png +0 -0
  104. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_8.png +0 -0
  105. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_9.png +0 -0
  106. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1.png +0 -0
  107. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_1.png +0 -0
  108. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_2.png +0 -0
  109. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_3.png +0 -0
  110. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_4.png +0 -0
  111. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_5.png +0 -0
  112. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_2.png +0 -0
  113. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_3.png +0 -0
  114. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_4.png +0 -0
  115. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_5.png +0 -0
  116. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_6.png +0 -0
  117. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_7.png +0 -0
  118. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_8.png +0 -0
  119. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_9.png +0 -0
  120. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_1.png +0 -0
  121. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_2.png +0 -0
  122. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_3.png +0 -0
  123. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_4.png +0 -0
  124. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_5.png +0 -0
  125. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_6.png +0 -0
  126. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1.png +0 -0
  127. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_1.png +0 -0
  128. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_2.png +0 -0
  129. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_3.png +0 -0
  130. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_4.png +0 -0
  131. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_5.png +0 -0
  132. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_6.png +0 -0
  133. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_7.png +0 -0
  134. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_8.png +0 -0
  135. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_2.png +0 -0
  136. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_3.png +0 -0
  137. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_4.png +0 -0
  138. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5.png +0 -0
  139. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_1.png +0 -0
  140. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_2.png +0 -0
  141. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_3.png +0 -0
  142. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_6.png +0 -0
  143. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1.png +0 -0
  144. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1_1.png +0 -0
  145. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_2.png +0 -0
  146. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_3.png +0 -0
  147. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_4.png +0 -0
  148. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_5.png +0 -0
  149. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_6.png +0 -0
  150. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_1.png +0 -0
  151. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_2.png +0 -0
  152. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_3.png +0 -0
  153. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_4.png +0 -0
  154. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_5.png +0 -0
  155. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_6.png +0 -0
  156. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_7.png +0 -0
  157. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_8.png +0 -0
  158. robert/gui_easyrob/utils/__init__.py +0 -0
  159. robert/gui_easyrob/utils/aqme_utils.py +238 -0
  160. robert/gui_easyrob/utils/molssi_utils.py +584 -0
  161. robert/gui_easyrob/utils/predictions_utils.py +985 -0
  162. robert/gui_easyrob/utils/utils_gui.py +738 -0
  163. robert/gui_easyrob/version.py +68 -0
  164. robert/gui_easyrob/web/app.css +484 -0
  165. robert/gui_easyrob/web/app.html +134 -0
  166. robert/gui_easyrob/web/app.js +764 -0
  167. robert/gui_easyrob/web/checkml_brand.png +0 -0
  168. robert/gui_easyrob/web/easyrob_background.gif +0 -0
  169. robert/gui_easyrob/web/easyrob_background.png +0 -0
  170. robert/gui_easyrob/web/images.css +89 -0
  171. robert/gui_easyrob/web/images.html +39 -0
  172. robert/gui_easyrob/web/images.js +101 -0
  173. robert/gui_easyrob/web/results.js +499 -0
  174. robert/gui_easyrob/web/robert_brand.png +0 -0
  175. robert/gui_easyrob/web_dialogs.py +64 -0
  176. robert/gui_easyrob/web_results.py +253 -0
  177. robert/gui_easyrob/web_shell.py +684 -0
  178. robert/gui_easyrob/workflow_progress.py +89 -0
  179. robert/gui_easyrob/workflow_run_lock.py +27 -0
  180. robert/icons/CheckML_icon.png +0 -0
  181. robert/icons/Robert_icon.png +0 -0
  182. robert/icons/Robert_logo.jpg +0 -0
  183. robert/icons/Robert_logo_transparent.png +0 -0
  184. robert/icons/documentation_icon.png +0 -0
  185. robert/icons/info_icon.png +0 -0
  186. robert/icons/pdf_icon.png +0 -0
  187. robert/icons/play_icon.png +0 -0
  188. robert/icons/stop_icon.png +0 -0
  189. robert/icons/youtube_icon.ico +0 -0
  190. robert/predict.py +193 -0
  191. robert/predict_utils.py +410 -0
  192. robert/report/CheckML_logo.jpg +0 -0
  193. robert/report/GENERATE.png +0 -0
  194. robert/report/Robert_icon.ico +0 -0
  195. robert/report/Robert_logo.jpg +0 -0
  196. robert/report/Robert_logo1.jpg +0 -0
  197. robert/report/abbrev.png +0 -0
  198. robert/report/adv_anal.png +0 -0
  199. robert/report/checkml_pass.svg +3 -0
  200. robert/report/checkml_unclear.svg +3 -0
  201. robert/report/checkml_warning.svg +3 -0
  202. robert/report/features.png +0 -0
  203. robert/report/outliers.png +0 -0
  204. robert/report/pred.png +0 -0
  205. robert/report/repro.png +0 -0
  206. robert/report/robust_x.png +0 -0
  207. robert/report/robust_y_high.png +0 -0
  208. robert/report/robust_y_low.png +0 -0
  209. robert/report/score.png +0 -0
  210. robert/report/score_0.jpg +0 -0
  211. robert/report/score_1.jpg +0 -0
  212. robert/report/score_10.jpg +0 -0
  213. robert/report/score_2.jpg +0 -0
  214. robert/report/score_3.jpg +0 -0
  215. robert/report/score_4.jpg +0 -0
  216. robert/report/score_5.jpg +0 -0
  217. robert/report/score_6.jpg +0 -0
  218. robert/report/score_7.jpg +0 -0
  219. robert/report/score_8.jpg +0 -0
  220. robert/report/score_9.jpg +0 -0
  221. robert/report/score_gray_0.jpg +0 -0
  222. robert/report/score_gray_1.jpg +0 -0
  223. robert/report/score_gray_10.jpg +0 -0
  224. robert/report/score_gray_2.jpg +0 -0
  225. robert/report/score_gray_3.jpg +0 -0
  226. robert/report/score_gray_4.jpg +0 -0
  227. robert/report/score_gray_5.jpg +0 -0
  228. robert/report/score_gray_6.jpg +0 -0
  229. robert/report/score_gray_7.jpg +0 -0
  230. robert/report/score_gray_8.jpg +0 -0
  231. robert/report/score_gray_9.jpg +0 -0
  232. robert/report/score_w_1_0.jpg +0 -0
  233. robert/report/score_w_1_1.jpg +0 -0
  234. robert/report/score_w_2_0.jpg +0 -0
  235. robert/report/score_w_2_1.jpg +0 -0
  236. robert/report/score_w_2_2.jpg +0 -0
  237. robert/report/score_w_2_gray_0.jpg +0 -0
  238. robert/report/score_w_2_gray_1.jpg +0 -0
  239. robert/report/score_w_2_gray_2.jpg +0 -0
  240. robert/report/score_w_3_0.jpg +0 -0
  241. robert/report/score_w_3_1.jpg +0 -0
  242. robert/report/score_w_3_2.jpg +0 -0
  243. robert/report/score_w_3_3.jpg +0 -0
  244. robert/report/score_w_4_0.jpg +0 -0
  245. robert/report/score_w_4_1.JPG +0 -0
  246. robert/report/score_w_4_2.jpg +0 -0
  247. robert/report/score_w_4_3.jpg +0 -0
  248. robert/report/score_w_4_4.jpg +0 -0
  249. robert/report/transpa.png +0 -0
  250. robert/report/y_distrib.png +0 -0
  251. robert/report.py +2880 -0
  252. robert/report_utils.py +2270 -0
  253. robert/robert.py +181 -0
  254. robert/utils.py +4763 -0
  255. robert/verify.py +606 -0
  256. robert-2.2.0.dist-info/METADATA +55 -0
  257. robert-2.2.0.dist-info/RECORD +261 -0
  258. robert-2.2.0.dist-info/WHEEL +5 -0
  259. robert-2.2.0.dist-info/entry_points.txt +3 -0
  260. robert-2.2.0.dist-info/licenses/LICENSE +21 -0
  261. robert-2.2.0.dist-info/top_level.txt +1 -0
robert/verify.py ADDED
@@ -0,0 +1,606 @@
1
+ """
2
+ Parameters
3
+ ----------
4
+
5
+ destination : str, default=None,
6
+ Directory to create the output file(s).
7
+ varfile : str, default=None
8
+ Option to parse the variables using a yaml file (specify the filename, i.e. varfile=FILE.yaml).
9
+ params_dir : str, default=''
10
+ Folder containing the database and parameters of the ML model to analyze.
11
+ seed : int, default=0
12
+ Random seed used in the ML predictor models and other protocols.
13
+ kfold : int, default=5
14
+ Number of random data splits for the cross-validation of the models.
15
+ repeat_kfolds : int, default=10
16
+ Number of repetitions for the k-fold cross-validation of the models.
17
+
18
+ """
19
+ #####################################################.
20
+ # This file stores the VERIFY class #
21
+ # used for ML model analysis #
22
+ #####################################################.
23
+
24
+ import os
25
+ import time
26
+ import copy
27
+ import numpy as np
28
+ from statistics import mode
29
+ from sklearn.cluster import KMeans
30
+ from robert.utils import (load_variables,
31
+ load_db_n_params,
32
+ load_n_predict,
33
+ finish_print,
34
+ get_prediction_results,
35
+ print_pfi,
36
+ plot_metrics,
37
+ repeated_kfold_cv,
38
+ build_params_dirs,
39
+ Logger
40
+ )
41
+
42
+
43
+ class _ClusterMeanBaseline:
44
+ '''
45
+ Trivial baseline used by verify.cluster_test(): clusters the X descriptors into two groups
46
+ with KMeans and predicts each point with its own cluster's training-y mean. Follows the
47
+ same fit()/predict() interface as the real sklearn models so it can be dropped straight
48
+ into repeated_kfold_cv() and evaluated out-of-fold exactly like the real model, making its
49
+ RMSE directly comparable to CV_score.
50
+ '''
51
+
52
+ def __init__(self, random_state=0):
53
+ self.random_state = random_state
54
+
55
+ def fit(self, X, y):
56
+ self.kmeans = KMeans(n_clusters=2, random_state=self.random_state, n_init=10)
57
+ labels = self.kmeans.fit_predict(X)
58
+ y = np.asarray(y)
59
+ self.cluster_means = {label: y[labels == label].mean() for label in set(labels)}
60
+ return self
61
+
62
+ def predict(self, X):
63
+ labels = self.kmeans.predict(X)
64
+ return np.array([self.cluster_means[label] for label in labels])
65
+
66
+
67
+ # thresholds for passing tests in VERIFY
68
+ thres_test_pass = 0.3
69
+ thres_test_unclear = 0.15
70
+
71
+ # MVL baseline comparison (not scored): the model is "better" than a plain linear baseline when
72
+ # the baseline's CV error is this fraction worse than the model's, "similar" within +-this
73
+ # fraction, and the baseline is "better" when its error is this fraction lower
74
+ thres_mvl_baseline = 0.15
75
+
76
+ # models that are already linear: comparing them against a linear baseline is meaningless
77
+ _LINEAR_MODEL_CODES = {'MVL', 'RIDGE', 'LOGISTIC'}
78
+
79
+
80
+ def _is_linear_model(model_name):
81
+ '''
82
+ True for ROBERT's linear codes and any scikit-learn estimator from sklearn.linear_model
83
+ '''
84
+
85
+ from sklearn import linear_model
86
+ name = str(model_name or '').strip()
87
+ return name.upper() in _LINEAR_MODEL_CODES or name in getattr(linear_model, '__all__', [])
88
+
89
+
90
+ def linear_baseline_code(pred_type):
91
+ '''
92
+ ROBERT code and display name of the plain linear baseline: MVL (LinearRegression) for
93
+ regression, LOGISTIC (LogisticRegression) for classification
94
+ '''
95
+
96
+ return ('MVL','MVL') if str(pred_type).lower() == 'reg' else ('LOGISTIC','Logistic')
97
+
98
+
99
+ def _mvl_screened_in_generate(baseline_code='MVL'):
100
+ '''
101
+ True when GENERATE screened the linear baseline (MVL, or LOGISTIC for classification)
102
+ together with at least one other model (its Raw_data folder only exists in the full
103
+ ROBERT workflow, not in CHECKML)
104
+ '''
105
+
106
+ import glob
107
+ import pandas as pd
108
+ models = set()
109
+ for csv_file in glob.glob(f'{os.getcwd()}/GENERATE/Raw_data/**/*.csv', recursive=True):
110
+ if '_db' in os.path.basename(csv_file):
111
+ continue
112
+ try:
113
+ models.add(str(pd.read_csv(csv_file, nrows=1)['model'][0]).upper())
114
+ except Exception:
115
+ continue
116
+ return baseline_code in models and len(models) > 1
117
+
118
+ class verify:
119
+ """
120
+ Class containing all the functions from the VERIFY module.
121
+
122
+ Parameters
123
+ ----------
124
+ kwargs : argument class
125
+ Specify any arguments from the VERIFY module (for a complete list of variables, visit the ROBERT documentation)
126
+ """
127
+
128
+ def __init__(self, **kwargs):
129
+
130
+ start_time = time.time()
131
+
132
+ # load default and user-specified variables
133
+ self.args = load_variables(kwargs, "verify")
134
+
135
+ # if params_dir = '', the program performs the tests for the No_PFI and PFI folders
136
+ # (or, with --all_models, for every model staged under GENERATE/All_models)
137
+ params_dirs, suffixes, suffix_titles, model_names = build_params_dirs(self)
138
+
139
+ # --all_models: each model gets its own VERIFY_{model}_data.dat instead of merging
140
+ # every model's output into one shared log, where REPORT would have no reliable way
141
+ # to tell which lines belong to which model. The original shared log (already holds
142
+ # the run header from load_variables) is closed right away in that case.
143
+ default_log = self.args.log
144
+ if any(m is not None for m in model_names):
145
+ default_log.finalize()
146
+
147
+ # model_names repeats each model once per PFI variant (No_PFI then PFI) - only
148
+ # open a new Logger when the model actually changes, otherwise the PFI pass would
149
+ # re-open (and truncate, Logger uses mode 'w') the same file the No_PFI pass just
150
+ # wrote, silently discarding the No_PFI block
151
+ current_model = None
152
+ model_time_start = None
153
+ model_durations = {}
154
+ for (params_dir,suffix,suffix_title,model_name) in zip(params_dirs,suffixes,suffix_titles,model_names):
155
+ if os.path.exists(params_dir):
156
+
157
+ if model_name is not None and model_name != current_model:
158
+ if self.args.log is not default_log:
159
+ self.args.log.finalize()
160
+ if current_model is not None:
161
+ model_durations[current_model] = time.time() - model_time_start
162
+ self.args.log = Logger(self.args.destination / f'VERIFY_{model_name}', 'data')
163
+ current_model = model_name
164
+ model_time_start = time.time()
165
+
166
+ _ = print_pfi(self,params_dir)
167
+
168
+ # load the Xy databse and model parameters
169
+ Xy_data, model_data, suffix_title = load_db_n_params(self,params_dir,suffix,suffix_title,"verify",True)
170
+
171
+ # ymean_test/yshuffle_test/onehot_test/cluster_test below each need their own
172
+ # untouched copy of the freshly-loaded data (onehot_test in particular mutates
173
+ # X_train_scaled in place, and load_n_predict() right below adds CV-result keys
174
+ # to Xy_data) - snapshot it now with a deep copy instead of re-reading and
175
+ # reprocessing the same CSVs (plus the external test set, if any) from disk
176
+ # 4 more times just to get a clean copy
177
+ Xy_data_pristine = copy.deepcopy(Xy_data)
178
+
179
+ # this dictionary will keep the results of the tests
180
+ verify_results = {'error_type': model_data['error_type']}
181
+
182
+ # get data about repeated and sorted CVs
183
+ Xy_data = load_n_predict(self, model_data, Xy_data, BO_opt=True, verify_job=True)
184
+ verify_results['CV_score'] = Xy_data[f'{verify_results["error_type"]}_train']
185
+ verify_results['sorted_CV_score'] = Xy_data[f'{model_data["error_type"]}_train_sorted_CV']
186
+ if model_data['type'].lower() == 'reg':
187
+ verify_results[f'r2_train_sorted_CV'] = [float(f"{val:.2f}") for val in Xy_data[f'r2_train_sorted_CV']]
188
+ verify_results[f'mae_train_sorted_CV'] = [float(f"{val:.2f}") for val in Xy_data[f'mae_train_sorted_CV']]
189
+ verify_results[f'rmse_train_sorted_CV'] = [float(f"{val:.2f}") for val in Xy_data[f'rmse_train_sorted_CV']]
190
+ elif model_data['type'].lower() == 'clas':
191
+ verify_results[f'acc_train_sorted_CV'] = [float(f"{val:.2f}") for val in Xy_data[f'acc_train_sorted_CV']]
192
+ verify_results[f'f1_train_sorted_CV'] = [float(f"{val:.2f}") for val in Xy_data[f'f1_train_sorted_CV']]
193
+ verify_results[f'mcc_train_sorted_CV'] = [float(f"{val:.2f}") for val in Xy_data[f'mcc_train_sorted_CV']]
194
+
195
+ # calculate scores for the y-mean test
196
+ verify_results = self.ymean_test(verify_results,copy.deepcopy(Xy_data_pristine),model_data)
197
+
198
+ # calculate scores for the y-shuffle test
199
+ verify_results = self.yshuffle_test(verify_results,copy.deepcopy(Xy_data_pristine),model_data)
200
+
201
+ # one-hot test (check that if a value isnt 0, the value assigned is 1)
202
+ verify_results = self.onehot_test(verify_results,copy.deepcopy(Xy_data_pristine),model_data)
203
+
204
+ # two-cluster-mean test (flags datasets that are really just two separated
205
+ # point clouds, where a model can look good while only learning "which side
206
+ # of the gap is this point on")
207
+ verify_results = self.cluster_test(verify_results,copy.deepcopy(Xy_data_pristine),model_data)
208
+
209
+ # comparison with a plain linear (MVL) baseline - shown next to the tests above
210
+ # but not scored: a model that is no better than MVL isn't flawed, it's just
211
+ # more complex than the data justify
212
+ verify_results = self.mvl_baseline_test(verify_results,copy.deepcopy(Xy_data_pristine),model_data)
213
+
214
+ # analysis of results
215
+ results_print,verify_results,verify_metrics = self.analyze_tests(verify_results)
216
+
217
+ # plot a bar graph with the results (kept with its title - the report crops
218
+ # the title out via a precisely-measured container height, see report.py's
219
+ # verify_height - but the saved PNG itself keeps the full title)
220
+ print_ver = plot_metrics(model_data,suffix_title,verify_metrics,verify_results)
221
+
222
+ # print and save results
223
+ _ = self.print_verify(results_print,verify_results,print_ver,model_data)
224
+
225
+ # --all_models: each model gets its own "Time VERIFY" line reflecting only the time
226
+ # spent processing that model (not the cumulative time for every model), since each
227
+ # model's own PDF report should show its own VERIFY duration. finish_print() can't be
228
+ # reused here because it always measures from the original start_time (the whole
229
+ # multi-model run), and it also only writes into whichever log is CURRENTLY open (the
230
+ # last model processed) - every other model's log needs its line appended separately
231
+ # to its own (already-closed) file
232
+ if current_model is not None:
233
+ model_durations[current_model] = time.time() - model_time_start
234
+ for m, duration in model_durations.items():
235
+ if m == current_model:
236
+ continue
237
+ with open(self.args.destination / f'VERIFY_{m}_data.dat', 'a', encoding='utf-8') as f:
238
+ f.write(f"\nTime VERIFY: {round(duration, 2)} seconds\n")
239
+ self.args.log.write(f"\nTime VERIFY: {round(model_durations[current_model], 2)} seconds\n")
240
+ self.args.log.finalize()
241
+ else:
242
+ _ = finish_print(self,start_time,'VERIFY')
243
+
244
+
245
+ def ymean_test(self,verify_results,Xy_data,model_data):
246
+ '''
247
+ Calculate the accuracy of the model when using a flat line of predicted y values. For
248
+ regression, the mean of the y values is used. For classification, the value that is
249
+ predicted more often is used.
250
+ '''
251
+
252
+ Xy_ymean = Xy_data.copy()
253
+ if model_data['type'].lower() == 'reg':
254
+ y_mean_array = np.ones(len(Xy_ymean['y_train']))*(Xy_ymean['y_train'].mean())
255
+ Xy_ymean['r2_train'], Xy_ymean['mae_train'], Xy_ymean['rmse_train'] = get_prediction_results(model_data,Xy_ymean['y_train'],y_mean_array)
256
+
257
+ elif model_data['type'].lower() == 'clas':
258
+ y_mean_array = np.ones(len(Xy_ymean['y_train']))*mode(Xy_ymean['y_train'])
259
+ Xy_ymean['acc_train'], Xy_ymean['f1_train'], Xy_ymean['mcc_train'] = get_prediction_results(model_data,Xy_ymean['y_train'],y_mean_array)
260
+
261
+ verify_results['y_mean'] = Xy_ymean[f'{verify_results["error_type"]}_train']
262
+
263
+ return verify_results
264
+
265
+
266
+ def yshuffle_test(self,verify_results,Xy_data,model_data):
267
+ '''
268
+ Calculate the accuracy of the model when the y values are randomly shuffled in the validation set
269
+ For example, a y array of 1.3, 2.1, 4.0, 5.2 might become 2.1, 1.3, 5.2, 4.0.
270
+ '''
271
+
272
+ Xy_yshuffle = Xy_data.copy()
273
+ Xy_yshuffle['y_train'] = Xy_yshuffle['y_train'].sample(frac=1,random_state=model_data['seed'],axis=0)
274
+ Xy_yshuffle = load_n_predict(self, model_data, Xy_yshuffle, BO_opt=False)
275
+
276
+ verify_results['y_shuffle'] = Xy_yshuffle[f'{verify_results["error_type"]}_train']
277
+
278
+ return verify_results
279
+
280
+
281
+ def onehot_test(self,verify_results,Xy_data,model_data):
282
+ '''
283
+ Calculate the accuracy of the model when using one-hot models. Continuous descriptors
284
+ are binarized by their own median (value >= median -> 1, else -> 0) - not by "== 0",
285
+ which only binarizes descriptors that already contain literal zeros and silently
286
+ collapses any strictly-positive continuous descriptor (e.g. a molecular weight) into
287
+ a constant, useless column instead of a genuine two-way split.
288
+
289
+ If any descriptor of the model already has exactly 2 unique values, the test is skipped
290
+ (marked N/A, like the cluster test in classification). Binarizing can't remove information
291
+ from such a descriptor, so the "onehot" model keeps everything that descriptor carries and
292
+ can still predict as well as the original model - the test would then fail without the
293
+ model being flawed (i.e. a model driven by a 0/1 flag, or a dataset of on/off features).
294
+ A constant descriptor (1 value) carries no information at all, so it doesn't disable the
295
+ test (it's dropped below, like any descriptor that ends up constant after binarizing).
296
+ '''
297
+
298
+ binary_descs = [desc for desc in Xy_data['X_train'] if Xy_data['X_train'][desc].dropna().nunique() == 2]
299
+ if binary_descs:
300
+ verify_results['onehot'] = verify_results['CV_score']
301
+ verify_results['onehot_skipped'] = True
302
+ verify_results['onehot_binary_descs'] = binary_descs
303
+ return verify_results
304
+
305
+ Xy_onehot = Xy_data.copy()
306
+ constant_descs = []
307
+ for desc in Xy_onehot['X_train']:
308
+ desc_median = Xy_onehot['X_train'][desc].median()
309
+ new_vals = [1 if val >= desc_median else 0 for val in Xy_onehot['X_train'][desc]]
310
+
311
+ # a discrete descriptor with many ties at the median can still collapse to a
312
+ # constant after the split - drop just that descriptor instead of letting it
313
+ # invalidate the whole test
314
+ if len(set(new_vals)) <= 1:
315
+ constant_descs.append(desc)
316
+ continue
317
+
318
+ Xy_onehot['X_train_scaled'][desc] = new_vals
319
+
320
+ if constant_descs:
321
+ Xy_onehot['X_train_scaled'] = Xy_onehot['X_train_scaled'].drop(columns=constant_descs)
322
+ if 'X_test_scaled' in Xy_onehot:
323
+ Xy_onehot['X_test_scaled'] = Xy_onehot['X_test_scaled'].drop(columns=constant_descs)
324
+ if 'X_external_scaled' in Xy_onehot:
325
+ Xy_onehot['X_external_scaled'] = Xy_onehot['X_external_scaled'].drop(columns=constant_descs)
326
+
327
+ if Xy_onehot['X_train_scaled'].shape[1] == 0:
328
+ # every descriptor collapsed to a constant after binarization: nothing left to
329
+ # evaluate, same rationale as the already-binary skip above
330
+ verify_results['onehot'] = verify_results['CV_score']
331
+ verify_results['onehot_skipped'] = True
332
+ return verify_results
333
+
334
+ Xy_onehot = load_n_predict(self, model_data, Xy_onehot, BO_opt=False)
335
+ verify_results['onehot'] = Xy_onehot[f'{verify_results["error_type"]}_train']
336
+ return verify_results
337
+
338
+
339
+ def cluster_test(self,verify_results,Xy_data,model_data):
340
+ '''
341
+ Calculate the accuracy of a simple two-cluster-mean baseline (_ClusterMeanBaseline):
342
+ clusters X into two groups with KMeans and predicts each point with its own cluster's
343
+ training-y mean, evaluated out-of-fold via the same repeated_kfold_cv() used for the
344
+ real model - so its RMSE is directly comparable to CV_score, unlike a naive in-sample
345
+ baseline (which would almost always look artificially good on any small dataset,
346
+ regardless of whether it is actually bimodal, and give a false positive here).
347
+
348
+ A dataset where the points sit in two point clouds separated by a wide gap in y (i.e.
349
+ barely any points cover the middle of the range) can make a model look deceptively good
350
+ even if it has only learned "which of the two point clouds is this compound in" - not
351
+ the underlying relationship. If the real model barely beats this trivial baseline, that
352
+ is a sign of exactly that failure mode, regardless of how good its raw CV error looks
353
+ in isolation.
354
+
355
+ _ClusterMeanBaseline predicts each point with its cluster's mean y - a continuous value
356
+ that isn't a valid class label, so it can't be reused for classification as-is (an
357
+ earlier version aliased this test to y_mean's result for classification, but that just
358
+ duplicated a different, X-blind baseline - the majority-class test - under a misleading
359
+ name, not a real equivalent). Skipped (N/A) for classification instead of guessing at a
360
+ classification-specific baseline until one is actually designed and validated.
361
+ '''
362
+
363
+ if model_data['type'].lower() != 'reg':
364
+ verify_results['cluster'] = verify_results['CV_score']
365
+ verify_results['cluster_skipped'] = True
366
+ return verify_results
367
+
368
+ baseline_model = _ClusterMeanBaseline(random_state=model_data['seed'])
369
+ Xy_cluster = repeated_kfold_cv(model_data, baseline_model, Xy_data.copy(), BO_opt=True)
370
+
371
+ y_all_list,y_pred_all_list = [],[]
372
+ for y_val,y_pred_vals in zip(Xy_cluster['y_train'], Xy_cluster['y_pred_train_all']):
373
+ for y_pred_val in y_pred_vals:
374
+ y_all_list.append(y_val)
375
+ y_pred_all_list.append(y_pred_val)
376
+
377
+ r2_cluster, mae_cluster, rmse_cluster = get_prediction_results(model_data, y_all_list, y_pred_all_list)
378
+ verify_results['cluster'] = {'r2': r2_cluster, 'mae': mae_cluster, 'rmse': rmse_cluster}[verify_results['error_type']]
379
+
380
+ return verify_results
381
+
382
+
383
+ def mvl_baseline_test(self,verify_results,Xy_data,model_data):
384
+ '''
385
+ Compares the model with a plain linear baseline trained on the same descriptors with
386
+ the same repeated CV (same folds/seed as CV_score): LinearRegression (ROBERT's MVL) for
387
+ regression, LogisticRegression for classification. If the baseline does as well or
388
+ better, a more complex algorithm isn't justified by the data.
389
+
390
+ Not scored (unlike the flawed-model tests): the model's own predictions are as good as
391
+ its metrics say, it's a question of parsimony. Skipped (N/A) when the model is already
392
+ linear, or when a CV training fold has as many descriptors as points (an unregularized
393
+ linear fit is then underdetermined and the comparison would be meaningless).
394
+
395
+ Sets verify_results['mvl'] (baseline CV score) and verify_results['mvl_status'] in
396
+ 'model_better' / 'similar' / 'baseline_better' / 'na' (+ 'mvl_na_reason')
397
+ '''
398
+
399
+ from sklearn.linear_model import LinearRegression, LogisticRegression
400
+
401
+ verify_results['mvl'] = verify_results['CV_score']
402
+ baseline_code,baseline_name = linear_baseline_code(model_data['type'])
403
+ verify_results['mvl_name'] = baseline_name
404
+ # baseline already screened together with other models in GENERATE: REPORT compares
405
+ # them in Section F, so the bar isn't drawn here
406
+ if _mvl_screened_in_generate(baseline_code):
407
+ verify_results['mvl_status'] = 'na'
408
+ verify_results['mvl_na_reason'] = f'{baseline_code} was screened with the other models (Section F)'
409
+ verify_results['mvl_hide'] = True
410
+ return verify_results
411
+ if _is_linear_model(model_data.get('model')):
412
+ verify_results['mvl_status'] = 'na'
413
+ verify_results['mvl_na_reason'] = 'the model is already linear'
414
+ return verify_results
415
+
416
+ n_train_fold = int(len(Xy_data['y_train']) * (1 - 1/int(model_data['kfold'])))
417
+ n_descp = Xy_data['X_train_scaled'].shape[1]
418
+ if n_descp >= n_train_fold:
419
+ verify_results['mvl_status'] = 'na'
420
+ verify_results['mvl_na_reason'] = f'{n_descp} descriptors for ~{n_train_fold} points per CV fold'
421
+ return verify_results
422
+
423
+ if model_data['type'].lower() == 'reg':
424
+ baseline_model = LinearRegression()
425
+ else:
426
+ baseline_model = LogisticRegression(max_iter=1000, random_state=model_data['seed'])
427
+ Xy_mvl = repeated_kfold_cv(model_data, baseline_model, Xy_data.copy(), BO_opt=True)
428
+
429
+ y_all_list,y_pred_all_list = [],[]
430
+ for y_val,y_pred_vals in zip(Xy_mvl['y_train'], Xy_mvl['y_pred_train_all']):
431
+ for y_pred_val in y_pred_vals:
432
+ y_all_list.append(y_val)
433
+ y_pred_all_list.append(y_pred_val)
434
+ metrics_mvl = get_prediction_results(model_data, y_all_list, y_pred_all_list)
435
+ if model_data['type'].lower() == 'reg':
436
+ metric_names = ['r2', 'mae', 'rmse']
437
+ else:
438
+ metric_names = ['acc', 'f1', 'mcc']
439
+ mvl_score = dict(zip(metric_names, metrics_mvl))[verify_results['error_type']]
440
+ verify_results['mvl'] = mvl_score
441
+
442
+ # lower-is-better errors (MAE/RMSE) vs higher-is-better scores (R2/acc/F1/MCC)
443
+ cv_score = verify_results['CV_score']
444
+ if verify_results['error_type'].lower() in ['mae','rmse']:
445
+ model_better = mvl_score >= (1+thres_mvl_baseline)*cv_score
446
+ mvl_better = mvl_score <= (1-thres_mvl_baseline)*cv_score
447
+ else:
448
+ model_better = mvl_score <= cv_score - thres_mvl_baseline*abs(cv_score)
449
+ mvl_better = mvl_score >= cv_score + thres_mvl_baseline*abs(cv_score)
450
+ verify_results['mvl_status'] = 'model_better' if model_better else 'baseline_better' if mvl_better else 'similar'
451
+
452
+ return verify_results
453
+
454
+
455
+ def analyze_tests(self,verify_results):
456
+ '''
457
+ Function to check whether the tests pass and retrieve the corresponding colors:
458
+ 1. Blue for passing tests
459
+ 2. Red for failing tests
460
+ '''
461
+
462
+ blue_color = '#1f77b4'
463
+ red_color = '#cd5c5c'
464
+ yellow_color = '#c5c57d'
465
+ gray_color = '#a9a9a9'
466
+ colors = [None,None,None,None]
467
+ results_print = [None,None,None,None]
468
+ metrics = [None,None,None,None]
469
+
470
+ # the threshold uses validation results to compare in the tests
471
+ verify_results['higher_thres'] = (1+thres_test_pass)*verify_results['CV_score']
472
+ verify_results['unclear_higher_thres'] = (1+thres_test_unclear)*verify_results['CV_score']
473
+ # for higher-is-better metrics (r2/acc/mcc/f1, the only ones that use lower_thres/
474
+ # unclear_lower_thres below), CV_score can be negative (e.g. a poor-fitting R2) - scaling
475
+ # by (1-thres) then moves the threshold TOWARD zero, i.e. easier to pass, the opposite of
476
+ # the intended "thres fraction worse than CV_score". Subtracting a fraction of
477
+ # abs(CV_score) instead keeps the threshold on the "worse" side regardless of sign
478
+ verify_results['lower_thres'] = verify_results['CV_score'] - thres_test_pass*abs(verify_results['CV_score'])
479
+ verify_results['unclear_lower_thres'] = verify_results['CV_score'] - thres_test_unclear*abs(verify_results['CV_score'])
480
+
481
+ # determine whether the tests pass
482
+ test_names = ['y_mean','y_shuffle','onehot','cluster']
483
+ for i,test_ver in enumerate(test_names):
484
+ metrics[i] = verify_results[test_ver]
485
+
486
+ # onehot test skipped (a descriptor is already binary, or every descriptor collapsed
487
+ # to a constant - see onehot_test()): not scored, shown as N/A instead of being
488
+ # forced through the pass/fail thresholds
489
+ if test_ver == 'onehot' and verify_results.get('onehot_skipped',False):
490
+ colors[i] = gray_color
491
+ binary_descs = verify_results.get('onehot_binary_descs', [])
492
+ if binary_descs:
493
+ shown = ', '.join(binary_descs[:3]) + (', ...' if len(binary_descs) > 3 else '')
494
+ results_print[i] = f'\n - {test_ver}: N/A, descriptor(s) with only 2 values ({shown})'
495
+ else:
496
+ results_print[i] = f'\n - {test_ver}: N/A, all descriptors collapse to a constant when binarized'
497
+ continue
498
+
499
+ # cluster test skipped for classification (see cluster_test()): not scored
500
+ if test_ver == 'cluster' and verify_results.get('cluster_skipped',False):
501
+ colors[i] = gray_color
502
+ results_print[i] = f'\n - {test_ver}: N/A, not defined for classification'
503
+ continue
504
+
505
+ cv_score = verify_results['CV_score']
506
+ if cv_score == 0:
507
+ # A relative percentage is undefined when the reference score is zero.
508
+ # Keep the threshold comparisons below (which remain well-defined) and
509
+ # say why the percentage cannot be reported.
510
+ error_difference = 'percentage difference unavailable (CV score is 0)'
511
+ else:
512
+ if verify_results['error_type'].lower() in ['mae','rmse']:
513
+ relative_difference = (verify_results[test_ver]/cv_score - 1)*100
514
+ else:
515
+ # For higher-is-better metrics (including negative MCC), normalize by
516
+ # |CV_score| so the sign still reflects whether the test score rose or fell.
517
+ relative_difference = ((verify_results[test_ver]-cv_score)/abs(cv_score))*100
518
+ error_difference = f'{relative_difference:.2f}'.rstrip('0').rstrip('.') + '% difference'
519
+ if verify_results['error_type'].lower() in ['mae','rmse']:
520
+ if verify_results[test_ver] <= verify_results['unclear_higher_thres']:
521
+ colors[i] = red_color
522
+ results_print[i] = f'\n x {test_ver}: FAILED, {verify_results["error_type"].upper()} = {verify_results[test_ver]:.2}, lower than threshold. {error_difference}.'
523
+ elif verify_results[test_ver] <= verify_results['higher_thres']:
524
+ colors[i] = yellow_color
525
+ results_print[i] = f'\n - {test_ver}: UNCLEAR, {verify_results["error_type"].upper()} = {verify_results[test_ver]:.2}, higher than original, but close to fail. {error_difference}.'
526
+ else:
527
+ colors[i] = blue_color
528
+ results_print[i] = f'\n o {test_ver}: PASSED, {verify_results["error_type"].upper()} = {verify_results[test_ver]:.2}, higher than thresholds. {error_difference}.'
529
+
530
+ else:
531
+ if verify_results[test_ver] >= verify_results['unclear_lower_thres']:
532
+ colors[i] = red_color
533
+ results_print[i] = f'\n x {test_ver}: FAILED, {verify_results["error_type"].upper()} = {verify_results[test_ver]:.2}, higher than thresholds. {error_difference}.'
534
+ elif verify_results[test_ver] >= verify_results['lower_thres']:
535
+ colors[i] = yellow_color
536
+ results_print[i] = f'\n - {test_ver}: UNCLEAR, {verify_results["error_type"].upper()} = {verify_results[test_ver]:.2}, lower than original, but close to fail. {error_difference}.'
537
+ else:
538
+ colors[i] = blue_color
539
+ results_print[i] = f'\n o {test_ver}: PASSED, {verify_results["error_type"].upper()} = {verify_results[test_ver]:.2}, lower than thresholds. {error_difference}.'
540
+
541
+ # store metrics and colors to represent in comparison graph, adding the metrics of the
542
+ # original model first
543
+ test_names = ['Model'] + test_names
544
+ colors = [blue_color] + colors
545
+ metrics = [verify_results['CV_score']] + metrics
546
+
547
+ # MVL baseline (not scored, see mvl_baseline_test()): own colour/label and log line.
548
+ # The log line goes after the "Sorted CV" line (see print_verify()) so REPORT's parser
549
+ # of the 4 scored tests (fixed positions after the "Original ..." line) is unaffected
550
+ mvl_status = verify_results.get('mvl_status','na')
551
+ err = verify_results['error_type'].upper()
552
+ # MVL (regression) or Logistic (classification), see linear_baseline_code()
553
+ base_name = verify_results.get('mvl_name','MVL')
554
+ # two-line bar labels so they fit above the last bar of the chart
555
+ mvl_info = {'model_better': (blue_color, 'model\nbetter', 'o', 'the model is better than the linear baseline'),
556
+ 'similar': (yellow_color, 'similar', '-', 'similar performance, a simpler linear model may suffice'),
557
+ 'baseline_better': (red_color, f'{base_name}\nbetter', 'x', 'the linear baseline is better than the model'),
558
+ 'na': (gray_color, 'N/A', '-', None)}[mvl_status]
559
+ if mvl_status == 'na':
560
+ verify_results['mvl_print'] = f'\n - {base_name} baseline (not scored): N/A, {verify_results.get("mvl_na_reason","")}'
561
+ else:
562
+ verify_results['mvl_print'] = (f'\n {mvl_info[2]} {base_name} baseline (not scored): {mvl_status.upper()}, '
563
+ f'{err} = {verify_results["mvl"]:.2} vs {verify_results["CV_score"]:.2} (model), {mvl_info[3]}.')
564
+
565
+ verify_metrics = {'test_names': test_names,
566
+ 'colors': colors,
567
+ 'metrics': metrics,
568
+ 'higher_thres': verify_results['higher_thres'],
569
+ 'lower_thres': verify_results['lower_thres'],
570
+ 'unclear_higher_thres': verify_results['unclear_higher_thres'],
571
+ 'unclear_lower_thres': verify_results['unclear_lower_thres'],
572
+ # drawn as a separate, unscored bar (see plot_metrics()) - not drawn
573
+ # when Section F already compares MVL with the other models
574
+ 'baseline': None if verify_results.get('mvl_hide') else
575
+ {'name': base_name, 'value': verify_results['mvl'],
576
+ 'color': mvl_info[0], 'label': mvl_info[1],
577
+ 'band': thres_mvl_baseline},
578
+ }
579
+
580
+ return results_print,verify_results,verify_metrics
581
+
582
+
583
+ def print_verify(self,results_print,verify_results,print_ver,model_data):
584
+ '''
585
+ Print and store the results of VERIFY
586
+ '''
587
+
588
+ print_ver += f'\n Results of flawed models and sorted cross-validation:'
589
+ CV_type = f"{model_data['repeat_kfolds']}x {model_data['kfold']}-fold CV"
590
+ # the printing order should be y-mean, y-shuffle, one-hot and cluster
591
+ if verify_results['error_type'].lower() in ['mae','rmse']:
592
+ print_ver += f'\n Original {verify_results["error_type"].upper()} ({CV_type}) {verify_results["CV_score"]:.2} + {int(thres_test_unclear*100)}% & {int(thres_test_pass*100)}% threshold = {verify_results["unclear_higher_thres"]:.2} & {verify_results["higher_thres"]:.2}'
593
+ else:
594
+ print_ver += f'\n Original {verify_results["error_type"].upper()} ({CV_type}) {verify_results["CV_score"]:.2} - {int(thres_test_unclear*100)}% & {int(thres_test_pass*100)}% threshold = {verify_results["unclear_lower_thres"]:.2} & {verify_results["lower_thres"]:.2}'
595
+ print_ver += results_print[0]
596
+ print_ver += results_print[1]
597
+ print_ver += results_print[2]
598
+ print_ver += results_print[3]
599
+ if model_data['type'].lower() == 'reg':
600
+ print_ver += f"\n - Sorted {model_data['kfold']}-fold CV : R2 = {verify_results['r2_train_sorted_CV']}, MAE = {verify_results['mae_train_sorted_CV']}, RMSE = {verify_results['rmse_train_sorted_CV']}"
601
+ elif model_data['type'].lower() == 'clas':
602
+ print_ver += f"\n - Sorted CV : Accuracy = {verify_results['acc_train_sorted_CV']}, F1 score = {verify_results['f1_train_sorted_CV']}, MCC = {verify_results['mcc_train_sorted_CV']}"
603
+ # after the Sorted CV line on purpose (REPORT reads the 4 scored tests by position)
604
+ print_ver += verify_results.get('mvl_print','')
605
+
606
+ self.args.log.write(print_ver)
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.4
2
+ Name: robert
3
+ Version: 2.2.0
4
+ Summary: Refiner and Optimizer of a Bunch of Existing Regression Tools
5
+ Home-page: https://github.com/jvalegre/robert
6
+ Download-URL: https://github.com/jvalegre/robert/archive/refs/tags/2.2.0.tar.gz
7
+ Author: Juan V. Alegre Requena, David Dalmau
8
+ Author-email: jv.alegre@csic.es
9
+ License: MIT
10
+ Keywords: workflows,machine learning,cheminformatics,data curation,prediction,automated
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Build Tools
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Requires-Python: >=3.12,<3.14
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: PyYAML==6.0.3
21
+ Requires-Dist: matplotlib==3.11.1
22
+ Requires-Dist: pandas==2.3.3
23
+ Requires-Dist: numpy==2.3.4
24
+ Requires-Dist: progress==1.6.1
25
+ Requires-Dist: seaborn==0.13.2
26
+ Requires-Dist: scipy==1.18.0
27
+ Requires-Dist: scikit-learn==1.9.0
28
+ Requires-Dist: bayesian-optimization==3.3.0
29
+ Requires-Dist: numba==0.62.1
30
+ Requires-Dist: shap==0.52.0
31
+ Requires-Dist: weasyprint==63.1
32
+ Requires-Dist: PySide6==6.9.2
33
+ Requires-Dist: keyring==25.7.0; sys_platform != "win32"
34
+ Requires-Dist: PyMuPDF==1.27.2.3
35
+ Requires-Dist: pdfplumber==0.11.10
36
+ Requires-Dist: openpyxl==3.1.5
37
+ Requires-Dist: ansi2html==1.9.5
38
+ Requires-Dist: rdkit==2025.9.1
39
+ Requires-Dist: psutil==7.2.2
40
+ Requires-Dist: requests==2.34.2
41
+ Dynamic: author
42
+ Dynamic: author-email
43
+ Dynamic: classifier
44
+ Dynamic: description
45
+ Dynamic: description-content-type
46
+ Dynamic: download-url
47
+ Dynamic: home-page
48
+ Dynamic: keywords
49
+ Dynamic: license
50
+ Dynamic: license-file
51
+ Dynamic: requires-dist
52
+ Dynamic: requires-python
53
+ Dynamic: summary
54
+
55
+ Documentation in Read The Docs: https://robert.readthedocs.io