treeton 0.0.1__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.
- treeton-0.0.1/LICENSE +21 -0
- treeton-0.0.1/PKG-INFO +630 -0
- treeton-0.0.1/README.md +564 -0
- treeton-0.0.1/pyproject.toml +78 -0
- treeton-0.0.1/setup.cfg +4 -0
- treeton-0.0.1/test/test_config.py +177 -0
- treeton-0.0.1/test/test_evaluation.py +39 -0
- treeton-0.0.1/test/test_tree_box.py +106 -0
- treeton-0.0.1/treeton/__init__.py +10 -0
- treeton-0.0.1/treeton/box/__init__.py +1 -0
- treeton-0.0.1/treeton/box/base.py +619 -0
- treeton-0.0.1/treeton/cli/__init__.py +0 -0
- treeton-0.0.1/treeton/cli/cli.py +166 -0
- treeton-0.0.1/treeton/cli/predict.py +50 -0
- treeton-0.0.1/treeton/cli/train.py +41 -0
- treeton-0.0.1/treeton/config.py +175 -0
- treeton-0.0.1/treeton/metrics/__init__.py +1 -0
- treeton-0.0.1/treeton/metrics/base.py +131 -0
- treeton-0.0.1/treeton/typing.py +18 -0
- treeton-0.0.1/treeton/utils/__init__.py +0 -0
- treeton-0.0.1/treeton/utils/plotting.py +70 -0
- treeton-0.0.1/treeton.egg-info/PKG-INFO +630 -0
- treeton-0.0.1/treeton.egg-info/SOURCES.txt +25 -0
- treeton-0.0.1/treeton.egg-info/dependency_links.txt +1 -0
- treeton-0.0.1/treeton.egg-info/entry_points.txt +2 -0
- treeton-0.0.1/treeton.egg-info/requires.txt +29 -0
- treeton-0.0.1/treeton.egg-info/top_level.txt +1 -0
treeton-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [year] [fullname]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
treeton-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: treeton
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Reproducible tree-based machine learning.
|
|
5
|
+
Author-email: Eachan Johnson <eachan.johnson@crick.ac.uk>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) [year] [fullname]
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Project-URL: Homepage, https://github.com/scbirlab/treeton
|
|
28
|
+
Project-URL: Bug Tracker, https://github.com/scbirlab/treeton/issues
|
|
29
|
+
Keywords: ai,active-learning,bayesian-optimization,data,deep-learning,machine-learning
|
|
30
|
+
Classifier: Development Status :: 3 - Alpha
|
|
31
|
+
Classifier: Intended Audience :: Science/Research
|
|
32
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
39
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
40
|
+
Requires-Python: >=3.11
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
License-File: LICENSE
|
|
43
|
+
Requires-Dist: aspect-data>=0.0.7
|
|
44
|
+
Requires-Dist: carabiner-tools>=0.0.5.post3
|
|
45
|
+
Requires-Dist: datasets>=3.5.0
|
|
46
|
+
Requires-Dist: joblib>=1.3
|
|
47
|
+
Requires-Dist: numpy>=1.26
|
|
48
|
+
Requires-Dist: scikit-learn>=1.7
|
|
49
|
+
Provides-Extra: chem
|
|
50
|
+
Requires-Dist: schemist>=0.0.7; extra == "chem"
|
|
51
|
+
Provides-Extra: bio
|
|
52
|
+
Requires-Dist: vectome>=0.0.7; extra == "bio"
|
|
53
|
+
Provides-Extra: xgb
|
|
54
|
+
Requires-Dist: xgboost_cpu; extra == "xgb"
|
|
55
|
+
Provides-Extra: xgb-cuda12
|
|
56
|
+
Requires-Dist: xgboost-cu12; extra == "xgb-cuda12"
|
|
57
|
+
Provides-Extra: xgb-cuda13
|
|
58
|
+
Requires-Dist: xgboost>=3.0; extra == "xgb-cuda13"
|
|
59
|
+
Provides-Extra: lgbm
|
|
60
|
+
Requires-Dist: lightgbm[arrow,plotting,scikit-learn]>=4.0; extra == "lgbm"
|
|
61
|
+
Provides-Extra: dev
|
|
62
|
+
Requires-Dist: treeton[bio,chem,xgb]; extra == "dev"
|
|
63
|
+
Requires-Dist: pytest>=7.4; extra == "dev"
|
|
64
|
+
Requires-Dist: flake8; extra == "dev"
|
|
65
|
+
Dynamic: license-file
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# 🌳 Treeton
|
|
69
|
+
|
|
70
|
+
[GitHub Workflow Status (with branch)](https://img.shields.io/github/actions/workflow/status/scbirlab/treeton/python-test.yml)
|
|
71
|
+

|
|
72
|
+

|
|
73
|
+
|
|
74
|
+
**Treeton** is a lightweight framework for reproducible tree-based machine learning, combining declarative model configuration, data featurisation, provenance tracking, training, evaluation and checkpointing.
|
|
75
|
+
|
|
76
|
+
Treeton works with estimators implementing the familiar scikit-learn `fit(X, y)` and `predict(X)` interface. It delegates data loading and provenance to [Providence](https://github.com/scbirlab/providence) and feature transformations to [Aspect](https://github.com/scbirlab/aspect).
|
|
77
|
+
|
|
78
|
+
The goal is to make a machine-learning experiment easy to **specify, run, save and reproduce**, whether the input is a local table, molecular fingerprints or other structured scientific data.
|
|
79
|
+
|
|
80
|
+
## Features
|
|
81
|
+
|
|
82
|
+
- **Estimator-agnostic training** — instantiate compatible estimators from a JSON configuration, including scikit-learn tree models.
|
|
83
|
+
- **Composable feature transformations** — use Aspect to generate, concatenate and reuse features.
|
|
84
|
+
- **Dataset provenance** — resolve local and remote datasets using Providence, with source metadata carried into training checkpoints.
|
|
85
|
+
- **Checkpointing** — save fitted models together with pipeline configurations and training-data artefacts.
|
|
86
|
+
- **Batched prediction** — predict over Hugging Face Datasets, with optional CLI row selection.
|
|
87
|
+
- **Model evaluation** — calculate RMSE/RMSD, MAE, Pearson's *r* and Spearman's ρ.
|
|
88
|
+
- **CLI and Python API** — use the same `Box` abstraction interactively or in automated workflows.
|
|
89
|
+
|
|
90
|
+
Treeton is at an early stage of development. Random-forest regression is covered by end-to-end tests; compatibility with other estimators depends on their APIs.
|
|
91
|
+
|
|
92
|
+
## Contents
|
|
93
|
+
|
|
94
|
+
- [Installation](#installation)
|
|
95
|
+
- [Quick start](#quick-start)
|
|
96
|
+
- [Command-line interface](#command-line-interface)
|
|
97
|
+
- [Configuration](#configuration)
|
|
98
|
+
- [Python API](#python-api)
|
|
99
|
+
- [Molecular machine learning](#molecular-machine-learning)
|
|
100
|
+
- [Checkpoints and reproducibility](#checkpoints-and-reproducibility)
|
|
101
|
+
- [Development](#development)
|
|
102
|
+
- [Related packages](#related-packages)
|
|
103
|
+
|
|
104
|
+
## Installation
|
|
105
|
+
|
|
106
|
+
Treeton requires Python 3.11 or later.
|
|
107
|
+
|
|
108
|
+
### From GitHub
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
pip install "git+https://github.com/scbirlab/treeton.git@dev"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
For development:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
git clone https://github.com/scbirlab/treeton.git
|
|
118
|
+
cd treeton
|
|
119
|
+
pip install -e ".[dev]"
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Optional dependencies
|
|
123
|
+
|
|
124
|
+
Additional packages are available for specialised workflows:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# Chemical featurisation through Schemist
|
|
128
|
+
pip install -e ".[chem]"
|
|
129
|
+
|
|
130
|
+
# Biological sequence and taxonomy features through Vectome
|
|
131
|
+
pip install -e ".[bio]"
|
|
132
|
+
|
|
133
|
+
# XGBoost
|
|
134
|
+
pip install -e ".[xgb]"
|
|
135
|
+
|
|
136
|
+
# LightGBM
|
|
137
|
+
pip install -e ".[lgbm]"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
See `pyproject.toml` for the complete list of optional dependency groups, including CUDA-specific XGBoost options.
|
|
141
|
+
|
|
142
|
+
## Quick start
|
|
143
|
+
|
|
144
|
+
Train a random forest, save it and predict on new observations using a single JSON configuration.
|
|
145
|
+
|
|
146
|
+
### 1. Prepare some data
|
|
147
|
+
|
|
148
|
+
For a self-contained example, create a small CSV training dataset and a prediction dataset:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
printf 'x,y\n1,3\n2,5\n3,7\n4,9\n5,11\n6,13\n7,15\n8,17\n9,19\n10,21\n' > train.csv
|
|
152
|
+
|
|
153
|
+
printf 'x\n2.5\n5.5\n8.5\n' > unseen.csv
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### 2. Define an experiment
|
|
157
|
+
|
|
158
|
+
Save the following as `experiment.json`:
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"box": {
|
|
163
|
+
"model": {
|
|
164
|
+
"class_path": "sklearn.ensemble.RandomForestRegressor",
|
|
165
|
+
"init_args": {
|
|
166
|
+
"n_estimators": 100,
|
|
167
|
+
"random_state": 42
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
"pipeline": {
|
|
171
|
+
"column_transforms": {
|
|
172
|
+
"log_x": ["x", "log"]
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
"features": ["log_x"],
|
|
176
|
+
"target": "y"
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
This configuration specifies:
|
|
182
|
+
|
|
183
|
+
1. A `RandomForestRegressor` with reproducible initialisation.
|
|
184
|
+
2. An Aspect transform generating `log_x` from `x`.
|
|
185
|
+
3. The feature columns supplied to the estimator.
|
|
186
|
+
4. The prediction target.
|
|
187
|
+
|
|
188
|
+
Treeton converts the selected feature columns into a numeric matrix before calling the estimator.
|
|
189
|
+
|
|
190
|
+
### 3. Train
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
treeton train train.csv \
|
|
194
|
+
--config experiment.json \
|
|
195
|
+
--checkpoint model.tt
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
The `model.tt` directory contains the fitted estimator and the information required to reconstruct its preprocessing pipeline.
|
|
199
|
+
|
|
200
|
+
### 4. Predict
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
treeton predict model.tt \
|
|
204
|
+
--data unseen.csv \
|
|
205
|
+
--output predictions.parquet
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
The output contains the input observations and a prediction column named `prediction:y`.
|
|
209
|
+
|
|
210
|
+
You can also save the predictions as a Providence dataset checkpoint:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
treeton predict model.tt \
|
|
214
|
+
--data unseen.csv \
|
|
215
|
+
--checkpoint predictions.pv
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Both output options can be used together.
|
|
219
|
+
|
|
220
|
+
## Command-line interface
|
|
221
|
+
|
|
222
|
+
Treeton provides two primary commands:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
treeton train --help
|
|
226
|
+
treeton predict --help
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Training
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
treeton train DATA \
|
|
233
|
+
--config experiment.json \
|
|
234
|
+
--checkpoint model.tt
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
`DATA` can be a supported local or remote dataset specification understood by Providence.
|
|
238
|
+
|
|
239
|
+
Common training options:
|
|
240
|
+
|
|
241
|
+
| Option | Description |
|
|
242
|
+
| --- | --- |
|
|
243
|
+
| `--config` | JSON experiment configuration |
|
|
244
|
+
| `--checkpoint`, `-c` | Output model checkpoint directory |
|
|
245
|
+
| `--validation`, `-2` | Optional validation dataset |
|
|
246
|
+
| `--pipeline`, `-p` | Override the configured Aspect pipeline with a JSON file |
|
|
247
|
+
| `--set` | Override a configuration value |
|
|
248
|
+
| `--cache` | Directory for dataset and preprocessing caches |
|
|
249
|
+
|
|
250
|
+
#### Configuration overrides
|
|
251
|
+
|
|
252
|
+
Use `--set` to override nested configuration values without editing the JSON file:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
treeton train train.csv \
|
|
256
|
+
--config experiment.json \
|
|
257
|
+
--checkpoint model.tt \
|
|
258
|
+
--set box.model.init_args.n_estimators=500 \
|
|
259
|
+
--set box.model.init_args.max_depth=12
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Overrides use `dotted.path=value` notation. Values are parsed as JSON when possible, so integers, floating-point numbers, booleans, `null` and arrays are supported.
|
|
263
|
+
|
|
264
|
+
For example:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
--set box.features='["log_x","another_feature"]'
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
The corresponding feature must exist in the input data or be generated by the selected pipeline.
|
|
271
|
+
|
|
272
|
+
### Prediction
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
treeton predict MODEL_CHECKPOINT \
|
|
276
|
+
--data DATA \
|
|
277
|
+
--output predictions.parquet
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Common prediction options:
|
|
281
|
+
|
|
282
|
+
| Option | Description |
|
|
283
|
+
| --- | --- |
|
|
284
|
+
| `--data`, `-d` | Dataset on which to predict |
|
|
285
|
+
| `--output`, `-o` | Output table, e.g. CSV or Parquet |
|
|
286
|
+
| `--checkpoint`, `-c` | Output Providence dataset checkpoint |
|
|
287
|
+
| `--start` | First row to predict, inclusive |
|
|
288
|
+
| `--stop` | Row at which to stop, exclusive |
|
|
289
|
+
| `--pipeline`, `-p` | Override preprocessing pipeline |
|
|
290
|
+
| `--config` | Optional JSON prediction settings |
|
|
291
|
+
| `--set` | Override prediction settings |
|
|
292
|
+
| `--cache` | Cache directory |
|
|
293
|
+
|
|
294
|
+
For example, predict a subset of a larger dataset:
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
treeton predict model.tt \
|
|
298
|
+
--data dataset.parquet \
|
|
299
|
+
--start 10000 \
|
|
300
|
+
--stop 20000 \
|
|
301
|
+
--output predictions-10000-20000.parquet
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
The selected interval follows Python slicing semantics: `[start:stop]`.
|
|
305
|
+
|
|
306
|
+
Prediction settings may also be supplied in JSON:
|
|
307
|
+
|
|
308
|
+
```json
|
|
309
|
+
{
|
|
310
|
+
"batch_size": 2048
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
treeton predict model.tt \
|
|
316
|
+
--data unseen.csv \
|
|
317
|
+
--config predict.json \
|
|
318
|
+
--output predictions.parquet
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
## Configuration
|
|
322
|
+
|
|
323
|
+
The experiment configuration has a small number of top-level sections:
|
|
324
|
+
|
|
325
|
+
```json
|
|
326
|
+
{
|
|
327
|
+
"box": {
|
|
328
|
+
"model": {
|
|
329
|
+
"class_path": "sklearn.ensemble.RandomForestRegressor",
|
|
330
|
+
"init_args": {
|
|
331
|
+
"n_estimators": 100,
|
|
332
|
+
"random_state": 42
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
"pipeline": {},
|
|
336
|
+
"features": ["feature_1", "feature_2"],
|
|
337
|
+
"target": "response"
|
|
338
|
+
},
|
|
339
|
+
"fit": {},
|
|
340
|
+
"save": {}
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### `box.model`
|
|
345
|
+
|
|
346
|
+
The model is specified using a fully qualified Python class path and constructor arguments.
|
|
347
|
+
|
|
348
|
+
```json
|
|
349
|
+
{
|
|
350
|
+
"class_path": "sklearn.ensemble.ExtraTreesRegressor",
|
|
351
|
+
"init_args": {
|
|
352
|
+
"n_estimators": 200,
|
|
353
|
+
"random_state": 42
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
This mechanism can instantiate other compatible estimator classes available in the environment. Backend-specific behaviour may require additional integration and testing.
|
|
359
|
+
|
|
360
|
+
### `box.pipeline`
|
|
361
|
+
|
|
362
|
+
The pipeline is an [Aspect](https://github.com/scbirlab/aspect) configuration describing transformations from source columns to model features.
|
|
363
|
+
|
|
364
|
+
For example:
|
|
365
|
+
|
|
366
|
+
```json
|
|
367
|
+
{
|
|
368
|
+
"column_transforms": {
|
|
369
|
+
"log_x": ["x", "log"]
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
The `features` list refers to the logical feature names, including transformed output names.
|
|
375
|
+
|
|
376
|
+
A model can use both existing and transformed columns:
|
|
377
|
+
|
|
378
|
+
```json
|
|
379
|
+
{
|
|
380
|
+
"features": ["numeric_feature", "log_x"]
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### `box.features` and `box.target`
|
|
385
|
+
|
|
386
|
+
Features are supplied as an ordered list of column names. Each selected column can contain a scalar or a fixed-length numeric vector; Treeton concatenates them into a numeric feature matrix.
|
|
387
|
+
|
|
388
|
+
The target may be a single column or a list of columns:
|
|
389
|
+
|
|
390
|
+
```json
|
|
391
|
+
{
|
|
392
|
+
"features": ["fingerprint", "descriptors"],
|
|
393
|
+
"target": ["activity_a", "activity_b"]
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
Multi-target training requires an estimator that supports multiple outputs.
|
|
398
|
+
|
|
399
|
+
### `fit` and `save`
|
|
400
|
+
|
|
401
|
+
The `fit` section passes keyword arguments to `Box.fit()`. The `save` section passes options to the underlying Aspect pipeline checkpoint.
|
|
402
|
+
|
|
403
|
+
For example:
|
|
404
|
+
|
|
405
|
+
```json
|
|
406
|
+
{
|
|
407
|
+
"save": {
|
|
408
|
+
"save_source_data": true,
|
|
409
|
+
"save_transformed": false
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
Whether the source data are embedded or referenced affects checkpoint size and portability.
|
|
415
|
+
|
|
416
|
+
## Python API
|
|
417
|
+
|
|
418
|
+
The core abstraction is `treeton.Box`, which combines an estimator, its feature definitions and an Aspect pipeline.
|
|
419
|
+
|
|
420
|
+
### Train and predict
|
|
421
|
+
|
|
422
|
+
```python
|
|
423
|
+
import json
|
|
424
|
+
|
|
425
|
+
from treeton import Box
|
|
426
|
+
|
|
427
|
+
with open("experiment.json") as f:
|
|
428
|
+
experiment = json.load(f)
|
|
429
|
+
|
|
430
|
+
box = Box.from_config(experiment["box"])
|
|
431
|
+
|
|
432
|
+
box.fit("train.csv")
|
|
433
|
+
|
|
434
|
+
predictions = box.predict("unseen.csv")
|
|
435
|
+
print(predictions["prediction:y"])
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
`predict()` returns a Hugging Face Dataset containing prediction columns alongside the prepared input data.
|
|
439
|
+
|
|
440
|
+
### Save and restore
|
|
441
|
+
|
|
442
|
+
```python
|
|
443
|
+
box.save("model.tt")
|
|
444
|
+
|
|
445
|
+
restored = Box.load("model.tt")
|
|
446
|
+
|
|
447
|
+
predictions = restored.predict("unseen.csv")
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
The model and preprocessing pipeline are restored together.
|
|
451
|
+
|
|
452
|
+
### Use an existing estimator
|
|
453
|
+
|
|
454
|
+
You can also construct a `Box` directly:
|
|
455
|
+
|
|
456
|
+
```python
|
|
457
|
+
from sklearn.ensemble import RandomForestRegressor
|
|
458
|
+
from treeton import Box
|
|
459
|
+
|
|
460
|
+
box = Box(
|
|
461
|
+
model=RandomForestRegressor(
|
|
462
|
+
n_estimators=200,
|
|
463
|
+
random_state=42,
|
|
464
|
+
),
|
|
465
|
+
features=["x"],
|
|
466
|
+
target="y",
|
|
467
|
+
)
|
|
468
|
+
|
|
469
|
+
box.fit("train.csv")
|
|
470
|
+
box.save("model.tt")
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
A model passed directly need only implement compatible `fit()` and `predict()` methods.
|
|
474
|
+
|
|
475
|
+
### Evaluate a model
|
|
476
|
+
|
|
477
|
+
```python
|
|
478
|
+
predicted, scores = box.evaluate(
|
|
479
|
+
"train.csv",
|
|
480
|
+
metrics=["rmse", "mae", "pearson", "spearman"],
|
|
481
|
+
)
|
|
482
|
+
|
|
483
|
+
print(scores)
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
`evaluate()` returns a tuple containing the predicted dataset and a dictionary of metric values.
|
|
487
|
+
|
|
488
|
+
Available registered regression metrics include:
|
|
489
|
+
|
|
490
|
+
| Metric | Description |
|
|
491
|
+
| --- | --- |
|
|
492
|
+
| `rmsd`, `rmse` | Root mean square deviation/error |
|
|
493
|
+
| `mae` | Mean absolute error |
|
|
494
|
+
| `pearson` | Pearson correlation coefficient |
|
|
495
|
+
| `spearman` | Spearman rank correlation coefficient |
|
|
496
|
+
|
|
497
|
+
Evaluation requires the target columns to be present. For meaningful model assessment, use held-out data rather than the training set.
|
|
498
|
+
|
|
499
|
+
### Verify the training data source
|
|
500
|
+
|
|
501
|
+
When the original data source is available through Providence, its recorded provenance can be accessed and verified:
|
|
502
|
+
|
|
503
|
+
```python
|
|
504
|
+
source = box.training_data_source
|
|
505
|
+
|
|
506
|
+
if source is not None:
|
|
507
|
+
print(box.verify_training_data_source())
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
A returned `None` indicates that no verifiable source is available. Source verification does not independently guarantee reproducibility of the entire software environment.
|
|
511
|
+
|
|
512
|
+
## Molecular machine learning
|
|
513
|
+
|
|
514
|
+
Treeton is intended to work with scientific feature representations, including molecular fingerprints and descriptors.
|
|
515
|
+
|
|
516
|
+
For chemical featurisation, install the `chem` optional dependencies and specify Aspect transforms:
|
|
517
|
+
|
|
518
|
+
```json
|
|
519
|
+
{
|
|
520
|
+
"box": {
|
|
521
|
+
"model": {
|
|
522
|
+
"class_path": "sklearn.ensemble.RandomForestRegressor",
|
|
523
|
+
"init_args": {
|
|
524
|
+
"n_estimators": 200,
|
|
525
|
+
"random_state": 42
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
"pipeline": {
|
|
529
|
+
"column_transforms": {
|
|
530
|
+
"fp": ["smiles", "morgan-fingerprint"],
|
|
531
|
+
"descriptors": ["smiles", "descriptors-2d"]
|
|
532
|
+
}
|
|
533
|
+
},
|
|
534
|
+
"features": ["fp", "descriptors"],
|
|
535
|
+
"target": "activity"
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
This example assumes a dataset with `smiles` and `activity` columns. The transforms create feature vectors that Treeton concatenates before fitting the model.
|
|
541
|
+
|
|
542
|
+
Dataset specifications supported by Providence can also refer to remote resources, including Hugging Face datasets:
|
|
543
|
+
|
|
544
|
+
```bash
|
|
545
|
+
treeton train \
|
|
546
|
+
'hf://scbirlab/fang-2023-biogen-adme~scaffold-split:train' \
|
|
547
|
+
--config experiment.json \
|
|
548
|
+
--checkpoint model.tt
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
Adjust the feature and target definitions to match the selected dataset.
|
|
552
|
+
|
|
553
|
+
For dataset splitting, see [Eluent](https://github.com/scbirlab/eluent), which handles split assignments separately from model training.
|
|
554
|
+
|
|
555
|
+
## Checkpoints and reproducibility
|
|
556
|
+
|
|
557
|
+
A Treeton model checkpoint is a directory containing the saved estimator, a manifest and its Aspect pipeline checkpoint.
|
|
558
|
+
|
|
559
|
+
For example:
|
|
560
|
+
|
|
561
|
+
```text
|
|
562
|
+
model.tt/
|
|
563
|
+
├── config.json
|
|
564
|
+
├── model.joblib
|
|
565
|
+
└── training-data.as/
|
|
566
|
+
└── ...
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
`config.json` records the checkpoint schema, experiment configuration and artefact locations.
|
|
570
|
+
|
|
571
|
+
`model.joblib` stores the fitted Python estimator. Models exposing a native `save()` method may also generate a native-format artefact, although the current loader restores the joblib representation.
|
|
572
|
+
|
|
573
|
+
`training-data.as/` contains the Aspect pipeline checkpoint, including its configuration and the training-data source information managed by Providence.
|
|
574
|
+
|
|
575
|
+
The pipeline can preserve references to immutable remote datasets or package local source data, according to its checkpoint options.
|
|
576
|
+
|
|
577
|
+
### Reproducibility considerations
|
|
578
|
+
|
|
579
|
+
A checkpoint makes model restoration convenient, but exact reproducibility also depends on:
|
|
580
|
+
|
|
581
|
+
- The original data and its version or checksum.
|
|
582
|
+
- The preprocessing implementation and dependencies.
|
|
583
|
+
- The fitted model's software versions.
|
|
584
|
+
- Random seeds and numerical execution environment.
|
|
585
|
+
|
|
586
|
+
For long-term archival, retain the checkpoint alongside a record of the package environment, such as a lock file or container image.
|
|
587
|
+
|
|
588
|
+
**Security:** joblib uses pickle-based deserialization. Only load model checkpoints from trusted sources.
|
|
589
|
+
|
|
590
|
+
## Development
|
|
591
|
+
|
|
592
|
+
Install the development dependencies:
|
|
593
|
+
|
|
594
|
+
```bash
|
|
595
|
+
pip install -e ".[dev]"
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
Run the unit and integration tests:
|
|
599
|
+
|
|
600
|
+
```bash
|
|
601
|
+
pytest -q test
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
Run module doctests:
|
|
605
|
+
|
|
606
|
+
```bash
|
|
607
|
+
pytest -q treeton --doctest-modules
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
The GitHub Actions workflows also exercise the command-line interface, including training and prediction on a remote scientific dataset.
|
|
611
|
+
|
|
612
|
+
To report a bug or propose a feature, open an [issue](https://github.com/scbirlab/treeton/issues).
|
|
613
|
+
|
|
614
|
+
## Related packages
|
|
615
|
+
|
|
616
|
+
Treeton is designed to work as part of a modular machine-learning workflow:
|
|
617
|
+
|
|
618
|
+
| Package | Role |
|
|
619
|
+
| --- | --- |
|
|
620
|
+
| [Providence](https://github.com/scbirlab/providence) | Dataset resolution, provenance and checkpointing |
|
|
621
|
+
| [Eluent](https://github.com/scbirlab/eluent) | Dataset splitting and split provenance |
|
|
622
|
+
| [Aspect](https://github.com/scbirlab/aspect) | Feature transformation and representation |
|
|
623
|
+
| [Treeton](https://github.com/scbirlab/treeton) | Tree-based estimator training and evaluation |
|
|
624
|
+
| [Duvidnn](https://github.com/scbirlab/duvidnn) | Neural-network modelling and uncertainty methods |
|
|
625
|
+
|
|
626
|
+
Each package has a separate responsibility, making it possible to reuse the same data sources, splits and feature representations across different model families.
|
|
627
|
+
|
|
628
|
+
## License
|
|
629
|
+
|
|
630
|
+
Treeton is distributed under the [MIT License](LICENSE).
|