Mercurial > repos > bgruening > sklearn_svm_classifier
annotate keras_train_and_eval.py @ 31:80852884053f draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
author | bgruening |
---|---|
date | Sun, 05 Nov 2023 15:03:39 +0000 |
parents | e92c8a69b0e0 |
children |
rev | line source |
---|---|
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
1 import argparse |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
2 import json |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
3 import os |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
4 import warnings |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
5 from itertools import chain |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
6 |
20
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
7 import joblib |
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
8 import numpy as np |
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
9 import pandas as pd |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
10 from galaxy_ml.keras_galaxy_models import ( |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
11 _predict_generator, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
12 KerasGBatchClassifier, |
30
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
13 KerasGClassifier, |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
14 KerasGRegressor |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
15 ) |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
16 from galaxy_ml.model_persist import dump_model_to_h5, load_model_from_h5 |
20
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
17 from galaxy_ml.model_validations import train_test_split |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
18 from galaxy_ml.utils import ( |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
19 clean_params, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
20 gen_compute_scores, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
21 get_main_estimator, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
22 get_module, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
23 get_scoring, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
24 read_columns, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
25 SafeEval |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
26 ) |
20
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
27 from scipy.io import mmread |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
28 from sklearn.metrics._scorer import _check_multimetric_scoring |
20
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
29 from sklearn.model_selection._validation import _score |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
30 from sklearn.utils import _safe_indexing, indexable |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
31 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
32 N_JOBS = int(os.environ.get("GALAXY_SLOTS", 1)) |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
33 CACHE_DIR = os.path.join(os.getcwd(), "cached") |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
34 NON_SEARCHABLE = ( |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
35 "n_jobs", |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
36 "pre_dispatch", |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
37 "memory", |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
38 "_path", |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
39 "_dir", |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
40 "nthread", |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
41 "callbacks", |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
42 ) |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
43 ALLOWED_CALLBACKS = ( |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
44 "EarlyStopping", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
45 "TerminateOnNaN", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
46 "ReduceLROnPlateau", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
47 "CSVLogger", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
48 "None", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
49 ) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
50 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
51 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
52 def _eval_swap_params(params_builder): |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
53 swap_params = {} |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
54 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
55 for p in params_builder["param_set"]: |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
56 swap_value = p["sp_value"].strip() |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
57 if swap_value == "": |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
58 continue |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
59 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
60 param_name = p["sp_name"] |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
61 if param_name.lower().endswith(NON_SEARCHABLE): |
21
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
62 warnings.warn( |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
63 "Warning: `%s` is not eligible for search and was " |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
64 "omitted!" % param_name |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
65 ) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
66 continue |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
67 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
68 if not swap_value.startswith(":"): |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
69 safe_eval = SafeEval(load_scipy=True, load_numpy=True) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
70 ev = safe_eval(swap_value) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
71 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
72 # Have `:` before search list, asks for estimator evaluatio |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
73 safe_eval_es = SafeEval(load_estimators=True) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
74 swap_value = swap_value[1:].strip() |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
75 # TODO maybe add regular express check |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
76 ev = safe_eval_es(swap_value) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
77 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
78 swap_params[param_name] = ev |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
79 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
80 return swap_params |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
81 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
82 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
83 def train_test_split_none(*arrays, **kwargs): |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
84 """extend train_test_split to take None arrays |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
85 and support split by group names. |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
86 """ |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
87 nones = [] |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
88 new_arrays = [] |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
89 for idx, arr in enumerate(arrays): |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
90 if arr is None: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
91 nones.append(idx) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
92 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
93 new_arrays.append(arr) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
94 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
95 if kwargs["shuffle"] == "None": |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
96 kwargs["shuffle"] = None |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
97 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
98 group_names = kwargs.pop("group_names", None) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
99 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
100 if group_names is not None and group_names.strip(): |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
101 group_names = [name.strip() for name in group_names.split(",")] |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
102 new_arrays = indexable(*new_arrays) |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
103 groups = kwargs["labels"] |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
104 n_samples = new_arrays[0].shape[0] |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
105 index_arr = np.arange(n_samples) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
106 test = index_arr[np.isin(groups, group_names)] |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
107 train = index_arr[~np.isin(groups, group_names)] |
21
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
108 rval = list( |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
109 chain.from_iterable( |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
110 (_safe_indexing(a, train), _safe_indexing(a, test)) for a in new_arrays |
21
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
111 ) |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
112 ) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
113 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
114 rval = train_test_split(*new_arrays, **kwargs) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
115 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
116 for pos in nones: |
20
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
117 rval[pos * 2: 2] = [None, None] |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
118 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
119 return rval |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
120 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
121 |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
122 def _evaluate_keras_and_sklearn_scores( |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
123 estimator, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
124 data_generator, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
125 X, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
126 y=None, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
127 sk_scoring=None, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
128 steps=None, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
129 batch_size=32, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
130 return_predictions=False, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
131 ): |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
132 """output scores for bother keras and sklearn metrics |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
133 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
134 Parameters |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
135 ----------- |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
136 estimator : object |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
137 Fitted `galaxy_ml.keras_galaxy_models.KerasGBatchClassifier`. |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
138 data_generator : object |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
139 From `galaxy_ml.preprocessors.ImageDataFrameBatchGenerator`. |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
140 X : 2-D array |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
141 Contains indecies of images that need to be evaluated. |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
142 y : None |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
143 Target value. |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
144 sk_scoring : dict |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
145 Galaxy tool input parameters. |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
146 steps : integer or None |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
147 Evaluation/prediction steps before stop. |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
148 batch_size : integer |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
149 Number of samples in a batch |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
150 return_predictions : bool, default is False |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
151 Whether to return predictions and true labels. |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
152 """ |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
153 scores = {} |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
154 |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
155 generator = data_generator.flow(X, y=y, batch_size=batch_size) |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
156 # keras metrics evaluation |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
157 # handle scorer, convert to scorer dict |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
158 generator.reset() |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
159 score_results = estimator.model_.evaluate_generator(generator, steps=steps) |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
160 metrics_names = estimator.model_.metrics_names |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
161 if not isinstance(metrics_names, list): |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
162 scores[metrics_names] = score_results |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
163 else: |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
164 scores = dict(zip(metrics_names, score_results)) |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
165 |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
166 if sk_scoring["primary_scoring"] == "default" and not return_predictions: |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
167 return scores |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
168 |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
169 generator.reset() |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
170 predictions, y_true = _predict_generator(estimator.model_, generator, steps=steps) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
171 |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
172 # for sklearn metrics |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
173 if sk_scoring["primary_scoring"] != "default": |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
174 scorer = get_scoring(sk_scoring) |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
175 if not isinstance(scorer, (dict, list)): |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
176 scorer = [sk_scoring["primary_scoring"]] |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
177 scorer = _check_multimetric_scoring(estimator, scoring=scorer) |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
178 sk_scores = gen_compute_scores(y_true, predictions, scorer) |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
179 scores.update(sk_scores) |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
180 |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
181 if return_predictions: |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
182 return scores, predictions, y_true |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
183 else: |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
184 return scores, None, None |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
185 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
186 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
187 def main( |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
188 inputs, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
189 infile_estimator, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
190 infile1, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
191 infile2, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
192 outfile_result, |
29
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
193 outfile_history=None, |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
194 outfile_object=None, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
195 outfile_y_true=None, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
196 outfile_y_preds=None, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
197 groups=None, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
198 ref_seq=None, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
199 intervals=None, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
200 targets=None, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
201 fasta_path=None, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
202 ): |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
203 """ |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
204 Parameter |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
205 --------- |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
206 inputs : str |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
207 File path to galaxy tool parameter. |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
208 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
209 infile_estimator : str |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
210 File path to estimator. |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
211 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
212 infile1 : str |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
213 File path to dataset containing features. |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
214 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
215 infile2 : str |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
216 File path to dataset containing target values. |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
217 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
218 outfile_result : str |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
219 File path to save the results, either cv_results or test result. |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
220 |
29
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
221 outfile_history : str, optional |
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
222 File path to save the training history. |
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
223 |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
224 outfile_object : str, optional |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
225 File path to save searchCV object. |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
226 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
227 outfile_y_true : str, optional |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
228 File path to target values for prediction. |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
229 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
230 outfile_y_preds : str, optional |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
231 File path to save predictions. |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
232 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
233 groups : str |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
234 File path to dataset containing groups labels. |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
235 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
236 ref_seq : str |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
237 File path to dataset containing genome sequence file. |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
238 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
239 intervals : str |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
240 File path to dataset containing interval file. |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
241 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
242 targets : str |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
243 File path to dataset compressed target bed file. |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
244 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
245 fasta_path : str |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
246 File path to dataset containing fasta file. |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
247 """ |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
248 warnings.simplefilter("ignore") |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
249 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
250 with open(inputs, "r") as param_handler: |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
251 params = json.load(param_handler) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
252 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
253 # load estimator |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
254 estimator = load_model_from_h5(infile_estimator) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
255 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
256 estimator = clean_params(estimator) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
257 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
258 # swap hyperparameter |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
259 swapping = params["experiment_schemes"]["hyperparams_swapping"] |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
260 swap_params = _eval_swap_params(swapping) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
261 estimator.set_params(**swap_params) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
262 estimator_params = estimator.get_params() |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
263 # store read dataframe object |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
264 loaded_df = {} |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
265 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
266 input_type = params["input_options"]["selected_input"] |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
267 # tabular input |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
268 if input_type == "tabular": |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
269 header = "infer" if params["input_options"]["header1"] else None |
21
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
270 column_option = params["input_options"]["column_selector_options_1"][ |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
271 "selected_column_selector_option" |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
272 ] |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
273 if column_option in [ |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
274 "by_index_number", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
275 "all_but_by_index_number", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
276 "by_header_name", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
277 "all_but_by_header_name", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
278 ]: |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
279 c = params["input_options"]["column_selector_options_1"]["col1"] |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
280 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
281 c = None |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
282 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
283 df_key = infile1 + repr(header) |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
284 df = pd.read_csv(infile1, sep="\t", header=header, parse_dates=True) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
285 loaded_df[df_key] = df |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
286 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
287 X = read_columns(df, c=c, c_option=column_option).astype(float) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
288 # sparse input |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
289 elif input_type == "sparse": |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
290 X = mmread(open(infile1, "r")) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
291 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
292 # fasta_file input |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
293 elif input_type == "seq_fasta": |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
294 pyfaidx = get_module("pyfaidx") |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
295 sequences = pyfaidx.Fasta(fasta_path) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
296 n_seqs = len(sequences.keys()) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
297 X = np.arange(n_seqs)[:, np.newaxis] |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
298 for param in estimator_params.keys(): |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
299 if param.endswith("fasta_path"): |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
300 estimator.set_params(**{param: fasta_path}) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
301 break |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
302 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
303 raise ValueError( |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
304 "The selected estimator doesn't support " |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
305 "fasta file input! Please consider using " |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
306 "KerasGBatchClassifier with " |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
307 "FastaDNABatchGenerator/FastaProteinBatchGenerator " |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
308 "or having GenomeOneHotEncoder/ProteinOneHotEncoder " |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
309 "in pipeline!" |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
310 ) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
311 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
312 elif input_type == "refseq_and_interval": |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
313 path_params = { |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
314 "data_batch_generator__ref_genome_path": ref_seq, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
315 "data_batch_generator__intervals_path": intervals, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
316 "data_batch_generator__target_path": targets, |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
317 } |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
318 estimator.set_params(**path_params) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
319 n_intervals = sum(1 for line in open(intervals)) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
320 X = np.arange(n_intervals)[:, np.newaxis] |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
321 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
322 # Get target y |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
323 header = "infer" if params["input_options"]["header2"] else None |
21
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
324 column_option = params["input_options"]["column_selector_options_2"][ |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
325 "selected_column_selector_option2" |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
326 ] |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
327 if column_option in [ |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
328 "by_index_number", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
329 "all_but_by_index_number", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
330 "by_header_name", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
331 "all_but_by_header_name", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
332 ]: |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
333 c = params["input_options"]["column_selector_options_2"]["col2"] |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
334 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
335 c = None |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
336 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
337 df_key = infile2 + repr(header) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
338 if df_key in loaded_df: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
339 infile2 = loaded_df[df_key] |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
340 else: |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
341 infile2 = pd.read_csv(infile2, sep="\t", header=header, parse_dates=True) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
342 loaded_df[df_key] = infile2 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
343 |
21
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
344 y = read_columns( |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
345 infile2, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
346 c=c, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
347 c_option=column_option, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
348 sep="\t", |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
349 header=header, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
350 parse_dates=True, |
21
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
351 ) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
352 if len(y.shape) == 2 and y.shape[1] == 1: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
353 y = y.ravel() |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
354 if input_type == "refseq_and_interval": |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
355 estimator.set_params(data_batch_generator__features=y.ravel().tolist()) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
356 y = None |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
357 # end y |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
358 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
359 # load groups |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
360 if groups: |
21
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
361 groups_selector = ( |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
362 params["experiment_schemes"]["test_split"]["split_algos"] |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
363 ).pop("groups_selector") |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
364 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
365 header = "infer" if groups_selector["header_g"] else None |
21
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
366 column_option = groups_selector["column_selector_options_g"][ |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
367 "selected_column_selector_option_g" |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
368 ] |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
369 if column_option in [ |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
370 "by_index_number", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
371 "all_but_by_index_number", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
372 "by_header_name", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
373 "all_but_by_header_name", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
374 ]: |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
375 c = groups_selector["column_selector_options_g"]["col_g"] |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
376 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
377 c = None |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
378 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
379 df_key = groups + repr(header) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
380 if df_key in loaded_df: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
381 groups = loaded_df[df_key] |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
382 |
21
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
383 groups = read_columns( |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
384 groups, |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
385 c=c, |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
386 c_option=column_option, |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
387 sep="\t", |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
388 header=header, |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
389 parse_dates=True, |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
390 ) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
391 groups = groups.ravel() |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
392 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
393 # del loaded_df |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
394 del loaded_df |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
395 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
396 # cache iraps_core fits could increase search speed significantly |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
397 memory = joblib.Memory(location=CACHE_DIR, verbose=0) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
398 main_est = get_main_estimator(estimator) |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
399 if main_est.__class__.__name__ == "IRAPSClassifier": |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
400 main_est.set_params(memory=memory) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
401 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
402 # handle scorer, convert to scorer dict |
21
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
403 scoring = params["experiment_schemes"]["metrics"]["scoring"] |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
404 scorer = get_scoring(scoring) |
30
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
405 |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
406 # We get 'None' back from the call to 'get_scoring()' if |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
407 # the primary scoring is 'default'. Replace 'default' with |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
408 # the default scoring for classification/regression (accuracy/r2) |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
409 if scorer is None: |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
410 if isinstance(estimator, KerasGClassifier): |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
411 scorer = ['accuracy'] |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
412 if isinstance(estimator, KerasGRegressor): |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
413 scorer = ['r2'] |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
414 |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
415 scorer = _check_multimetric_scoring(estimator, scoring=scorer) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
416 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
417 # handle test (first) split |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
418 test_split_options = params["experiment_schemes"]["test_split"]["split_algos"] |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
419 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
420 if test_split_options["shuffle"] == "group": |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
421 test_split_options["labels"] = groups |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
422 if test_split_options["shuffle"] == "stratified": |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
423 if y is not None: |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
424 test_split_options["labels"] = y |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
425 else: |
21
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
426 raise ValueError( |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
427 "Stratified shuffle split is not " "applicable on empty target values!" |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
428 ) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
429 |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
430 X_train, X_test, y_train, y_test, groups_train, groups_test = train_test_split_none( |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
431 X, y, groups, **test_split_options |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
432 ) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
433 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
434 exp_scheme = params["experiment_schemes"]["selected_exp_scheme"] |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
435 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
436 # handle validation (second) split |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
437 if exp_scheme == "train_val_test": |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
438 val_split_options = params["experiment_schemes"]["val_split"]["split_algos"] |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
439 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
440 if val_split_options["shuffle"] == "group": |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
441 val_split_options["labels"] = groups_train |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
442 if val_split_options["shuffle"] == "stratified": |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
443 if y_train is not None: |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
444 val_split_options["labels"] = y_train |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
445 else: |
21
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
446 raise ValueError( |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
447 "Stratified shuffle split is not " |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
448 "applicable on empty target values!" |
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
449 ) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
450 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
451 ( |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
452 X_train, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
453 X_val, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
454 y_train, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
455 y_val, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
456 groups_train, |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
457 groups_val, |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
458 ) = train_test_split_none(X_train, y_train, groups_train, **val_split_options) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
459 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
460 # train and eval |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
461 if hasattr(estimator, "config") and hasattr(estimator, "model_type"): |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
462 if exp_scheme == "train_val_test": |
29
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
463 history = estimator.fit(X_train, y_train, validation_data=(X_val, y_val)) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
464 else: |
29
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
465 history = estimator.fit(X_train, y_train, validation_data=(X_test, y_test)) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
466 else: |
29
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
467 history = estimator.fit(X_train, y_train) |
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
468 if "callbacks" in estimator_params: |
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
469 for cb in estimator_params["callbacks"]: |
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
470 if cb["callback_selection"]["callback_type"] == "CSVLogger": |
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
471 hist_df = pd.DataFrame(history.history) |
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
472 hist_df["epoch"] = np.arange(1, estimator_params["epochs"] + 1) |
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
473 epo_col = hist_df.pop('epoch') |
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
474 hist_df.insert(0, 'epoch', epo_col) |
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
475 hist_df.to_csv(path_or_buf=outfile_history, sep="\t", header=True, index=False) |
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
476 break |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
477 if isinstance(estimator, KerasGBatchClassifier): |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
478 scores = {} |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
479 steps = estimator.prediction_steps |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
480 batch_size = estimator.batch_size |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
481 data_generator = estimator.data_generator_ |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
482 |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
483 scores, predictions, y_true = _evaluate_keras_and_sklearn_scores( |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
484 estimator, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
485 data_generator, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
486 X_test, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
487 y=y_test, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
488 sk_scoring=scoring, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
489 steps=steps, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
490 batch_size=batch_size, |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
491 return_predictions=bool(outfile_y_true), |
21
14fa42b095c4
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents:
20
diff
changeset
|
492 ) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
493 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
494 else: |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
495 scores = {} |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
496 if hasattr(estimator, "model_") and hasattr(estimator.model_, "metrics_names"): |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
497 batch_size = estimator.batch_size |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
498 score_results = estimator.model_.evaluate( |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
499 X_test, y=y_test, batch_size=batch_size, verbose=0 |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
500 ) |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
501 metrics_names = estimator.model_.metrics_names |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
502 if not isinstance(metrics_names, list): |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
503 scores[metrics_names] = score_results |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
504 else: |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
505 scores = dict(zip(metrics_names, score_results)) |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
506 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
507 if hasattr(estimator, "predict_proba"): |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
508 predictions = estimator.predict_proba(X_test) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
509 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
510 predictions = estimator.predict(X_test) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
511 |
30
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
512 # Un-do OHE of the validation labels |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
513 if len(y_test.shape) == 2: |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
514 rounded_test_labels = np.argmax(y_test, axis=1) |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
515 y_true = rounded_test_labels |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
516 sk_scores = _score(estimator, X_test, rounded_test_labels, scorer) |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
517 else: |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
518 y_true = y_test |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
519 sk_scores = _score(estimator, X_test, y_true, scorer) |
e92c8a69b0e0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5eca9041ce0154eded5aec07195502d5eb3cdd4f
bgruening
parents:
29
diff
changeset
|
520 |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
521 scores.update(sk_scores) |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
522 |
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
523 # handle output |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
524 if outfile_y_true: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
525 try: |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
526 pd.DataFrame(y_true).to_csv(outfile_y_true, sep="\t", index=False) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
527 pd.DataFrame(predictions).astype(np.float32).to_csv( |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
528 outfile_y_preds, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
529 sep="\t", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
530 index=False, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
531 float_format="%g", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
532 chunksize=10000, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
533 ) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
534 except Exception as e: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
535 print("Error in saving predictions: %s" % e) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
536 # handle output |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
537 for name, score in scores.items(): |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
538 scores[name] = [score] |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
539 df = pd.DataFrame(scores) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
540 df = df[sorted(df.columns)] |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
541 df.to_csv(path_or_buf=outfile_result, sep="\t", header=True, index=False) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
542 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
543 memory.clear(warn=False) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
544 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
545 if outfile_object: |
25
b878e4cdd63a
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents:
21
diff
changeset
|
546 dump_model_to_h5(estimator, outfile_object) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
547 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
548 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
549 if __name__ == "__main__": |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
550 aparser = argparse.ArgumentParser() |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
551 aparser.add_argument("-i", "--inputs", dest="inputs", required=True) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
552 aparser.add_argument("-e", "--estimator", dest="infile_estimator") |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
553 aparser.add_argument("-X", "--infile1", dest="infile1") |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
554 aparser.add_argument("-y", "--infile2", dest="infile2") |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
555 aparser.add_argument("-O", "--outfile_result", dest="outfile_result") |
29
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
556 aparser.add_argument("-hi", "--outfile_history", dest="outfile_history") |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
557 aparser.add_argument("-o", "--outfile_object", dest="outfile_object") |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
558 aparser.add_argument("-l", "--outfile_y_true", dest="outfile_y_true") |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
559 aparser.add_argument("-p", "--outfile_y_preds", dest="outfile_y_preds") |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
560 aparser.add_argument("-g", "--groups", dest="groups") |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
561 aparser.add_argument("-r", "--ref_seq", dest="ref_seq") |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
562 aparser.add_argument("-b", "--intervals", dest="intervals") |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
563 aparser.add_argument("-t", "--targets", dest="targets") |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
564 aparser.add_argument("-f", "--fasta_path", dest="fasta_path") |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
565 args = aparser.parse_args() |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
566 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
567 main( |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
568 args.inputs, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
569 args.infile_estimator, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
570 args.infile1, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
571 args.infile2, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
572 args.outfile_result, |
29
0630258dcf35
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
bgruening
parents:
25
diff
changeset
|
573 outfile_history=args.outfile_history, |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
574 outfile_object=args.outfile_object, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
575 outfile_y_true=args.outfile_y_true, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
576 outfile_y_preds=args.outfile_y_preds, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
577 groups=args.groups, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
578 ref_seq=args.ref_seq, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
579 intervals=args.intervals, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
580 targets=args.targets, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
581 fasta_path=args.fasta_path, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
582 ) |