caf.brain 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.
- caf_brain-0.1.0/LICENSE +22 -0
- caf_brain-0.1.0/PKG-INFO +195 -0
- caf_brain-0.1.0/README.md +118 -0
- caf_brain-0.1.0/pyproject.toml +122 -0
- caf_brain-0.1.0/requirements.txt +12 -0
- caf_brain-0.1.0/requirements_dev.txt +15 -0
- caf_brain-0.1.0/requirements_vision.txt +12 -0
- caf_brain-0.1.0/setup.cfg +4 -0
- caf_brain-0.1.0/src/caf/brain/__init__.py +3 -0
- caf_brain-0.1.0/src/caf/brain/_version.py +15 -0
- caf_brain-0.1.0/src/caf/brain/ml/__init__.py +16 -0
- caf_brain-0.1.0/src/caf/brain/ml/__main__.py +78 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/__init__.py +4 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/_baseclasses.py +155 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/_ml_inputs.py +350 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/data_analysis/__init__.py +1 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/data_analysis/functions.py +1239 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/data_analysis/main.py +181 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/feature_selection/__init__.py +0 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/feature_selection/functions.py +654 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/feature_selection/main.py +186 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/hparam_optimisation/__init__.py +27 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/hparam_optimisation/functions.py +308 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/hparam_optimisation/main.py +108 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/model_selection/__init__.py +27 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/model_selection/functions.py +746 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/model_selection/main.py +112 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/prediction/__init__.py +27 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/prediction/functions.py +129 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/prediction/main.py +64 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/prediction_model_main.py +205 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/process_data_functions/__init__.py +27 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/process_data_functions/encode_and_scale.py +549 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/process_data_functions/input_data.py +579 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/process_data_functions/main.py +249 -0
- caf_brain-0.1.0/src/caf/brain/ml/_functions/process_data_functions/split_data_into_ttv.py +317 -0
- caf_brain-0.1.0/src/caf/brain/ml/_ml.py +634 -0
- caf_brain-0.1.0/src/caf/brain/py.typed +0 -0
- caf_brain-0.1.0/src/caf.brain.egg-info/PKG-INFO +195 -0
- caf_brain-0.1.0/src/caf.brain.egg-info/SOURCES.txt +42 -0
- caf_brain-0.1.0/src/caf.brain.egg-info/dependency_links.txt +1 -0
- caf_brain-0.1.0/src/caf.brain.egg-info/entry_points.txt +2 -0
- caf_brain-0.1.0/src/caf.brain.egg-info/requires.txt +38 -0
- caf_brain-0.1.0/src/caf.brain.egg-info/top_level.txt +1 -0
caf_brain-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright © Transport for the North (“TfN”) (2025).
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Use of this software and associated documentation files (“the Software”) by you indicates your acceptance of the terms and conditions below (“the Licence”).
|
|
5
|
+
We make available the Software to you on the basis of this Licence. We do not sell the Software to you. We remain the owners of the Software at all times.
|
|
6
|
+
|
|
7
|
+
We grant you a non-exclusive, worldwide, royalty-free, perpetual licence:
|
|
8
|
+
(a) to use the Software;
|
|
9
|
+
(b) to develop, modify and maintain the Software;
|
|
10
|
+
(c) copy, publish, distribute and transmit the Software;
|
|
11
|
+
(d) adapt the Software.
|
|
12
|
+
|
|
13
|
+
Where you do any of the above you must acknowledge the source of the Software in your product or application by including or linking the following attribution statement in a prominent and noticeable location in or in the context of your product or application:
|
|
14
|
+
“Outputs derived from CAF.Brain (the Common Analytical Framework AI Toolkit), developed by Transport for the North [https://github.com/Transport-for-the-North/caf.brain]”
|
|
15
|
+
|
|
16
|
+
Any adaptations applied to the Software before application should be briefly described alongside the above citation. We encourage you to submit to us any adaptations to the Software and where you choose to do so your submissions will be considered for integration into the Software.
|
|
17
|
+
|
|
18
|
+
The above are important conditions of this Licence and if you fail to comply with them the rights granted to you under this Licence will end automatically.
|
|
19
|
+
This Licence does not grant you any right to use the Software in a way that suggests any official status or that we endorse you or your use of the Software.
|
|
20
|
+
The Software is licenced 'as is' and we exclude all representations, warranties, obligations and liabilities in relation to the Software to the maximum extent permitted by law.
|
|
21
|
+
We are not liable for any errors or omissions in the Software and shall not be liable for any loss, injury or damage of any kind caused by its use. We do not guarantee the continued supply of the Software.
|
|
22
|
+
This Licence is governed by the laws of the jurisdiction in which we have our principal place of business.
|
caf_brain-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: caf.brain
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Common Analytical Framework package of Machine and Deep Learning tools.
|
|
5
|
+
Author: Transport for the North
|
|
6
|
+
License: Copyright © Transport for the North (“TfN”) (2025).
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Use of this software and associated documentation files (“the Software”) by you indicates your acceptance of the terms and conditions below (“the Licence”).
|
|
10
|
+
We make available the Software to you on the basis of this Licence. We do not sell the Software to you. We remain the owners of the Software at all times.
|
|
11
|
+
|
|
12
|
+
We grant you a non-exclusive, worldwide, royalty-free, perpetual licence:
|
|
13
|
+
(a) to use the Software;
|
|
14
|
+
(b) to develop, modify and maintain the Software;
|
|
15
|
+
(c) copy, publish, distribute and transmit the Software;
|
|
16
|
+
(d) adapt the Software.
|
|
17
|
+
|
|
18
|
+
Where you do any of the above you must acknowledge the source of the Software in your product or application by including or linking the following attribution statement in a prominent and noticeable location in or in the context of your product or application:
|
|
19
|
+
“Outputs derived from CAF.Brain (the Common Analytical Framework AI Toolkit), developed by Transport for the North [https://github.com/Transport-for-the-North/caf.brain]”
|
|
20
|
+
|
|
21
|
+
Any adaptations applied to the Software before application should be briefly described alongside the above citation. We encourage you to submit to us any adaptations to the Software and where you choose to do so your submissions will be considered for integration into the Software.
|
|
22
|
+
|
|
23
|
+
The above are important conditions of this Licence and if you fail to comply with them the rights granted to you under this Licence will end automatically.
|
|
24
|
+
This Licence does not grant you any right to use the Software in a way that suggests any official status or that we endorse you or your use of the Software.
|
|
25
|
+
The Software is licenced 'as is' and we exclude all representations, warranties, obligations and liabilities in relation to the Software to the maximum extent permitted by law.
|
|
26
|
+
We are not liable for any errors or omissions in the Software and shall not be liable for any loss, injury or damage of any kind caused by its use. We do not guarantee the continued supply of the Software.
|
|
27
|
+
This Licence is governed by the laws of the jurisdiction in which we have our principal place of business.
|
|
28
|
+
|
|
29
|
+
Project-URL: Bug Tracker, https://github.com/transport-for-the-north/caf.brain/issues
|
|
30
|
+
Project-URL: Homepage, https://github.com/transport-for-the-north/caf.brain
|
|
31
|
+
Project-URL: Source, https://github.com/transport-for-the-north/caf.brain
|
|
32
|
+
Project-URL: Documentation, https://cafbrain.readthedocs.io/
|
|
33
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
37
|
+
Requires-Python: <3.13,>=3.10
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
License-File: LICENSE
|
|
40
|
+
Requires-Dist: caf.toolkit>=0.9.0
|
|
41
|
+
Requires-Dist: joblib>=1.4.2
|
|
42
|
+
Requires-Dist: matplotlib>=3.8.4
|
|
43
|
+
Requires-Dist: mlxtend>=0.23.1
|
|
44
|
+
Requires-Dist: numpy>=1.23.3
|
|
45
|
+
Requires-Dist: pandas>=2.2.3
|
|
46
|
+
Requires-Dist: PyYAML>=6.0.2
|
|
47
|
+
Requires-Dist: scikit-learn>=1.6.1
|
|
48
|
+
Requires-Dist: scipy>=1.15.1
|
|
49
|
+
Requires-Dist: seaborn>=0.13.2
|
|
50
|
+
Requires-Dist: statsmodels>=0.14.0
|
|
51
|
+
Requires-Dist: tqdm>=4.66.2
|
|
52
|
+
Provides-Extra: dev
|
|
53
|
+
Requires-Dist: black>=24; extra == "dev"
|
|
54
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
55
|
+
Requires-Dist: mypy_extensions>=1.0.0; extra == "dev"
|
|
56
|
+
Requires-Dist: pydocstyle[toml]>=6.3; extra == "dev"
|
|
57
|
+
Requires-Dist: pylint>=3.2; extra == "dev"
|
|
58
|
+
Requires-Dist: isort>=5.13; extra == "dev"
|
|
59
|
+
Requires-Dist: pytest>=8.3; extra == "dev"
|
|
60
|
+
Requires-Dist: pytest-cov>=5.0; extra == "dev"
|
|
61
|
+
Requires-Dist: pytest-xdist>=3.6; extra == "dev"
|
|
62
|
+
Requires-Dist: versioningit>=3.1; extra == "dev"
|
|
63
|
+
Provides-Extra: vision
|
|
64
|
+
Requires-Dist: geopandas>=1.0.1; extra == "vision"
|
|
65
|
+
Requires-Dist: albumentations>=2.0.8; extra == "vision"
|
|
66
|
+
Requires-Dist: beautifulsoup4>=4.12.3; extra == "vision"
|
|
67
|
+
Requires-Dist: dbfread>=2.0.7; extra == "vision"
|
|
68
|
+
Requires-Dist: optuna>=4.4.0; extra == "vision"
|
|
69
|
+
Requires-Dist: Pillow>=11.3.0; extra == "vision"
|
|
70
|
+
Requires-Dist: pyproj>=3.7.1; extra == "vision"
|
|
71
|
+
Requires-Dist: rasterio>=1.4.3; extra == "vision"
|
|
72
|
+
Requires-Dist: ray>=2.48.0; extra == "vision"
|
|
73
|
+
Requires-Dist: tensorflow>=2.10.0; extra == "vision"
|
|
74
|
+
Requires-Dist: torch>=2.8.0; extra == "vision"
|
|
75
|
+
Requires-Dist: ultralytics>=8.3.175; extra == "vision"
|
|
76
|
+
Dynamic: license-file
|
|
77
|
+
|
|
78
|
+

|
|
79
|
+
|
|
80
|
+
<h1 align="center">CAF.brAIn</h1>
|
|
81
|
+
|
|
82
|
+
<p align="center">
|
|
83
|
+
<a href="https://transport-for-the-north.github.io/CAF-Handbook/python_tools/framework.html">
|
|
84
|
+
<img alt="CAF Status - Pre-Alpha" src="https://img.shields.io/badge/CAF%20Status-Pre--Alpha-orange">
|
|
85
|
+
</a>
|
|
86
|
+
<a href="https://pypi.org/project/caf.brain/">
|
|
87
|
+
<img alt="Supported Python versions" src="https://img.shields.io/pypi/pyversions/caf.brain.svg?style=flat-square">
|
|
88
|
+
</a>
|
|
89
|
+
<a href="https://pypi.org/project/caf.brain/">
|
|
90
|
+
<img alt="Latest release" src="https://img.shields.io/github/release/transport-for-the-north/caf.brain.svg?style=flat-square&maxAge=86400">
|
|
91
|
+
</a>
|
|
92
|
+
<a href="https://anaconda.org/conda-forge/caf.brain">
|
|
93
|
+
<img alt="Conda" src="https://img.shields.io/conda/v/conda-forge/caf.brain?style=flat-square&logo=condaforge">
|
|
94
|
+
</a>
|
|
95
|
+
</p>
|
|
96
|
+
<p align="center">
|
|
97
|
+
<a href="https://app.codecov.io/gh/transport-for-the-north/caf.brain">
|
|
98
|
+
<img alt="Coverage" src="https://img.shields.io/codecov/c/github/transport-for-the-north/caf.brain.svg?branch=main&style=flat-square&logo=CodeCov">
|
|
99
|
+
</a>
|
|
100
|
+
<a href="https://github.com/transport-for-the-north/caf.brain/actions?query=event%3Apush">
|
|
101
|
+
<img alt="Testing Badge" src="https://img.shields.io/github/actions/workflow/status/transport-for-the-north/caf.brain/tests.yml?style=flat-square&logo=GitHub&label=Tests">
|
|
102
|
+
</a>
|
|
103
|
+
<a href='https://cafbrain.readthedocs.io/en/stable/?badge=stable'>
|
|
104
|
+
<img alt='Documentation Status' src="https://img.shields.io/readthedocs/cafbrain?style=flat-square&logo=readthedocs">
|
|
105
|
+
</a>
|
|
106
|
+
<a href="https://github.com/psf/black">
|
|
107
|
+
<img alt="code style: black" src="https://img.shields.io/badge/code%20format-black-000000.svg">
|
|
108
|
+
</a>
|
|
109
|
+
</p>
|
|
110
|
+
|
|
111
|
+
> [!WARNING]
|
|
112
|
+
> This package is in an early stage of development so features may change or be removed.
|
|
113
|
+
> If using this package it is recommended to set a specific version and check before
|
|
114
|
+
> upgrading to a new version.
|
|
115
|
+
|
|
116
|
+
Common Analytical Framework package of Machine and Deep Learning tools.
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
## Common Analytical Framework
|
|
121
|
+
|
|
122
|
+
This package is sits within the [Common Analytical Framework (CAF)](https://transport-for-the-north.github.io/caf_homepage/intro.html),
|
|
123
|
+
which is a collaboration between transport bodies in the UK to develop and maintain commonly used
|
|
124
|
+
transport analytics and appraisal tools.
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
<details><summary><h2>Contributing</h2></summary>
|
|
129
|
+
|
|
130
|
+
CAF.brain happily accepts contributions.
|
|
131
|
+
|
|
132
|
+
The best way to contribute to this project is to go to the [issues tab](https://github.com/transport-for-the-north/caf.brain/issues)
|
|
133
|
+
and report bugs or submit a feature request. This helps CAF.brain become more
|
|
134
|
+
stable and full-featured. Please check the closed bugs before submitting a bug report to see if your
|
|
135
|
+
question has already been answered.
|
|
136
|
+
|
|
137
|
+
Please see our [contribution guidelines](https://github.com/Transport-for-the-North/.github/blob/main/CONTRIBUTING.rst)
|
|
138
|
+
for details on contributing to the codebase or documentation.
|
|
139
|
+
</details>
|
|
140
|
+
|
|
141
|
+
<details><summary><h2>Documentation</h2></summary>
|
|
142
|
+
|
|
143
|
+
Documentation is created using [Sphinx](https://www.sphinx-doc.org/en/master/index.html) and is hosted online at
|
|
144
|
+
[cafbrain.readthedocs](https://cafbrain.readthedocs.io/en/stable/).
|
|
145
|
+
|
|
146
|
+
The documentation can be built locally once all the docs requirements
|
|
147
|
+
([`docs/requirements.txt`](docs/requirements.txt)) are installed into your Python environment.
|
|
148
|
+
|
|
149
|
+
The provided make batch file, (inside the docs folder), allow for building the documentation in
|
|
150
|
+
various target formats. The command for building the documentation is `make {target}`
|
|
151
|
+
(called from within docs/), where `{target}` is the type of documentation format to build. A full
|
|
152
|
+
list of all available target formats can be seen by running the `make` command without any
|
|
153
|
+
arguments but the two most common are detailed below.
|
|
154
|
+
|
|
155
|
+
### HTML
|
|
156
|
+
|
|
157
|
+
The HTML documentation (seen on Read the Docs) can be built using the `make html` command, this
|
|
158
|
+
will build the web-based documentation and provide an index.html file as the homepage,
|
|
159
|
+
[`docs/build/html/index.html`](docs/build/html/index.html).
|
|
160
|
+
|
|
161
|
+
### PDF
|
|
162
|
+
|
|
163
|
+
The PDF documentation has some other requirements before it can be built as Sphinx will first
|
|
164
|
+
build a [LaTeX](https://www.latex-project.org/) version of the documentation and then use an
|
|
165
|
+
installed TeX distribution to build the PDF from those. If you already have a TeX distribution
|
|
166
|
+
setup then you can build the PDF with `make latexpdf`, otherwise follow the instructions below.
|
|
167
|
+
|
|
168
|
+
Installing LaTeX on Windows is best done using [MiKTeX](https://miktex.org/), as this provides a
|
|
169
|
+
simple way of handling any additional TeX packages. Details of other operating systems and TeX
|
|
170
|
+
distributions can be found on the [Getting LaTeX](https://www.latex-project.org/get/) page on
|
|
171
|
+
LaTeX's website.
|
|
172
|
+
|
|
173
|
+
MiKTeX provides an installer on its website [miktex.org/download](https://miktex.org/download),
|
|
174
|
+
which will run through the process of getting it installed and setup. In addition to MiKTeX
|
|
175
|
+
the specific process Sphinx uses for building PDFs is [Latexmk](https://mg.readthedocs.io/latexmk.html),
|
|
176
|
+
which is a Perl script and so requires Perl to be installed on your machine, this can be done with an
|
|
177
|
+
installer provided by [Strawberry Perl](https://strawberryperl.com/).
|
|
178
|
+
|
|
179
|
+
Once MiKTex and Perl are installed you are able to build the PDF from the LaTeX files, Sphinx
|
|
180
|
+
provides a target (latexpdf) which builds the LaTeX files then immediately builds the PDF. When
|
|
181
|
+
running `make latexpdf` MiKTeX may ask for permission to installed some required TeX packages.
|
|
182
|
+
Once the command has finished the PDF will be located at
|
|
183
|
+
[`docs/build/latex/cafbrain.pdf`](docs/build/latex/cafbrain.pdf).
|
|
184
|
+
</details>
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
## Maintainers
|
|
188
|
+
|
|
189
|
+
- Adil Zaheer (AdilZ16)
|
|
190
|
+
- Ben Taylor (BenTaylor-TfN)
|
|
191
|
+
|
|
192
|
+
## Credit
|
|
193
|
+
|
|
194
|
+
This project was created using the Common Analytical Framework cookiecutter template found here:
|
|
195
|
+
<https://github.com/Transport-for-the-North/cookiecutter-caf>
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
<h1 align="center">CAF.brAIn</h1>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://transport-for-the-north.github.io/CAF-Handbook/python_tools/framework.html">
|
|
7
|
+
<img alt="CAF Status - Pre-Alpha" src="https://img.shields.io/badge/CAF%20Status-Pre--Alpha-orange">
|
|
8
|
+
</a>
|
|
9
|
+
<a href="https://pypi.org/project/caf.brain/">
|
|
10
|
+
<img alt="Supported Python versions" src="https://img.shields.io/pypi/pyversions/caf.brain.svg?style=flat-square">
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://pypi.org/project/caf.brain/">
|
|
13
|
+
<img alt="Latest release" src="https://img.shields.io/github/release/transport-for-the-north/caf.brain.svg?style=flat-square&maxAge=86400">
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://anaconda.org/conda-forge/caf.brain">
|
|
16
|
+
<img alt="Conda" src="https://img.shields.io/conda/v/conda-forge/caf.brain?style=flat-square&logo=condaforge">
|
|
17
|
+
</a>
|
|
18
|
+
</p>
|
|
19
|
+
<p align="center">
|
|
20
|
+
<a href="https://app.codecov.io/gh/transport-for-the-north/caf.brain">
|
|
21
|
+
<img alt="Coverage" src="https://img.shields.io/codecov/c/github/transport-for-the-north/caf.brain.svg?branch=main&style=flat-square&logo=CodeCov">
|
|
22
|
+
</a>
|
|
23
|
+
<a href="https://github.com/transport-for-the-north/caf.brain/actions?query=event%3Apush">
|
|
24
|
+
<img alt="Testing Badge" src="https://img.shields.io/github/actions/workflow/status/transport-for-the-north/caf.brain/tests.yml?style=flat-square&logo=GitHub&label=Tests">
|
|
25
|
+
</a>
|
|
26
|
+
<a href='https://cafbrain.readthedocs.io/en/stable/?badge=stable'>
|
|
27
|
+
<img alt='Documentation Status' src="https://img.shields.io/readthedocs/cafbrain?style=flat-square&logo=readthedocs">
|
|
28
|
+
</a>
|
|
29
|
+
<a href="https://github.com/psf/black">
|
|
30
|
+
<img alt="code style: black" src="https://img.shields.io/badge/code%20format-black-000000.svg">
|
|
31
|
+
</a>
|
|
32
|
+
</p>
|
|
33
|
+
|
|
34
|
+
> [!WARNING]
|
|
35
|
+
> This package is in an early stage of development so features may change or be removed.
|
|
36
|
+
> If using this package it is recommended to set a specific version and check before
|
|
37
|
+
> upgrading to a new version.
|
|
38
|
+
|
|
39
|
+
Common Analytical Framework package of Machine and Deep Learning tools.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## Common Analytical Framework
|
|
44
|
+
|
|
45
|
+
This package is sits within the [Common Analytical Framework (CAF)](https://transport-for-the-north.github.io/caf_homepage/intro.html),
|
|
46
|
+
which is a collaboration between transport bodies in the UK to develop and maintain commonly used
|
|
47
|
+
transport analytics and appraisal tools.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
<details><summary><h2>Contributing</h2></summary>
|
|
52
|
+
|
|
53
|
+
CAF.brain happily accepts contributions.
|
|
54
|
+
|
|
55
|
+
The best way to contribute to this project is to go to the [issues tab](https://github.com/transport-for-the-north/caf.brain/issues)
|
|
56
|
+
and report bugs or submit a feature request. This helps CAF.brain become more
|
|
57
|
+
stable and full-featured. Please check the closed bugs before submitting a bug report to see if your
|
|
58
|
+
question has already been answered.
|
|
59
|
+
|
|
60
|
+
Please see our [contribution guidelines](https://github.com/Transport-for-the-North/.github/blob/main/CONTRIBUTING.rst)
|
|
61
|
+
for details on contributing to the codebase or documentation.
|
|
62
|
+
</details>
|
|
63
|
+
|
|
64
|
+
<details><summary><h2>Documentation</h2></summary>
|
|
65
|
+
|
|
66
|
+
Documentation is created using [Sphinx](https://www.sphinx-doc.org/en/master/index.html) and is hosted online at
|
|
67
|
+
[cafbrain.readthedocs](https://cafbrain.readthedocs.io/en/stable/).
|
|
68
|
+
|
|
69
|
+
The documentation can be built locally once all the docs requirements
|
|
70
|
+
([`docs/requirements.txt`](docs/requirements.txt)) are installed into your Python environment.
|
|
71
|
+
|
|
72
|
+
The provided make batch file, (inside the docs folder), allow for building the documentation in
|
|
73
|
+
various target formats. The command for building the documentation is `make {target}`
|
|
74
|
+
(called from within docs/), where `{target}` is the type of documentation format to build. A full
|
|
75
|
+
list of all available target formats can be seen by running the `make` command without any
|
|
76
|
+
arguments but the two most common are detailed below.
|
|
77
|
+
|
|
78
|
+
### HTML
|
|
79
|
+
|
|
80
|
+
The HTML documentation (seen on Read the Docs) can be built using the `make html` command, this
|
|
81
|
+
will build the web-based documentation and provide an index.html file as the homepage,
|
|
82
|
+
[`docs/build/html/index.html`](docs/build/html/index.html).
|
|
83
|
+
|
|
84
|
+
### PDF
|
|
85
|
+
|
|
86
|
+
The PDF documentation has some other requirements before it can be built as Sphinx will first
|
|
87
|
+
build a [LaTeX](https://www.latex-project.org/) version of the documentation and then use an
|
|
88
|
+
installed TeX distribution to build the PDF from those. If you already have a TeX distribution
|
|
89
|
+
setup then you can build the PDF with `make latexpdf`, otherwise follow the instructions below.
|
|
90
|
+
|
|
91
|
+
Installing LaTeX on Windows is best done using [MiKTeX](https://miktex.org/), as this provides a
|
|
92
|
+
simple way of handling any additional TeX packages. Details of other operating systems and TeX
|
|
93
|
+
distributions can be found on the [Getting LaTeX](https://www.latex-project.org/get/) page on
|
|
94
|
+
LaTeX's website.
|
|
95
|
+
|
|
96
|
+
MiKTeX provides an installer on its website [miktex.org/download](https://miktex.org/download),
|
|
97
|
+
which will run through the process of getting it installed and setup. In addition to MiKTeX
|
|
98
|
+
the specific process Sphinx uses for building PDFs is [Latexmk](https://mg.readthedocs.io/latexmk.html),
|
|
99
|
+
which is a Perl script and so requires Perl to be installed on your machine, this can be done with an
|
|
100
|
+
installer provided by [Strawberry Perl](https://strawberryperl.com/).
|
|
101
|
+
|
|
102
|
+
Once MiKTex and Perl are installed you are able to build the PDF from the LaTeX files, Sphinx
|
|
103
|
+
provides a target (latexpdf) which builds the LaTeX files then immediately builds the PDF. When
|
|
104
|
+
running `make latexpdf` MiKTeX may ask for permission to installed some required TeX packages.
|
|
105
|
+
Once the command has finished the PDF will be located at
|
|
106
|
+
[`docs/build/latex/cafbrain.pdf`](docs/build/latex/cafbrain.pdf).
|
|
107
|
+
</details>
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
## Maintainers
|
|
111
|
+
|
|
112
|
+
- Adil Zaheer (AdilZ16)
|
|
113
|
+
- Ben Taylor (BenTaylor-TfN)
|
|
114
|
+
|
|
115
|
+
## Credit
|
|
116
|
+
|
|
117
|
+
This project was created using the Common Analytical Framework cookiecutter template found here:
|
|
118
|
+
<https://github.com/Transport-for-the-North/cookiecutter-caf>
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64.0.0", "versioningit"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "caf.brain"
|
|
7
|
+
dynamic = ["version", "dependencies", "optional-dependencies"]
|
|
8
|
+
description = "Common Analytical Framework package of Machine and Deep Learning tools."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { "file" = "LICENSE" }
|
|
11
|
+
requires-python = ">=3.10,<3.13"
|
|
12
|
+
authors = [{ name = "Transport for the North" }]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
15
|
+
"Programming Language :: Python :: 3.10",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
"Bug Tracker" = "https://github.com/transport-for-the-north/caf.brain/issues"
|
|
22
|
+
Homepage = "https://github.com/transport-for-the-north/caf.brain"
|
|
23
|
+
Source = "https://github.com/transport-for-the-north/caf.brain"
|
|
24
|
+
Documentation = "https://cafbrain.readthedocs.io/"
|
|
25
|
+
|
|
26
|
+
[tool.setuptools.dynamic]
|
|
27
|
+
dependencies = { "file" = "requirements.txt" }
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.dynamic.optional-dependencies]
|
|
30
|
+
dev = { "file" = "requirements_dev.txt" }
|
|
31
|
+
vision = { "file" = "requirements_vision.txt" }
|
|
32
|
+
|
|
33
|
+
# Dynamic versioning for editable installs
|
|
34
|
+
[tool.setuptools.cmdclass]
|
|
35
|
+
build_py = "versioningit.cmdclass.build_py"
|
|
36
|
+
sdist = "versioningit.cmdclass.sdist"
|
|
37
|
+
|
|
38
|
+
# Packaging options
|
|
39
|
+
[tool.setuptools.packages.find]
|
|
40
|
+
where = ["src"]
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.package-data]
|
|
43
|
+
"caf.brain" = ["py.typed"]
|
|
44
|
+
|
|
45
|
+
# Linters
|
|
46
|
+
[tool.black]
|
|
47
|
+
line-length = 95
|
|
48
|
+
target-version = ['py310']
|
|
49
|
+
|
|
50
|
+
[tool.pylint.messages_control]
|
|
51
|
+
disable = [
|
|
52
|
+
"line-too-long", # Compatibility with black
|
|
53
|
+
"too-many-lines",
|
|
54
|
+
"use-dict-literal",
|
|
55
|
+
"use-list-literal",
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
# Pylint settings
|
|
59
|
+
[tool.pylint.basic]
|
|
60
|
+
good-names = ["df", "fn", "ca", "tp", "x", "i"]
|
|
61
|
+
|
|
62
|
+
[tool.pylint.main]
|
|
63
|
+
ignore = ["__init__.py", "_version.py"]
|
|
64
|
+
|
|
65
|
+
[tool.pylint.design]
|
|
66
|
+
max-args = 10
|
|
67
|
+
max-attributes = 15
|
|
68
|
+
max-statements = 100
|
|
69
|
+
|
|
70
|
+
[tool.mypy]
|
|
71
|
+
packages = ["caf.brain"]
|
|
72
|
+
namespace_packages = true
|
|
73
|
+
ignore_missing_imports = true
|
|
74
|
+
allow_redefinition = true
|
|
75
|
+
|
|
76
|
+
[tool.pydocstyle]
|
|
77
|
+
convention = "numpy"
|
|
78
|
+
match = '(?!_test)(?!test_)(?!__init__).*\.py'
|
|
79
|
+
add-ignore = [
|
|
80
|
+
"D202", # Temporary compatibility with black
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
[tool.isort]
|
|
84
|
+
profile = "black"
|
|
85
|
+
src_paths = ["src", "tests"]
|
|
86
|
+
|
|
87
|
+
skip = ["__init__.py", "_version.py"]
|
|
88
|
+
skip_glob = [".*"]
|
|
89
|
+
|
|
90
|
+
# Section commenting
|
|
91
|
+
import_heading_stdlib = "Built-Ins"
|
|
92
|
+
import_heading_thirdparty = "Third Party"
|
|
93
|
+
import_heading_firstparty = "Local Imports"
|
|
94
|
+
|
|
95
|
+
[tool.pytest.ini_options]
|
|
96
|
+
pythonpath = ["src"]
|
|
97
|
+
addopts = """\
|
|
98
|
+
--cov=caf --cov-report=xml -n auto \
|
|
99
|
+
--doctest-modules --ignore=examples \
|
|
100
|
+
--junitxml=junit.xml -o junit_family=legacy\
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
[tool.coverage.report]
|
|
104
|
+
include_namespace_packages = true
|
|
105
|
+
|
|
106
|
+
# Versioning
|
|
107
|
+
[tool.versioningit.vcs]
|
|
108
|
+
method = "git"
|
|
109
|
+
match = ["v*"]
|
|
110
|
+
default-tag = "0.0.1"
|
|
111
|
+
|
|
112
|
+
[tool.versioningit.onbuild]
|
|
113
|
+
source-file = "src/caf/brain/_version.py"
|
|
114
|
+
build-file = "caf/brain/_version.py"
|
|
115
|
+
|
|
116
|
+
[tool.versioningit.format]
|
|
117
|
+
distance = "{base_version}+{distance}.{vcs}{rev}"
|
|
118
|
+
dirty = "{base_version}+{distance}.{vcs}{rev}.dirty"
|
|
119
|
+
distance-dirty = "{base_version}+{distance}.{vcs}{rev}.dirty"
|
|
120
|
+
|
|
121
|
+
[project.scripts]
|
|
122
|
+
caf-brain = "caf.brain.ml.__main__:model_setup"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Always get the current version in "editable" installs
|
|
2
|
+
# `pip install -e .` / `python setup.py develop`
|
|
3
|
+
def _get_version() -> str:
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from versioningit import get_version
|
|
7
|
+
|
|
8
|
+
return get_version(
|
|
9
|
+
project_dir=Path(__file__).parents[3],
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# The following _get_version() call will get replaced by versioningit with a
|
|
14
|
+
# static version string during a build
|
|
15
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""
|
|
2
|
+
caf.brAIn is Transport for the North's bespoke machine learning and AI
|
|
3
|
+
library. It consists of a generalised end to end machine learning pipeline,
|
|
4
|
+
simplified machine learning functions and a machine vision model.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from caf.brain.ml._ml import (
|
|
8
|
+
tidy_data,
|
|
9
|
+
transform_data,
|
|
10
|
+
feature_selection,
|
|
11
|
+
algorithm_evaluation,
|
|
12
|
+
hparam_optim,
|
|
13
|
+
evaluate_data,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
from caf.brain.ml._functions._ml_inputs import Models
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Created on: 15/1/2025
|
|
3
|
+
Original author: Adil Zaheer
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
# Built-Ins
|
|
7
|
+
import argparse
|
|
8
|
+
import os
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
# Third Party
|
|
12
|
+
from caf.toolkit import LogHelper, ToolDetails
|
|
13
|
+
|
|
14
|
+
# Local Imports
|
|
15
|
+
from caf.brain.ml._functions._ml_inputs import PredictionModelInputs
|
|
16
|
+
from caf.brain.ml._functions.prediction_model_main import main
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _custom_load_yaml(config_path: Path) -> PredictionModelInputs:
|
|
20
|
+
"""
|
|
21
|
+
Loads the YAML configuration file for the caf.brAIn full machine learning
|
|
22
|
+
pipline and returns its contents as a dictionary.
|
|
23
|
+
|
|
24
|
+
If no path is provided, defaults to 'brain.yml' which you can put in the
|
|
25
|
+
current working directory.
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
config_path: Path to the YAML configuration file.
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
Parsed contents of the YAML file as a dictionary.
|
|
34
|
+
"""
|
|
35
|
+
if config_path is None:
|
|
36
|
+
config_path = Path.cwd() / "brain.yml"
|
|
37
|
+
if not config_path.exists():
|
|
38
|
+
raise FileNotFoundError(f"No config file found at {config_path}")
|
|
39
|
+
|
|
40
|
+
config_data = PredictionModelInputs.load_yaml(config_path)
|
|
41
|
+
|
|
42
|
+
return config_data
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def model_setup():
|
|
46
|
+
"""
|
|
47
|
+
Function to set up logging files, output folders and input data
|
|
48
|
+
for the caf.brAIn full machine learning pipline.
|
|
49
|
+
"""
|
|
50
|
+
parser = argparse.ArgumentParser(
|
|
51
|
+
description="Run caf.brAIn prediction model.",
|
|
52
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
53
|
+
)
|
|
54
|
+
parser.add_argument(
|
|
55
|
+
"--config",
|
|
56
|
+
type=Path,
|
|
57
|
+
default=Path("brain.yml"),
|
|
58
|
+
help=(
|
|
59
|
+
"Path to YAML config file. You should use docs/config.rst \n"
|
|
60
|
+
"as guidance and examples/brain.yml as a template.\n"
|
|
61
|
+
),
|
|
62
|
+
)
|
|
63
|
+
args = parser.parse_args()
|
|
64
|
+
params = _custom_load_yaml(args.config)
|
|
65
|
+
|
|
66
|
+
output_path = params.paths.output_path / "output"
|
|
67
|
+
if not output_path.is_dir():
|
|
68
|
+
os.makedirs(output_path)
|
|
69
|
+
|
|
70
|
+
path = output_path / "log_file.log"
|
|
71
|
+
details = ToolDetails("caf.brAIn Prediction Model", "1.0.0")
|
|
72
|
+
|
|
73
|
+
with LogHelper("caf.brain", details, console=True, log_file=path):
|
|
74
|
+
main(params, output_path)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
if __name__ == "__main__":
|
|
78
|
+
model_setup()
|