Skip to content

Commit db99d9c

Browse files
authored
Merge pull request #74 from wwu-mmll/develop
Develop
2 parents c3ae9a4 + 87715bf commit db99d9c

35 files changed

+2618
-411
lines changed

.github/workflows/python-test_and_deploy.yml

+4-42
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,6 @@ on:
1212
- cron: '0 10 5 * *'
1313

1414
jobs:
15-
pytest:
16-
name: Run PHOTONAI tests ${{matrix.python-version}}
17-
runs-on: ubuntu-22.04
18-
19-
services:
20-
mongodb:
21-
image: mongo:latest
22-
ports:
23-
- 27017:27017
24-
25-
strategy:
26-
matrix:
27-
python-version: ['3.8', '3.9']
28-
29-
steps:
30-
- uses: actions/checkout@v3
31-
- name: Set up Python ${{ matrix.python-version }}
32-
uses: actions/setup-python@v4
33-
with:
34-
python-version: ${{ matrix.python-version }}
35-
# - name: Install os dependencies
36-
# run: |
37-
# sudo apt-get update
38-
# sudo apt-get -y install gfortran swig
39-
- name: Install dependencies
40-
run: |
41-
pip install wheel flake8 pbr
42-
python setup.py egg_info
43-
pip install tensorflow pytest pytest-cov coveralls -r photonai.egg-info/requires.txt -r photonai/optimization/smac/requirements.txt -r photonai/optimization/nevergrad/requirements.txt
44-
- name: Test with pytest
45-
run: |
46-
PYTHONPATH=./ pytest ./test --cov=./photonai --full-trace
4715
coverage:
4816
name: Run PHOTONAI tests and publish test coverage
4917
runs-on: ubuntu-22.04
@@ -56,14 +24,10 @@ jobs:
5624

5725
steps:
5826
- uses: actions/checkout@v3
59-
- name: Set up Python ${{ matrix.python-version }}
27+
- name: Set up Python 3.9
6028
uses: actions/setup-python@v4
6129
with:
62-
python-version: ${{ matrix.python-version }}
63-
# - name: Install os dependencies
64-
# run: |
65-
# sudo apt-get update
66-
# sudo apt-get -y install gfortran swig
30+
python-version: 3.9
6731
- name: Install dependencies
6832
run: |
6933
pip install wheel flake8 pbr
@@ -74,23 +38,21 @@ jobs:
7438
PYTHONPATH=./ pytest ./test --cov=./photonai --full-trace
7539
- name: Coveralls
7640
run: coveralls
77-
if: ${{ matrix.python-version }} == 3.10
7841
env:
7942
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
8043
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8144
deploy:
8245
name: Build and publish to TestPyPI
8346
runs-on: ubuntu-22.04
84-
needs: pytest
8547
if: github.ref == 'refs/heads/main'
8648
steps:
8749
- uses: actions/checkout@v3
8850
with:
8951
fetch-depth: 0
90-
- name: Set up Python 3.10
52+
- name: Set up Python 3.9
9153
uses: actions/setup-python@v4
9254
with:
93-
python-version: 3.10.8
55+
python-version: 3.9
9456
- name: Install pypa/build
9557
run: pip install build pbr wheel
9658
- name: Build a binary wheel and a source tarball

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ site/
1010
**/cache
1111
**/dask-worker-space
1212

13+
**/classification
14+
**/regression
15+
1316
# Byte-compiled / optimized / DLL files
1417
__pycache__/
1518
*.py[cod]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Documentation for `ClassificationPipe`
2+
::: photonai.base.ClassificationPipe
3+
selection:
4+
members:
5+
- __init__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Documentation for `ClassifierSwitch`
2+
::: photonai.base.ClassifierSwitch
3+
selection:
4+
members:
5+
- __init__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Documentation for `RegressionPipe`
2+
::: photonai.base.RegressionPipe
3+
selection:
4+
members:
5+
- __init__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Documentation for `RegressorSwitch`
2+
::: photonai.base.RegressorSwitch
3+
selection:
4+
members:
5+
- __init__

documentation/docs/getting_started/classification.md

+9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
</p>
77
</div>
88

9+
<h3>Classification with default pipeline</h3>
10+
911
``` python
1012
{% include "examples/basic/classification.py" %}
1113

14+
```
15+
16+
<h3>Classification with custom pipeline</h3>
17+
18+
``` python
19+
{% include "examples/basic/classification_custom.py" %}
20+
1221
```

documentation/docs/getting_started/regression.md

+8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
</p>
77
</div>
88

9+
<h3>Regression with default pipeline</h3>
910
``` python
1011
{% include "examples/basic/regression.py" %}
1112

13+
```
14+
15+
<h3>Regression with custom pipeline</h3>
16+
17+
``` python
18+
{% include "examples/basic/regression_custom.py" %}
19+
1220
```

documentation/docs/index.md

+36-12
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,55 @@
11
<h1>Getting Started</h1>
2-
<h2>1. Installation</h2>
2+
<h2>Installation</h2>
33
<p class="small-p">You only need two things: Python 3 and your favourite Python IDE to get started. Then simply install via pip.</p>
44

55
```python
66
pip install photonai
77
```
88

9-
<h2>2. Setup New Analysis</h2>
10-
Start by importing some utilities and creating a new Hyperpipe instance, naming the analysis and specifying where to save all outputs.
9+
<h2> Setup Default Analysis </h2>
10+
<h3>Regression with default pipeline</h3>
1111

1212
```python
13-
from sklearn.model_selection import ShuffleSplit, KFold
13+
from sklearn.datasets import load_diabetes
14+
from photonai import RegressionPipe
15+
16+
my_pipe = RegressionPipe('diabetes')
17+
X, y = load_diabetes(return_X_y=True)
18+
my_pipe.fit(X, y)
19+
```
20+
21+
<h3>Classification with modified default pipeline</h2>
22+
``` python
23+
from photonai import ClassificationPipe
1424
from sklearn.datasets import load_breast_cancer
15-
from photonai.base import Hyperpipe, PipelineElement, Switch
16-
from photonai.optimization import IntegerRange, FloatRange
25+
from sklearn.model_selection import ShuffleSplit
1726

18-
pipe = Hyperpipe('basic_pipe', project_folder='./')
27+
X, y = load_breast_cancer(return_X_y=True)
28+
my_pipe = ClassificationPipe(name='breast_cancer_analysis',
29+
inner_cv=ShuffleSplit(n_splits=2),
30+
scaling=True,
31+
imputation=False,
32+
imputation_nan_value=None,
33+
feature_selection=False,
34+
dim_reduction=True,
35+
n_pca_components=10)
36+
my_pipe.fit(X, y)
1937
```
2038

2139

22-
<h2>3. Define training, optimization and testing parameters</h2>
23-
Select parameters to customize the training, hyperparameter optimization and testing procedure.
40+
<h2>Or Setup New Custom Analysis</h2>
2441

42+
Start by importing some utilities. and creating a new Hyperpipe instance, naming the analysis and specifying where to save all outputs.
43+
Select parameters to customize the training, hyperparameter optimization and testing procedure.
2544
Particularly, you can choose the hyperparameter optimization strategy, set parameters, choose performance metrics
2645
and choose the performance metric to minimize or maximize, respectively.
2746

28-
```python
47+
```python
48+
from sklearn.model_selection import ShuffleSplit, KFold
49+
from sklearn.datasets import load_breast_cancer
50+
from photonai.base import Hyperpipe, PipelineElement, Switch
51+
from photonai.optimization import IntegerRange, FloatRange
52+
2953
pipe = Hyperpipe('basic_pipe', project_folder='./',
3054

3155
# choose hyperparameter optimization strategy
@@ -43,7 +67,7 @@ pipe = Hyperpipe('basic_pipe', project_folder='./',
4367
inner_cv=KFold(n_splits=10))
4468
```
4569

46-
<h2>4. Build custom pipeline</h2>
70+
<h3>Add pipeline elements to your liking.</h3>
4771
Select and arrange normalization, dimensionality reduction, feature selection, data augmentation,
4872
over- or undersampling algorithms in simple or parallel data streams. You can integrate
4973
custom algorithms or choose from our wide range of pre-registered algorithms from established toolboxes.
@@ -69,7 +93,7 @@ or_element += PipelineElement('SVC',
6993
pipe += or_element
7094
```
7195

72-
<h2>5. Load Data and Train</h2>
96+
<h3>Finally, load data and start training!</h3>
7397
Load your data and start the (nested-) cross-validated hyperparameter optimization, training and evaluation procedure.
7498
You will see an extensive output to monitor the hyperparameter optimization progress, see the results and track the
7599
best performances so far.

examples/advanced/feature_importance.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
my_pipe += PipelineElement('Ridge', alpha=1e-2)
1919
my_pipe.fit(X_train, y_train)
2020

21+
# get model-agnostic feature importances
2122
r = my_pipe.get_permutation_feature_importances(n_repeats=50, random_state=0)
2223

2324
for i in r["mean"].argsort()[::-1]:
@@ -26,7 +27,9 @@
2627
f"{r['mean'][i]:.3f}"
2728
f" +/- {r['std'][i]:.3f}")
2829

30+
# if your have a model that returns feature importance scores you can compare those to permutation feature importances
31+
feature_importances_df = my_pipe.get_model_and_permutation_importances(n_repeats=50, random_state=0)
2932

3033
# get permutation importances posthoc
3134
# reloaded_hyperpipe = Hyperpipe.reload_hyperpipe("full_path/to/results_folder/", X_train, y_train)
32-
# post_hoc_perm_importances = Hyperpipe.get_permutation_feature_importances(n_repeats=5, random_state=0)
35+
# post_hoc_perm_importances = reloaded_hyperpipe.get_permutation_feature_importances(n_repeats=5, random_state=0)

examples/basic/classification.py

+10-23
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
1+
from photonai import ClassificationPipe
12
from sklearn.datasets import load_breast_cancer
2-
from sklearn.model_selection import KFold
3+
from sklearn.model_selection import ShuffleSplit
34

4-
from photonai import Hyperpipe, PipelineElement, FloatRange, Categorical, IntegerRange
5-
6-
my_pipe = Hyperpipe('basic_svm_pipe',
7-
inner_cv=KFold(n_splits=5),
8-
outer_cv=KFold(n_splits=3),
9-
optimizer='sk_opt',
10-
optimizer_params={'n_configurations': 15},
11-
metrics=['accuracy', 'precision', 'recall', 'balanced_accuracy'],
12-
best_config_metric='accuracy',
13-
project_folder='./tmp')
14-
15-
my_pipe.add(PipelineElement('StandardScaler'))
16-
17-
my_pipe += PipelineElement('PCA',
18-
hyperparameters={'n_components': IntegerRange(10, 30)},
19-
n_components=10,
20-
test_disabled=True)
21-
22-
my_pipe += PipelineElement('SVC',
23-
hyperparameters={'kernel': Categorical(['rbf', 'linear']),
24-
'C': FloatRange(1, 6)},
25-
gamma='scale')
265

276
X, y = load_breast_cancer(return_X_y=True)
7+
my_pipe = ClassificationPipe(name='breast_cancer_analysis',
8+
inner_cv=ShuffleSplit(n_splits=2),
9+
scaling=True,
10+
imputation=False,
11+
imputation_nan_value=None,
12+
feature_selection=False,
13+
dim_reduction=True,
14+
n_pca_components=10)
2815
my_pipe.fit(X, y)
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from sklearn.model_selection import KFold
2+
from sklearn.datasets import load_breast_cancer
3+
from photonai import Hyperpipe, PipelineElement, FloatRange, Categorical, IntegerRange
4+
5+
my_pipe = Hyperpipe('basic_svm_pipe',
6+
inner_cv=KFold(n_splits=5),
7+
outer_cv=KFold(n_splits=3),
8+
optimizer='sk_opt',
9+
optimizer_params={'n_configurations': 15},
10+
metrics=['accuracy', 'precision', 'recall', 'balanced_accuracy'],
11+
best_config_metric='accuracy',
12+
project_folder='./tmp')
13+
14+
my_pipe.add(PipelineElement('StandardScaler'))
15+
16+
my_pipe += PipelineElement('PCA',
17+
hyperparameters={'n_components': IntegerRange(10, 30)},
18+
n_components=10,
19+
test_disabled=True)
20+
21+
my_pipe += PipelineElement('SVC',
22+
hyperparameters={'kernel': Categorical(['rbf', 'linear']),
23+
'C': FloatRange(1, 6)},
24+
gamma='scale')
25+
26+
27+
X, y = load_breast_cancer(return_X_y=True)
28+
my_pipe.fit(X, y)

examples/basic/no_hyperparameters.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from sklearn.model_selection import KFold
2+
from sklearn.datasets import load_breast_cancer
3+
from photonai import Hyperpipe, PipelineElement
4+
5+
my_pipe = Hyperpipe('basic_svm_pipe',
6+
inner_cv=KFold(n_splits=5),
7+
outer_cv=KFold(n_splits=3),
8+
metrics=['balanced_accuracy',
9+
'precision',
10+
'recall',
11+
'accuracy'],
12+
best_config_metric='balanced_accuracy',
13+
project_folder='./tmp')
14+
15+
my_pipe += PipelineElement('StandardScaler')
16+
17+
my_pipe += PipelineElement('PCA',
18+
n_components=10,
19+
test_disabled=True)
20+
21+
my_pipe += PipelineElement('LogisticRegression')
22+
23+
24+
X, y = load_breast_cancer(return_X_y=True)
25+
my_pipe.fit(X, y)
26+

examples/basic/regression.py

+11-25
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
from sklearn.datasets import load_diabetes
2-
from sklearn.model_selection import KFold
3-
4-
from photonai import Hyperpipe, PipelineElement, IntegerRange, FloatRange
5-
6-
7-
my_pipe = Hyperpipe('basic_regression_pipe',
8-
optimizer='random_search',
9-
optimizer_params={'n_configurations': 25},
10-
metrics=['mean_squared_error', 'mean_absolute_error', 'explained_variance'],
11-
best_config_metric='mean_squared_error',
12-
outer_cv=KFold(n_splits=3, shuffle=True),
13-
inner_cv=KFold(n_splits=3, shuffle=True),
14-
verbosity=1,
15-
project_folder='./tmp/')
16-
17-
my_pipe += PipelineElement('SimpleImputer')
18-
my_pipe += PipelineElement('StandardScaler')
19-
20-
my_pipe += PipelineElement('LassoFeatureSelection',
21-
hyperparameters={'percentile': [0.1, 0.2, 0.3],
22-
'alpha': FloatRange(0.5, 5)})
23-
24-
my_pipe += PipelineElement('RandomForestRegressor',
25-
hyperparameters={'n_estimators': IntegerRange(10, 50)})
26-
2+
from photonai import RegressionPipe
3+
4+
my_pipe = RegressionPipe('diabetes',
5+
add_default_pipeline_elements=True,
6+
scaling=True,
7+
imputation=False,
8+
imputation_nan_value=None,
9+
feature_selection=False,
10+
dim_reduction=True,
11+
n_pca_components=10,
12+
add_estimator=True)
2713
# load data and train
2814
X, y = load_diabetes(return_X_y=True)
2915
my_pipe.fit(X, y)

0 commit comments

Comments
 (0)