data-science-concepts 2026.0.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.
- data_science_concepts-2026.0.0/.gitignore +220 -0
- data_science_concepts-2026.0.0/LICENSE +21 -0
- data_science_concepts-2026.0.0/PKG-INFO +79 -0
- data_science_concepts-2026.0.0/README.md +64 -0
- data_science_concepts-2026.0.0/pyproject.toml +23 -0
- data_science_concepts-2026.0.0/src/data_science_concepts/__init__.py +8 -0
- data_science_concepts-2026.0.0/src/data_science_concepts/decision_boundary.py +31 -0
- data_science_concepts-2026.0.0/src/data_science_concepts/pca_example.py +148 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
*.lcov
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# uv
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
# poetry.lock
|
|
110
|
+
# poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
# pdm.lock
|
|
117
|
+
# pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
# pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi/*
|
|
127
|
+
!.pixi/config.toml
|
|
128
|
+
|
|
129
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
130
|
+
__pypackages__/
|
|
131
|
+
|
|
132
|
+
# Celery stuff
|
|
133
|
+
celerybeat-schedule*
|
|
134
|
+
celerybeat.pid
|
|
135
|
+
|
|
136
|
+
# Redis
|
|
137
|
+
*.rdb
|
|
138
|
+
*.aof
|
|
139
|
+
*.pid
|
|
140
|
+
|
|
141
|
+
# RabbitMQ
|
|
142
|
+
mnesia/
|
|
143
|
+
rabbitmq/
|
|
144
|
+
rabbitmq-data/
|
|
145
|
+
|
|
146
|
+
# ActiveMQ
|
|
147
|
+
activemq-data/
|
|
148
|
+
|
|
149
|
+
# SageMath parsed files
|
|
150
|
+
*.sage.py
|
|
151
|
+
|
|
152
|
+
# Environments
|
|
153
|
+
.env
|
|
154
|
+
.envrc
|
|
155
|
+
.venv
|
|
156
|
+
env/
|
|
157
|
+
venv/
|
|
158
|
+
ENV/
|
|
159
|
+
env.bak/
|
|
160
|
+
venv.bak/
|
|
161
|
+
|
|
162
|
+
# Spyder project settings
|
|
163
|
+
.spyderproject
|
|
164
|
+
.spyproject
|
|
165
|
+
|
|
166
|
+
# Rope project settings
|
|
167
|
+
.ropeproject
|
|
168
|
+
|
|
169
|
+
# mkdocs/Zensical documentation
|
|
170
|
+
/site
|
|
171
|
+
|
|
172
|
+
# mypy
|
|
173
|
+
.mypy_cache/
|
|
174
|
+
.dmypy.json
|
|
175
|
+
dmypy.json
|
|
176
|
+
|
|
177
|
+
# Pyre type checker
|
|
178
|
+
.pyre/
|
|
179
|
+
|
|
180
|
+
# pytype static type analyzer
|
|
181
|
+
.pytype/
|
|
182
|
+
|
|
183
|
+
# Cython debug symbols
|
|
184
|
+
cython_debug/
|
|
185
|
+
|
|
186
|
+
# PyCharm
|
|
187
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
188
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
189
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
190
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
191
|
+
# .idea/
|
|
192
|
+
|
|
193
|
+
# Abstra
|
|
194
|
+
# Abstra is an AI-powered process automation framework.
|
|
195
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
196
|
+
# Learn more at https://abstra.io/docs
|
|
197
|
+
.abstra/
|
|
198
|
+
|
|
199
|
+
# Visual Studio Code
|
|
200
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
|
|
201
|
+
# can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
202
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer, you
|
|
203
|
+
# could uncomment the following to ignore the entire vscode folder
|
|
204
|
+
# .vscode/
|
|
205
|
+
# Temporary file for partial code execution
|
|
206
|
+
tempCodeRunnerFile.py
|
|
207
|
+
|
|
208
|
+
# Ruff stuff:
|
|
209
|
+
.ruff_cache/
|
|
210
|
+
|
|
211
|
+
# PyPI configuration file
|
|
212
|
+
.pypirc
|
|
213
|
+
|
|
214
|
+
# Marimo
|
|
215
|
+
marimo/_static/
|
|
216
|
+
marimo/_lsp/
|
|
217
|
+
__marimo__/
|
|
218
|
+
|
|
219
|
+
# Streamlit
|
|
220
|
+
.streamlit/secrets.toml
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 WUR Bioinformatics
|
|
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.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: data-science-concepts
|
|
3
|
+
Version: 2026.0.0
|
|
4
|
+
Summary: Helper functions for the Concepts in Data Science practicals (Wageningen University)
|
|
5
|
+
Project-URL: Repository, https://github.com/wur-bioinformatics/data-science-concepts
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Requires-Dist: matplotlib
|
|
10
|
+
Requires-Dist: numpy
|
|
11
|
+
Requires-Dist: plotly
|
|
12
|
+
Requires-Dist: scikit-learn
|
|
13
|
+
Requires-Dist: seaborn
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# _INF34306_ Concepts in Data Science
|
|
17
|
+
|
|
18
|
+
Notebooks and datasets for Concepts in Data Science practicals.
|
|
19
|
+
|
|
20
|
+
### Using the notebooks
|
|
21
|
+
|
|
22
|
+
The notebooks are meant to be used in [Google Colab](https://colab.research.google.com). Open a notebook with one of the links below, then use *File → Save a copy in Drive* to keep your changes.
|
|
23
|
+
|
|
24
|
+
| Block | Tutorial | Project |
|
|
25
|
+
|---|---|---|
|
|
26
|
+
| 1 - Introduction | [](https://colab.research.google.com/github/wur-bioinformatics/data-science-concepts/blob/main/notebooks/block1_introduction/tutorial_1.ipynb) | [](https://colab.research.google.com/github/wur-bioinformatics/data-science-concepts/blob/main/notebooks/block1_introduction/project_1.ipynb) |
|
|
27
|
+
| 2 - Python libraries, Visualization, and the Grammar of Graphics | [](https://colab.research.google.com/github/wur-bioinformatics/data-science-concepts/blob/main/notebooks/block2_visualisation/tutorial_2.ipynb) | [](https://colab.research.google.com/github/wur-bioinformatics/data-science-concepts/blob/main/notebooks/block2_visualisation/project_2.ipynb) |
|
|
28
|
+
| 3 - Data exploration I | [](https://colab.research.google.com/github/wur-bioinformatics/data-science-concepts/blob/main/notebooks/block3_exploration_1/tutorial_3.ipynb) | [](https://colab.research.google.com/github/wur-bioinformatics/data-science-concepts/blob/main/notebooks/block3_exploration_1/project_3.ipynb) |
|
|
29
|
+
| 4 - Data exploration II | [](https://colab.research.google.com/github/wur-bioinformatics/data-science-concepts/blob/main/notebooks/block4_exploration_2/tutorial_4.ipynb) | [](https://colab.research.google.com/github/wur-bioinformatics/data-science-concepts/blob/main/notebooks/block4_exploration_2/project_4.ipynb) |
|
|
30
|
+
|
|
31
|
+
In blocks 1 and 2, students download the datasets from Kaggle themselves and upload them to Colab (`files.upload()`). From block 3 onwards, the notebooks read datasets directly from this repository on GitHub (`DATA_URL` in the notebooks). Note that this points to the `main` branch: files that are not on `main` yet will not load.
|
|
32
|
+
|
|
33
|
+
### Repository structure
|
|
34
|
+
|
|
35
|
+
Notebooks with exercises and examples are in the `notebooks` folder, with one subfolder per block. Datasets (when not available through APIs) are in the `datasets` folder, with informative filenames.
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
|-- README.md
|
|
39
|
+
|-- TODO.md
|
|
40
|
+
|-- datasets
|
|
41
|
+
| |-- UniComplaints.csv
|
|
42
|
+
| |-- anscombe_quartet.csv
|
|
43
|
+
| |-- automobile.csv
|
|
44
|
+
| |-- breast-cancer.csv
|
|
45
|
+
| |-- iris.csv
|
|
46
|
+
| |-- titanic.csv
|
|
47
|
+
| |-- top_1000_popular_movies_tmdb.csv
|
|
48
|
+
| `-- ... (not used by the current notebooks, see TODO.md)
|
|
49
|
+
|-- notebooks
|
|
50
|
+
| |-- block1_introduction
|
|
51
|
+
| | |-- tutorial_1.ipynb
|
|
52
|
+
| | `-- project_1.ipynb
|
|
53
|
+
| |-- block2_visualisation
|
|
54
|
+
| | |-- tutorial_2.ipynb
|
|
55
|
+
| | `-- project_2.ipynb
|
|
56
|
+
| |-- block3_exploration_1
|
|
57
|
+
| | |-- tutorial_3.ipynb
|
|
58
|
+
| | `-- project_3.ipynb
|
|
59
|
+
| `-- block4_exploration_2
|
|
60
|
+
| |-- tutorial_4.ipynb
|
|
61
|
+
| `-- project_4.ipynb
|
|
62
|
+
|-- pyproject.toml
|
|
63
|
+
|-- requirements.txt
|
|
64
|
+
`-- src
|
|
65
|
+
`-- data_science_concepts (course package, see below)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Images used in the notebooks are stored next to the notebooks and linked by their GitHub URL, because Colab does not resolve relative image paths.
|
|
69
|
+
|
|
70
|
+
### Course package
|
|
71
|
+
|
|
72
|
+
Helper functions used in the notebooks (e.g. `plot_decision_boundary`) are in the `data-science-concepts` package in `src/data_science_concepts`. The notebooks install it with
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
%pip install -q "data-science-concepts==2026.*"
|
|
76
|
+
import data_science_concepts as dsc
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
To release a new version, create a GitHub release with a tag of the form `vYEAR.MINOR.PATCH` (e.g. `v2026.0.1`). The `Package` workflow (`.github/workflows/package.yml`) builds the package and publishes it to [PyPI](https://pypi.org/project/data-science-concepts/); the version number is taken from the tag. Notebooks pin the course year, so a release for the next year (`v2027.0.0`) does not affect notebooks of the current year.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# _INF34306_ Concepts in Data Science
|
|
2
|
+
|
|
3
|
+
Notebooks and datasets for Concepts in Data Science practicals.
|
|
4
|
+
|
|
5
|
+
### Using the notebooks
|
|
6
|
+
|
|
7
|
+
The notebooks are meant to be used in [Google Colab](https://colab.research.google.com). Open a notebook with one of the links below, then use *File → Save a copy in Drive* to keep your changes.
|
|
8
|
+
|
|
9
|
+
| Block | Tutorial | Project |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| 1 - Introduction | [](https://colab.research.google.com/github/wur-bioinformatics/data-science-concepts/blob/main/notebooks/block1_introduction/tutorial_1.ipynb) | [](https://colab.research.google.com/github/wur-bioinformatics/data-science-concepts/blob/main/notebooks/block1_introduction/project_1.ipynb) |
|
|
12
|
+
| 2 - Python libraries, Visualization, and the Grammar of Graphics | [](https://colab.research.google.com/github/wur-bioinformatics/data-science-concepts/blob/main/notebooks/block2_visualisation/tutorial_2.ipynb) | [](https://colab.research.google.com/github/wur-bioinformatics/data-science-concepts/blob/main/notebooks/block2_visualisation/project_2.ipynb) |
|
|
13
|
+
| 3 - Data exploration I | [](https://colab.research.google.com/github/wur-bioinformatics/data-science-concepts/blob/main/notebooks/block3_exploration_1/tutorial_3.ipynb) | [](https://colab.research.google.com/github/wur-bioinformatics/data-science-concepts/blob/main/notebooks/block3_exploration_1/project_3.ipynb) |
|
|
14
|
+
| 4 - Data exploration II | [](https://colab.research.google.com/github/wur-bioinformatics/data-science-concepts/blob/main/notebooks/block4_exploration_2/tutorial_4.ipynb) | [](https://colab.research.google.com/github/wur-bioinformatics/data-science-concepts/blob/main/notebooks/block4_exploration_2/project_4.ipynb) |
|
|
15
|
+
|
|
16
|
+
In blocks 1 and 2, students download the datasets from Kaggle themselves and upload them to Colab (`files.upload()`). From block 3 onwards, the notebooks read datasets directly from this repository on GitHub (`DATA_URL` in the notebooks). Note that this points to the `main` branch: files that are not on `main` yet will not load.
|
|
17
|
+
|
|
18
|
+
### Repository structure
|
|
19
|
+
|
|
20
|
+
Notebooks with exercises and examples are in the `notebooks` folder, with one subfolder per block. Datasets (when not available through APIs) are in the `datasets` folder, with informative filenames.
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
|-- README.md
|
|
24
|
+
|-- TODO.md
|
|
25
|
+
|-- datasets
|
|
26
|
+
| |-- UniComplaints.csv
|
|
27
|
+
| |-- anscombe_quartet.csv
|
|
28
|
+
| |-- automobile.csv
|
|
29
|
+
| |-- breast-cancer.csv
|
|
30
|
+
| |-- iris.csv
|
|
31
|
+
| |-- titanic.csv
|
|
32
|
+
| |-- top_1000_popular_movies_tmdb.csv
|
|
33
|
+
| `-- ... (not used by the current notebooks, see TODO.md)
|
|
34
|
+
|-- notebooks
|
|
35
|
+
| |-- block1_introduction
|
|
36
|
+
| | |-- tutorial_1.ipynb
|
|
37
|
+
| | `-- project_1.ipynb
|
|
38
|
+
| |-- block2_visualisation
|
|
39
|
+
| | |-- tutorial_2.ipynb
|
|
40
|
+
| | `-- project_2.ipynb
|
|
41
|
+
| |-- block3_exploration_1
|
|
42
|
+
| | |-- tutorial_3.ipynb
|
|
43
|
+
| | `-- project_3.ipynb
|
|
44
|
+
| `-- block4_exploration_2
|
|
45
|
+
| |-- tutorial_4.ipynb
|
|
46
|
+
| `-- project_4.ipynb
|
|
47
|
+
|-- pyproject.toml
|
|
48
|
+
|-- requirements.txt
|
|
49
|
+
`-- src
|
|
50
|
+
`-- data_science_concepts (course package, see below)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Images used in the notebooks are stored next to the notebooks and linked by their GitHub URL, because Colab does not resolve relative image paths.
|
|
54
|
+
|
|
55
|
+
### Course package
|
|
56
|
+
|
|
57
|
+
Helper functions used in the notebooks (e.g. `plot_decision_boundary`) are in the `data-science-concepts` package in `src/data_science_concepts`. The notebooks install it with
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
%pip install -q "data-science-concepts==2026.*"
|
|
61
|
+
import data_science_concepts as dsc
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
To release a new version, create a GitHub release with a tag of the form `vYEAR.MINOR.PATCH` (e.g. `v2026.0.1`). The `Package` workflow (`.github/workflows/package.yml`) builds the package and publishes it to [PyPI](https://pypi.org/project/data-science-concepts/); the version number is taken from the tag. Notebooks pin the course year, so a release for the next year (`v2027.0.0`) does not affect notebooks of the current year.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "data-science-concepts"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Helper functions for the Concepts in Data Science practicals (Wageningen University)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
# No version bounds: installing the package in Colab should not change the preinstalled packages
|
|
13
|
+
dependencies = ["numpy", "matplotlib", "seaborn", "scikit-learn", "plotly"]
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Repository = "https://github.com/wur-bioinformatics/data-science-concepts"
|
|
17
|
+
|
|
18
|
+
# Version is taken from the git tag of the release (e.g. v2026.0.0)
|
|
19
|
+
[tool.hatch.version]
|
|
20
|
+
source = "vcs"
|
|
21
|
+
|
|
22
|
+
[tool.hatch.build.targets.sdist]
|
|
23
|
+
include = ["src/data_science_concepts"]
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""Helper functions for the Concepts in Data Science practicals (Wageningen University)."""
|
|
2
|
+
from importlib.metadata import version
|
|
3
|
+
|
|
4
|
+
from .decision_boundary import plot_decision_boundary
|
|
5
|
+
from .pca_example import make_pca_example_figure
|
|
6
|
+
|
|
7
|
+
__version__ = version("data-science-concepts")
|
|
8
|
+
__all__ = ["make_pca_example_figure", "plot_decision_boundary"]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import matplotlib.pyplot as plt
|
|
2
|
+
import numpy as np
|
|
3
|
+
import seaborn as sns
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def plot_decision_boundary(X, y, feature_names, clf, ax=None, proba=True):
|
|
7
|
+
"""
|
|
8
|
+
Utility function for plotting a binary classication boundary in a 2D dataset
|
|
9
|
+
This function does not work for any other classification problem (e.g. multiclass) or feature dimensionality
|
|
10
|
+
"""
|
|
11
|
+
if ax is None:
|
|
12
|
+
fig, ax = plt.subplots(figsize=(10,10))
|
|
13
|
+
# Plot the decision boundary by assigning a color to each point in the mesh [x_min, x_max]x[y_min, y_max].
|
|
14
|
+
x_min, x_max = X[feature_names[0]].min() - 1, X[feature_names[0]].max() + 1
|
|
15
|
+
y_min, y_max = X[feature_names[1]].min() - 1, X[feature_names[1]].max() + 1
|
|
16
|
+
step = 0.05
|
|
17
|
+
xx, yy = np.meshgrid(np.arange(x_min, x_max, step),
|
|
18
|
+
np.arange(y_min, y_max, step))
|
|
19
|
+
|
|
20
|
+
# Predict on all data points
|
|
21
|
+
if proba:
|
|
22
|
+
Z = clf.predict_proba(np.c_[xx.ravel(), yy.ravel()])[:, 1]
|
|
23
|
+
else:
|
|
24
|
+
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
|
|
25
|
+
|
|
26
|
+
# Put the result into a color plot
|
|
27
|
+
Z = Z.reshape(xx.shape)
|
|
28
|
+
ax.contourf(xx, yy, Z, alpha=0.6, cmap="RdYlBu_r")
|
|
29
|
+
|
|
30
|
+
# Plot data points
|
|
31
|
+
sns.scatterplot(data=X, x=feature_names[0], y=feature_names[1], hue=y, s=30, palette="RdYlBu_r", ax=ax, edgecolor='black')
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import plotly.graph_objects as go
|
|
3
|
+
from plotly.subplots import make_subplots
|
|
4
|
+
from sklearn.decomposition import PCA
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def make_pca_example_figure():
|
|
8
|
+
"""Interactive figure of PCA on a simulated 3D dataset: the data space with the
|
|
9
|
+
first two principal components (left) and the projection onto those components (right)."""
|
|
10
|
+
np.random.seed(0)
|
|
11
|
+
X1 = np.random.normal(0, 15, 50)
|
|
12
|
+
X2 = X1 + np.random.normal(0, 10, 50)
|
|
13
|
+
X3 = X1 + np.random.normal(0, 10, 50)
|
|
14
|
+
|
|
15
|
+
dat = np.array([X1, X2, X3]).T
|
|
16
|
+
mu = dat.mean(axis=0)
|
|
17
|
+
|
|
18
|
+
n_comp = 2
|
|
19
|
+
|
|
20
|
+
pca = PCA(n_components=2).fit(dat)
|
|
21
|
+
latent_points = pca.transform(dat).T
|
|
22
|
+
|
|
23
|
+
pc1_latent = np.array([
|
|
24
|
+
[0, -30],
|
|
25
|
+
[0, 30]
|
|
26
|
+
])
|
|
27
|
+
pc1 = np.dot(pc1_latent, pca.components_[:n_comp,:]) + mu[0]
|
|
28
|
+
|
|
29
|
+
pc2_latent = np.array([
|
|
30
|
+
[-80, 0],
|
|
31
|
+
[80, 0]
|
|
32
|
+
])
|
|
33
|
+
pc2 = np.dot(pc2_latent, pca.components_[:n_comp,:]) + mu[1]
|
|
34
|
+
|
|
35
|
+
fig = make_subplots(
|
|
36
|
+
specs=[[
|
|
37
|
+
dict(type='scene'),
|
|
38
|
+
dict(type='xy')
|
|
39
|
+
]],
|
|
40
|
+
subplot_titles=['Data space (3D)', 'Principal Component space (2D)'],
|
|
41
|
+
rows=1,
|
|
42
|
+
cols=2)
|
|
43
|
+
|
|
44
|
+
# Data space (3D)
|
|
45
|
+
fig.add_trace(
|
|
46
|
+
go.Scatter3d(
|
|
47
|
+
x=X1,
|
|
48
|
+
y=X2,
|
|
49
|
+
z=X3,
|
|
50
|
+
mode='markers',
|
|
51
|
+
marker=dict(
|
|
52
|
+
size=4,
|
|
53
|
+
color='darkblue',
|
|
54
|
+
opacity=.7
|
|
55
|
+
),
|
|
56
|
+
showlegend=False
|
|
57
|
+
),
|
|
58
|
+
row=1,col=1
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
fig.add_trace(
|
|
62
|
+
go.Scatter3d(
|
|
63
|
+
x=pc1.T[0],
|
|
64
|
+
y=pc1.T[1],
|
|
65
|
+
z=pc1.T[2],
|
|
66
|
+
mode='lines',
|
|
67
|
+
marker=dict(
|
|
68
|
+
color='orange'
|
|
69
|
+
),
|
|
70
|
+
showlegend=False
|
|
71
|
+
),
|
|
72
|
+
row=1,col=1
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
fig.add_trace(
|
|
76
|
+
go.Scatter3d(
|
|
77
|
+
x=pc2.T[0],
|
|
78
|
+
y=pc2.T[1],
|
|
79
|
+
z=pc2.T[2],
|
|
80
|
+
mode='lines',
|
|
81
|
+
marker=dict(
|
|
82
|
+
color='darkgreen'
|
|
83
|
+
),
|
|
84
|
+
showlegend=False
|
|
85
|
+
),
|
|
86
|
+
row=1,col=1
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# Latent space (2D)
|
|
90
|
+
fig.add_trace(
|
|
91
|
+
go.Scatter(
|
|
92
|
+
x=latent_points[0],
|
|
93
|
+
y=latent_points[1],
|
|
94
|
+
mode='markers',
|
|
95
|
+
marker=dict(
|
|
96
|
+
size=8,
|
|
97
|
+
color='darkblue',
|
|
98
|
+
opacity=.7
|
|
99
|
+
),
|
|
100
|
+
showlegend=False
|
|
101
|
+
),
|
|
102
|
+
row=1,
|
|
103
|
+
col=2
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
fig.add_trace(
|
|
107
|
+
go.Scatter(
|
|
108
|
+
x=pc1_latent.T[0],
|
|
109
|
+
y=pc1_latent.T[1],
|
|
110
|
+
mode='lines',
|
|
111
|
+
marker=dict(
|
|
112
|
+
color='orange'
|
|
113
|
+
),
|
|
114
|
+
showlegend=False
|
|
115
|
+
),
|
|
116
|
+
row=1,col=2
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
fig.add_trace(
|
|
120
|
+
go.Scatter(
|
|
121
|
+
x=pc2_latent.T[0],
|
|
122
|
+
y=pc2_latent.T[1],
|
|
123
|
+
mode='lines',
|
|
124
|
+
marker=dict(
|
|
125
|
+
color='darkgreen'
|
|
126
|
+
),
|
|
127
|
+
showlegend=False
|
|
128
|
+
),
|
|
129
|
+
row=1,col=2
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
fig.update_xaxes(
|
|
133
|
+
title_text=f'PC1 ({pca.explained_variance_ratio_[0] * 100:.4}% variance)',
|
|
134
|
+
range=(-100, 100),
|
|
135
|
+
row=1,
|
|
136
|
+
col=2
|
|
137
|
+
)
|
|
138
|
+
fig.update_yaxes(
|
|
139
|
+
title_text=f'PC2 ({pca.explained_variance_ratio_[1] * 100:.3}% variance)',
|
|
140
|
+
range=(-50, 50),
|
|
141
|
+
row=1,
|
|
142
|
+
col=2
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
fig.update_layout(margin=dict(l=0, r=40, b=100, t=100))
|
|
147
|
+
#fig.show()
|
|
148
|
+
return fig
|