Skip to content

Commit 51c5705

Browse files
committed
Update docs
1 parent 93d3d4b commit 51c5705

File tree

2 files changed

+70
-18
lines changed

2 files changed

+70
-18
lines changed

docs/getting-started.md

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,19 @@ X_2 = X[:, 3:6]
4747

4848
# Create a project
4949
project = PhotonaiProject(project_folder="example_project")
50+
```
5051

52+
You can now add multiple analyses that e.g. use different sets of features. You need to pass the data (X, y) as if
53+
you were to call .fit() on a hyperpipe. The data arrays are then saved to disk which makes it easy to access them
54+
when running an analysis or performing the permutation test. This also makes it easy to simply rsync everything
55+
to an HPC cluster and run analyses there. Instead of creating a hyperpipe during runtime, you pass the location
56+
of a Python script that contains a function (hyperpipe constructor) that creates the PHOTONAI Hyperpipe you want
57+
to use in this project.
58+
```python
5159
# ---------------------------------------------------------------------
5260
# 1) Register analyses
5361
# ---------------------------------------------------------------------
54-
for name, current_X in [
55-
("all_features", X),
56-
("first_feature_set", X_1),
57-
("second_feature_set", X_2),
58-
]:
62+
for name, current_X in [("all_features", X), ("first_feature_set", X_1), ("second_feature_set", X_2)]:
5963
project.add(
6064
name=name,
6165
X=current_X,
@@ -65,51 +69,86 @@ for name, current_X in [
6569
)
6670

6771
project.list_analyses()
72+
```
73+
Your PHOTONAI Hyperpipe constructor might look something like this.
74+
```python
75+
from photonai import Hyperpipe, PipelineElement
76+
from sklearn.model_selection import KFold
77+
78+
79+
def create_hyperpipe():
80+
my_pipe = Hyperpipe('',
81+
optimizer='grid_search',
82+
metrics=['accuracy', 'precision', 'recall'],
83+
best_config_metric='accuracy',
84+
outer_cv=KFold(n_splits=10),
85+
inner_cv=KFold(n_splits=2),
86+
verbosity=1,
87+
project_folder='')
88+
89+
# Add transformer elements
90+
my_pipe += PipelineElement("StandardScaler", hyperparameters={},
91+
test_disabled=True, with_mean=True, with_std=True)
92+
93+
my_pipe += PipelineElement("PCA", test_disabled=False)
94+
95+
# Add estimator
96+
my_pipe += PipelineElement("SVC", hyperparameters={'kernel': ['linear', 'rbf']},
97+
gamma='scale', max_iter=10000)
6898

99+
return my_pipe
100+
```
101+
102+
Now, when you want to run an analysis, you can refer to it by its name and simply call .run(). You can
103+
perform a permutation test in the same way.
104+
```python
69105
# ---------------------------------------------------------------------
70106
# 2) Run analyses
71107
# ---------------------------------------------------------------------
72-
for name in ["all_features", "first_feature_set", "second_feature_set"]:
73-
project.run(name=name)
108+
project.run(name="all_features")
109+
project.run(name="first_feature_set")
110+
project.run(name="second_feature_set")
74111

75112
# ---------------------------------------------------------------------
76113
# 3) Run permutation tests (local example)
77114
# ---------------------------------------------------------------------
78115
# Use a small number of permutations for testing; increase for real studies.
79-
for name in ["all_features", "first_feature_set", "second_feature_set"]:
80-
project.run_permutation_test(name=name, n_perms=10, overwrite=True)
116+
project.run_permutation_test(name="all_features", n_perms=1000)
117+
project.run_permutation_test(name="first_feature_set", n_perms=1000)
118+
project.run_permutation_test(name="second_feature_set", n_perms=1000)
119+
```
81120

121+
If you want to compare two PHOTONAI analyses, you can use the .compare_analyses() method which either uses
122+
the Nadeau-Bengio corrected t-test or relies on the permutations that have been computed in the individual
123+
significance test of each analysis.
124+
```python
82125
# ---------------------------------------------------------------------
83126
# 4) Statistical comparison of analyses
84127
# ---------------------------------------------------------------------
85128
# For the Nadeau–Bengio test you must provide n_train and n_test as used
86129
# during cross-validation. Here we give a simple example.
87-
n_samples = X.shape[0]
88-
n_train = int(0.8 * n_samples)
89-
n_test = n_samples - n_train
90-
91130
# Compare two analyses (Nadeau–Bengio corrected t-test)
92131
project.compare_analyses(
93132
first_analysis="first_feature_set",
94133
second_analysis="second_feature_set",
95134
method="nadeau-bengio",
96-
n_train=n_train,
97-
n_test=n_test,
135+
n_train=9,
136+
n_test=1,
98137
)
99138

100139
# Compare two analyses (permutation-based)
101140
project.compare_analyses(
102141
first_analysis="all_features",
103142
second_analysis="second_feature_set",
104143
method="permutation",
105-
n_perms=10,
144+
n_perms=1000,
106145
)
107146

108147
# Compare all pairs at once (optional)
109148
multi_results = project.compare_multiple_analyses(
110149
analyses=["all_features", "first_feature_set", "second_feature_set"],
111150
method="permutation",
112-
n_perms=10,
151+
n_perms=1000,
113152
)
114153
print(multi_results.head())
115154
```

docs/report.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
# Generate an HTML report for your project
22

3-
## Showcase
3+
## Example code
4+
You can generate an HTML report that summarizes all of your analyses for a project. This makes it easy to get
5+
a quick overview of all results but you can also access more detailed results for every analysis.
6+
7+
```python
8+
# load an existing project
9+
project = PhotonaiProject(name='breast_cancer', directory='./')
410

11+
# then call the collect_results and write_report() function
12+
project.collect_results()
13+
project.write_report()
14+
```
15+
16+
## Showcase
17+
Here, you can see how such an HTML report looks like. Simply click through the individual tabs and look at the results.
518
<iframe src="../static/example_report.html"
619
width="100%" height="700px"
720
sandbox="allow-scripts allow-same-origin"

0 commit comments

Comments
 (0)