forestgump 0.1.0__tar.gz
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.
- forestgump-0.1.0/.gitignore +6 -0
- forestgump-0.1.0/LICENSE +202 -0
- forestgump-0.1.0/PKG-INFO +157 -0
- forestgump-0.1.0/README.md +134 -0
- forestgump-0.1.0/pyproject.toml +47 -0
- forestgump-0.1.0/src/forestgump/__init__.py +14 -0
- forestgump-0.1.0/src/forestgump/baselines.py +180 -0
- forestgump-0.1.0/src/forestgump/cli.py +109 -0
- forestgump-0.1.0/src/forestgump/core.py +108 -0
- forestgump-0.1.0/src/forestgump/demo.py +42 -0
- forestgump-0.1.0/src/forestgump/featurize.py +29 -0
- forestgump-0.1.0/src/forestgump/io.py +173 -0
- forestgump-0.1.0/src/forestgump/jokes.py +81 -0
- forestgump-0.1.0/src/forestgump/report.py +208 -0
- forestgump-0.1.0/src/forestgump/stats.py +81 -0
- forestgump-0.1.0/tests/conftest.py +22 -0
- forestgump-0.1.0/tests/test_baselines.py +83 -0
- forestgump-0.1.0/tests/test_cli.py +40 -0
- forestgump-0.1.0/tests/test_io.py +84 -0
- forestgump-0.1.0/tests/test_report.py +93 -0
- forestgump-0.1.0/tests/test_stats.py +46 -0
forestgump-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: forestgump
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Life is like a box of baselines. Did your cheminformatics model beat a random forest trained on Morgan fingerprints?
|
|
5
|
+
Author-email: Jenny Luo <jennyluo@berkeley.edu>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: baselines,cheminformatics,model-evaluation,morgan-fingerprint,random-forest,rdkit
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Requires-Dist: numpy>=1.24
|
|
16
|
+
Requires-Dist: pandas>=2.0
|
|
17
|
+
Requires-Dist: rdkit>=2023.9
|
|
18
|
+
Requires-Dist: scikit-learn>=1.3
|
|
19
|
+
Requires-Dist: scipy>=1.10
|
|
20
|
+
Provides-Extra: test
|
|
21
|
+
Requires-Dist: pytest>=8; extra == 'test'
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# forestgump
|
|
25
|
+
|
|
26
|
+
*Life is like a box of baselines.*
|
|
27
|
+
|
|
28
|
+
**Morgan-fingerprint baselines for cheminformatics models.**
|
|
29
|
+
|
|
30
|
+
You trained a molecular property model for 3 days on 8×H100. Did it beat a random forest trained on Morgan
|
|
31
|
+
fingerprints?
|
|
32
|
+
|
|
33
|
+
forestgump takes your molecules as SMILES, plus your labels, your cross-validation folds and your model's
|
|
34
|
+
out-of-fold predictions. It fits three baselines on **exactly the same folds**: the training mean, Tanimoto kNN on
|
|
35
|
+
Morgan fingerprints, and a random forest on Morgan fingerprints. Name a context column, such as an assay, a
|
|
36
|
+
chemical series or a reaction's catalyst, and it adds a fourth: the context mean. Then it runs a paired test to
|
|
37
|
+
decide whether your model beat the forest.
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
Your model, trained on 8×H100 for 3 days, lost to a random forest. The forest trained in 31 seconds on a CPU.
|
|
41
|
+
The forest has no GPU. The forest has no feelings. The forest won.
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install forestgump
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Try it
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
forestgump demo # a model that predicts noise. The forest wins.
|
|
54
|
+
forestgump demo --model oracle # knows the answer, beats the forest on all 5 folds, and only ties
|
|
55
|
+
forestgump demo --model oracle --repeats 3 # 15 folds is enough evidence. You win.
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The demo molecules are 105 para-disubstituted benzenes. Their labels are RDKit's Crippen logP.
|
|
59
|
+
|
|
60
|
+
The tie is not a bug. Five folds is not much evidence, and the test is built not to call a winner without it.
|
|
61
|
+
|
|
62
|
+
## Use it
|
|
63
|
+
|
|
64
|
+
You need one CSV with one row per molecule. Its columns are:
|
|
65
|
+
|
|
66
|
+
| Column | Meaning |
|
|
67
|
+
|---|---|
|
|
68
|
+
| `smiles` | the molecule |
|
|
69
|
+
| `target` | the label: a number, or one of two classes |
|
|
70
|
+
| `fold` | which test fold the row belongs to |
|
|
71
|
+
| `pred` | your model's prediction for the row, made while it was in the test fold. For a two-class target, this is the probability of the larger class label. |
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
forestgump run my_results.csv
|
|
75
|
+
forestgump run my_results.csv --smiles SMILES --target y --fold cv_fold --pred my_model
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
For **repeated** cross-validation, add one row per (molecule, repeat) and pass `--repeat repeat_column`. The test
|
|
79
|
+
set of (repeat r, fold f) is those rows. Its training set is every other row of repeat r.
|
|
80
|
+
|
|
81
|
+
To add the context mean, name one or more context columns. With several, a group is one combination of their values.
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
forestgump run my_results.csv --context catalyst base
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
From Python:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
import forestgump
|
|
91
|
+
|
|
92
|
+
report = forestgump.run(df, smiles="smiles", target="target", fold="fold", pred="pred", context=["catalyst", "base"])
|
|
93
|
+
print(report.verdict) # "win", "lose", "tie", or "refuse"
|
|
94
|
+
print(report.render())
|
|
95
|
+
report.to_json("forest.json")
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## The baselines
|
|
99
|
+
|
|
100
|
+
Each baseline is retrained on every training set, and its hyperparameters are picked from **that training set
|
|
101
|
+
only**. Test rows are only ever predicted.
|
|
102
|
+
|
|
103
|
+
- **The Mean** has nothing to tune. It predicts the training-set mean for every test row, or for a two-class
|
|
104
|
+
target the training share of the larger class.
|
|
105
|
+
- **Retrieval-Augmented Mean** appears only with `--context`, and it has nothing to tune either. For each test
|
|
106
|
+
row it retrieves the training rows with the same context values and averages their labels. A group with no
|
|
107
|
+
training rows gets the training-set mean, and the report says how many test rows that happened to.
|
|
108
|
+
- **Large Lookup Model** uses inner cross-validation, which takes milliseconds for kNN: 5 folds, or 3 below 50
|
|
109
|
+
training rows.
|
|
110
|
+
- **The Forest** fits each of its 12 configs once and keeps the one with the best out-of-bag score. Every tree
|
|
111
|
+
skips about a third of the training rows, so the forest gets a validation score for free. If you'd rather tune
|
|
112
|
+
it like everything else, `--forest-inner-cv` uses inner cross-validation instead. That fits each config once
|
|
113
|
+
per inner fold and then refits the winner, so it is about 5× slower.
|
|
114
|
+
|
|
115
|
+
| Name | What it is | Grid |
|
|
116
|
+
|---|---|---|
|
|
117
|
+
| The Mean | the training-set mean, or the class prior | none (zero parameters, zero shots, zero GPUs) |
|
|
118
|
+
| Retrieval-Augmented Mean | only with `--context`: the mean label of the training rows in the test row's group, or the training-set mean if the group has no training rows | none (it is a groupby) |
|
|
119
|
+
| Large Lookup Model | k-nearest neighbors with Tanimoto distance | k ∈ {1, 3, 5, 10} × {uniform, distance} weights × radius ∈ {2, 3} |
|
|
120
|
+
| The Forest | a random forest with 500 trees | max_features ∈ {sqrt, 0.3, 1.0} × min_samples_leaf ∈ {1, 3} × radius ∈ {2, 3} |
|
|
121
|
+
|
|
122
|
+
Both fingerprint baselines use 2048-bit Morgan fingerprints from RDKit.
|
|
123
|
+
|
|
124
|
+
## How the verdict is decided
|
|
125
|
+
|
|
126
|
+
The primary metric is RMSE for numeric targets and ROC-AUC for two-class targets. The report also gives MAE, R²
|
|
127
|
+
and Spearman ρ, or accuracy.
|
|
128
|
+
|
|
129
|
+
1. Every method is scored on every test set. The full per-test-set table is printed **before** any verdict.
|
|
130
|
+
2. Your model is compared with each baseline on the per-test-set differences, using the **Nadeau–Bengio corrected
|
|
131
|
+
resampled t-test**. CV training sets overlap, so the differences are correlated and a plain paired t-test is
|
|
132
|
+
overconfident. The correction inflates the variance by `1/J + n_test/n_train` over J test sets
|
|
133
|
+
(Nadeau & Bengio 2003; Bouckaert & Frank 2004 for repeated CV).
|
|
134
|
+
3. The p-values, three or four with `--context`, are Holm-adjusted together.
|
|
135
|
+
4. The verdict compares you with the forest at α = 0.05: **win**, **lose**, or **tie**. With fewer than 3 test
|
|
136
|
+
sets the forest declines to be judged.
|
|
137
|
+
|
|
138
|
+
The report also gives the mean difference, its confidence interval and Cohen's d_z. Use `--json` to get every
|
|
139
|
+
number, the hyperparameters chosen on each test set, and the baselines' predictions.
|
|
140
|
+
|
|
141
|
+
## Flags
|
|
142
|
+
|
|
143
|
+
| Flag | Effect |
|
|
144
|
+
|---|---|
|
|
145
|
+
| `--seriously` | plain output with no jokes, for logs and papers |
|
|
146
|
+
| `--brag "a 3-billion-parameter foundation model"` | changes how the forest describes your training |
|
|
147
|
+
| `--forest-inner-cv` | picks the forest's hyperparameters by inner CV instead of out-of-bag score. About 5× slower, and it warns you. |
|
|
148
|
+
| `--fail-if-forest-wins` | exits 1 if the forest won, so a CI pipeline goes red when your model loses |
|
|
149
|
+
| `--context catalyst base` | adds the context mean, grouping rows by these columns. The report says how many test rows had a group with no training rows and fell back to the training-set mean. |
|
|
150
|
+
| `--task regression\|binary` | overrides the task. By default a target with 2 values is binary. |
|
|
151
|
+
| `--seed 0` | the random seed for the forest's trees and the inner CV splits. Default 0. In `forestgump demo` it also sets the demo's folds and noise. |
|
|
152
|
+
| `--n-jobs -1` | how many CPU cores the forest uses. Default -1, meaning all of them. |
|
|
153
|
+
| `--alpha 0.05` | the significance level: the forest wins or loses only when the Holm-adjusted p is below it. It also sets the confidence intervals to 1 − alpha. Default 0.05. |
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
Apache-2.0.
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# forestgump
|
|
2
|
+
|
|
3
|
+
*Life is like a box of baselines.*
|
|
4
|
+
|
|
5
|
+
**Morgan-fingerprint baselines for cheminformatics models.**
|
|
6
|
+
|
|
7
|
+
You trained a molecular property model for 3 days on 8×H100. Did it beat a random forest trained on Morgan
|
|
8
|
+
fingerprints?
|
|
9
|
+
|
|
10
|
+
forestgump takes your molecules as SMILES, plus your labels, your cross-validation folds and your model's
|
|
11
|
+
out-of-fold predictions. It fits three baselines on **exactly the same folds**: the training mean, Tanimoto kNN on
|
|
12
|
+
Morgan fingerprints, and a random forest on Morgan fingerprints. Name a context column, such as an assay, a
|
|
13
|
+
chemical series or a reaction's catalyst, and it adds a fourth: the context mean. Then it runs a paired test to
|
|
14
|
+
decide whether your model beat the forest.
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
Your model, trained on 8×H100 for 3 days, lost to a random forest. The forest trained in 31 seconds on a CPU.
|
|
18
|
+
The forest has no GPU. The forest has no feelings. The forest won.
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install forestgump
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Try it
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
forestgump demo # a model that predicts noise. The forest wins.
|
|
31
|
+
forestgump demo --model oracle # knows the answer, beats the forest on all 5 folds, and only ties
|
|
32
|
+
forestgump demo --model oracle --repeats 3 # 15 folds is enough evidence. You win.
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The demo molecules are 105 para-disubstituted benzenes. Their labels are RDKit's Crippen logP.
|
|
36
|
+
|
|
37
|
+
The tie is not a bug. Five folds is not much evidence, and the test is built not to call a winner without it.
|
|
38
|
+
|
|
39
|
+
## Use it
|
|
40
|
+
|
|
41
|
+
You need one CSV with one row per molecule. Its columns are:
|
|
42
|
+
|
|
43
|
+
| Column | Meaning |
|
|
44
|
+
|---|---|
|
|
45
|
+
| `smiles` | the molecule |
|
|
46
|
+
| `target` | the label: a number, or one of two classes |
|
|
47
|
+
| `fold` | which test fold the row belongs to |
|
|
48
|
+
| `pred` | your model's prediction for the row, made while it was in the test fold. For a two-class target, this is the probability of the larger class label. |
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
forestgump run my_results.csv
|
|
52
|
+
forestgump run my_results.csv --smiles SMILES --target y --fold cv_fold --pred my_model
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
For **repeated** cross-validation, add one row per (molecule, repeat) and pass `--repeat repeat_column`. The test
|
|
56
|
+
set of (repeat r, fold f) is those rows. Its training set is every other row of repeat r.
|
|
57
|
+
|
|
58
|
+
To add the context mean, name one or more context columns. With several, a group is one combination of their values.
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
forestgump run my_results.csv --context catalyst base
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
From Python:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
import forestgump
|
|
68
|
+
|
|
69
|
+
report = forestgump.run(df, smiles="smiles", target="target", fold="fold", pred="pred", context=["catalyst", "base"])
|
|
70
|
+
print(report.verdict) # "win", "lose", "tie", or "refuse"
|
|
71
|
+
print(report.render())
|
|
72
|
+
report.to_json("forest.json")
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## The baselines
|
|
76
|
+
|
|
77
|
+
Each baseline is retrained on every training set, and its hyperparameters are picked from **that training set
|
|
78
|
+
only**. Test rows are only ever predicted.
|
|
79
|
+
|
|
80
|
+
- **The Mean** has nothing to tune. It predicts the training-set mean for every test row, or for a two-class
|
|
81
|
+
target the training share of the larger class.
|
|
82
|
+
- **Retrieval-Augmented Mean** appears only with `--context`, and it has nothing to tune either. For each test
|
|
83
|
+
row it retrieves the training rows with the same context values and averages their labels. A group with no
|
|
84
|
+
training rows gets the training-set mean, and the report says how many test rows that happened to.
|
|
85
|
+
- **Large Lookup Model** uses inner cross-validation, which takes milliseconds for kNN: 5 folds, or 3 below 50
|
|
86
|
+
training rows.
|
|
87
|
+
- **The Forest** fits each of its 12 configs once and keeps the one with the best out-of-bag score. Every tree
|
|
88
|
+
skips about a third of the training rows, so the forest gets a validation score for free. If you'd rather tune
|
|
89
|
+
it like everything else, `--forest-inner-cv` uses inner cross-validation instead. That fits each config once
|
|
90
|
+
per inner fold and then refits the winner, so it is about 5× slower.
|
|
91
|
+
|
|
92
|
+
| Name | What it is | Grid |
|
|
93
|
+
|---|---|---|
|
|
94
|
+
| The Mean | the training-set mean, or the class prior | none (zero parameters, zero shots, zero GPUs) |
|
|
95
|
+
| Retrieval-Augmented Mean | only with `--context`: the mean label of the training rows in the test row's group, or the training-set mean if the group has no training rows | none (it is a groupby) |
|
|
96
|
+
| Large Lookup Model | k-nearest neighbors with Tanimoto distance | k ∈ {1, 3, 5, 10} × {uniform, distance} weights × radius ∈ {2, 3} |
|
|
97
|
+
| The Forest | a random forest with 500 trees | max_features ∈ {sqrt, 0.3, 1.0} × min_samples_leaf ∈ {1, 3} × radius ∈ {2, 3} |
|
|
98
|
+
|
|
99
|
+
Both fingerprint baselines use 2048-bit Morgan fingerprints from RDKit.
|
|
100
|
+
|
|
101
|
+
## How the verdict is decided
|
|
102
|
+
|
|
103
|
+
The primary metric is RMSE for numeric targets and ROC-AUC for two-class targets. The report also gives MAE, R²
|
|
104
|
+
and Spearman ρ, or accuracy.
|
|
105
|
+
|
|
106
|
+
1. Every method is scored on every test set. The full per-test-set table is printed **before** any verdict.
|
|
107
|
+
2. Your model is compared with each baseline on the per-test-set differences, using the **Nadeau–Bengio corrected
|
|
108
|
+
resampled t-test**. CV training sets overlap, so the differences are correlated and a plain paired t-test is
|
|
109
|
+
overconfident. The correction inflates the variance by `1/J + n_test/n_train` over J test sets
|
|
110
|
+
(Nadeau & Bengio 2003; Bouckaert & Frank 2004 for repeated CV).
|
|
111
|
+
3. The p-values, three or four with `--context`, are Holm-adjusted together.
|
|
112
|
+
4. The verdict compares you with the forest at α = 0.05: **win**, **lose**, or **tie**. With fewer than 3 test
|
|
113
|
+
sets the forest declines to be judged.
|
|
114
|
+
|
|
115
|
+
The report also gives the mean difference, its confidence interval and Cohen's d_z. Use `--json` to get every
|
|
116
|
+
number, the hyperparameters chosen on each test set, and the baselines' predictions.
|
|
117
|
+
|
|
118
|
+
## Flags
|
|
119
|
+
|
|
120
|
+
| Flag | Effect |
|
|
121
|
+
|---|---|
|
|
122
|
+
| `--seriously` | plain output with no jokes, for logs and papers |
|
|
123
|
+
| `--brag "a 3-billion-parameter foundation model"` | changes how the forest describes your training |
|
|
124
|
+
| `--forest-inner-cv` | picks the forest's hyperparameters by inner CV instead of out-of-bag score. About 5× slower, and it warns you. |
|
|
125
|
+
| `--fail-if-forest-wins` | exits 1 if the forest won, so a CI pipeline goes red when your model loses |
|
|
126
|
+
| `--context catalyst base` | adds the context mean, grouping rows by these columns. The report says how many test rows had a group with no training rows and fell back to the training-set mean. |
|
|
127
|
+
| `--task regression\|binary` | overrides the task. By default a target with 2 values is binary. |
|
|
128
|
+
| `--seed 0` | the random seed for the forest's trees and the inner CV splits. Default 0. In `forestgump demo` it also sets the demo's folds and noise. |
|
|
129
|
+
| `--n-jobs -1` | how many CPU cores the forest uses. Default -1, meaning all of them. |
|
|
130
|
+
| `--alpha 0.05` | the significance level: the forest wins or loses only when the Holm-adjusted p is below it. It also sets the confidence intervals to 1 − alpha. Default 0.05. |
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
Apache-2.0.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.25"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "forestgump"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Life is like a box of baselines. Did your cheminformatics model beat a random forest trained on Morgan fingerprints?"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
authors = [{ name = "Jenny Luo", email = "jennyluo@berkeley.edu" }]
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
dependencies = [
|
|
15
|
+
"numpy>=1.24",
|
|
16
|
+
"pandas>=2.0",
|
|
17
|
+
"rdkit>=2023.9",
|
|
18
|
+
"scikit-learn>=1.3",
|
|
19
|
+
"scipy>=1.10",
|
|
20
|
+
]
|
|
21
|
+
keywords = ["baselines", "random-forest", "cheminformatics", "morgan-fingerprint", "rdkit", "model-evaluation"]
|
|
22
|
+
classifiers = [
|
|
23
|
+
"Development Status :: 3 - Alpha",
|
|
24
|
+
"Intended Audience :: Science/Research",
|
|
25
|
+
"Programming Language :: Python :: 3",
|
|
26
|
+
"Topic :: Scientific/Engineering :: Chemistry",
|
|
27
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.scripts]
|
|
31
|
+
forestgump = "forestgump.cli:main"
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
test = ["pytest>=8"]
|
|
35
|
+
|
|
36
|
+
[tool.hatch.build.targets.wheel]
|
|
37
|
+
packages = ["src/forestgump"]
|
|
38
|
+
|
|
39
|
+
[tool.pytest.ini_options]
|
|
40
|
+
testpaths = ["tests"]
|
|
41
|
+
|
|
42
|
+
[tool.ruff]
|
|
43
|
+
line-length = 120
|
|
44
|
+
target-version = "py310"
|
|
45
|
+
|
|
46
|
+
[tool.ruff.lint]
|
|
47
|
+
select = ["E", "F", "W", "I", "UP", "B", "RUF"]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""forestgump: did your model beat a random forest? Life is like a box of baselines."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
__version__ = version("forestgump")
|
|
7
|
+
except PackageNotFoundError: # running from a source tree
|
|
8
|
+
__version__ = "0+unknown"
|
|
9
|
+
|
|
10
|
+
from .core import run
|
|
11
|
+
from .io import InputError, load
|
|
12
|
+
from .report import Report
|
|
13
|
+
|
|
14
|
+
__all__ = ["InputError", "Report", "__version__", "load", "run"]
|