Mercurial > repos > bgruening > sklearn_svm_classifier
annotate keras_train_and_eval.py @ 20:a5665e1b06b0 draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
author | bgruening |
---|---|
date | Tue, 13 Apr 2021 22:52:20 +0000 |
parents | d67dcd63f6cb |
children | 14fa42b095c4 |
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 pickle |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
5 import warnings |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
6 from itertools import chain |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
7 |
20
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
8 import joblib |
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
9 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
|
10 import pandas as pd |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
11 from galaxy_ml.externals.selene_sdk.utils import compute_score |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
12 from galaxy_ml.keras_galaxy_models import _predict_generator |
20
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
13 from galaxy_ml.model_validations import train_test_split |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
14 from galaxy_ml.utils import ( |
20
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
15 clean_params, |
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
16 get_main_estimator, |
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
17 get_module, |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
18 get_scoring, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
19 load_model, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
20 read_columns, |
20
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
21 SafeEval, |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
22 try_get_attr, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
23 ) |
20
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
24 from scipy.io import mmread |
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
25 from sklearn.metrics.scorer import _check_multimetric_scoring |
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
26 from sklearn.model_selection import _search, _validation |
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
27 from sklearn.model_selection._validation import _score |
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
28 from sklearn.pipeline import Pipeline |
a5665e1b06b0
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
19
diff
changeset
|
29 from sklearn.utils import indexable, safe_indexing |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
30 |
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 _fit_and_score = try_get_attr("galaxy_ml.model_validations", "_fit_and_score") |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
33 setattr(_search, "_fit_and_score", _fit_and_score) |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
34 setattr(_validation, "_fit_and_score", _fit_and_score) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
35 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
36 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
|
37 CACHE_DIR = os.path.join(os.getcwd(), "cached") |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
38 del os |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
39 NON_SEARCHABLE = ("n_jobs", "pre_dispatch", "memory", "_path", "nthread", "callbacks") |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
40 ALLOWED_CALLBACKS = ( |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
41 "EarlyStopping", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
42 "TerminateOnNaN", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
43 "ReduceLROnPlateau", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
44 "CSVLogger", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
45 "None", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
46 ) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
47 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
48 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
49 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
|
50 swap_params = {} |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
51 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
52 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
|
53 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
|
54 if swap_value == "": |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
55 continue |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
56 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
57 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
|
58 if param_name.lower().endswith(NON_SEARCHABLE): |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
59 warnings.warn("Warning: `%s` is not eligible for search and was " "omitted!" % param_name) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
60 continue |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
61 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
66 # 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
|
67 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
|
68 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
|
69 # 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
|
70 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
|
71 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
72 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
|
73 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
74 return swap_params |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
75 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
76 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
77 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
|
78 """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
|
79 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
|
80 """ |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
81 nones = [] |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
82 new_arrays = [] |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
83 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
|
84 if arr is None: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
85 nones.append(idx) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
86 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
87 new_arrays.append(arr) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
88 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
89 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
|
90 kwargs["shuffle"] = None |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
91 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
92 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
|
93 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
94 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
|
95 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
|
96 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
|
97 groups = kwargs["labels"] |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 train = index_arr[~np.isin(groups, group_names)] |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
102 rval = list(chain.from_iterable((safe_indexing(a, train), safe_indexing(a, test)) for a in new_arrays)) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
103 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
104 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
|
105 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
106 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
|
107 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
|
108 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
109 return rval |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
110 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
111 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
112 def _evaluate(y_true, pred_probas, scorer, is_multimetric=True): |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
113 """output scores based on input scorer |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
114 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
115 Parameters |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
116 ---------- |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
117 y_true : array |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
118 True label or target values |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
119 pred_probas : array |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
120 Prediction values, probability for classification problem |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
121 scorer : dict |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
122 dict of `sklearn.metrics.scorer.SCORER` |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
123 is_multimetric : bool, default is True |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
124 """ |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
125 if y_true.ndim == 1 or y_true.shape[-1] == 1: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
126 pred_probas = pred_probas.ravel() |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
127 pred_labels = (pred_probas > 0.5).astype("int32") |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
128 targets = y_true.ravel().astype("int32") |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
129 if not is_multimetric: |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
130 preds = pred_labels if scorer.__class__.__name__ == "_PredictScorer" else pred_probas |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
131 score = scorer._score_func(targets, preds, **scorer._kwargs) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
132 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
133 return score |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
134 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
135 scores = {} |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
136 for name, one_scorer in scorer.items(): |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
137 preds = pred_labels if one_scorer.__class__.__name__ == "_PredictScorer" else pred_probas |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
138 score = one_scorer._score_func(targets, preds, **one_scorer._kwargs) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
139 scores[name] = score |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
140 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
141 # TODO: multi-class metrics |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
142 # multi-label |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
143 else: |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
144 pred_labels = (pred_probas > 0.5).astype("int32") |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
145 targets = y_true.astype("int32") |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
146 if not is_multimetric: |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
147 preds = pred_labels if scorer.__class__.__name__ == "_PredictScorer" else pred_probas |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
148 score, _ = compute_score(preds, targets, scorer._score_func) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
149 return score |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
150 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
151 scores = {} |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
152 for name, one_scorer in scorer.items(): |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
153 preds = pred_labels if one_scorer.__class__.__name__ == "_PredictScorer" else pred_probas |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
154 score, _ = compute_score(preds, targets, one_scorer._score_func) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
155 scores[name] = score |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
156 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
157 return scores |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
158 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
159 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
160 def main( |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
161 inputs, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
162 infile_estimator, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
163 infile1, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
164 infile2, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
165 outfile_result, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
166 outfile_object=None, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
167 outfile_weights=None, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
168 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
|
169 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
|
170 groups=None, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
171 ref_seq=None, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
172 intervals=None, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
173 targets=None, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
174 fasta_path=None, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
175 ): |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
176 """ |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
177 Parameter |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
178 --------- |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
179 inputs : str |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
180 File path to galaxy tool parameter |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
181 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
182 infile_estimator : str |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
183 File path to estimator |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
184 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
185 infile1 : str |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
186 File path to dataset containing features |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
187 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
188 infile2 : str |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
189 File path to dataset containing target values |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
190 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
191 outfile_result : str |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
192 File path to save the results, either cv_results or test result |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
193 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
194 outfile_object : str, optional |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
195 File path to save searchCV object |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
196 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
197 outfile_weights : str, optional |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
198 File path to save deep learning model weights |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
199 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
200 outfile_y_true : str, optional |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
201 File path to target values for prediction |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
202 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
203 outfile_y_preds : str, optional |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
204 File path to save deep learning model weights |
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 groups : str |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
207 File path to dataset containing groups labels |
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 ref_seq : str |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
210 File path to dataset containing genome sequence file |
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 intervals : str |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
213 File path to dataset containing interval file |
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 targets : str |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
216 File path to dataset compressed target bed file |
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 fasta_path : str |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
219 File path to dataset containing fasta file |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
220 """ |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
221 warnings.simplefilter("ignore") |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
222 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
223 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
|
224 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
|
225 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
226 # load estimator |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
227 with open(infile_estimator, "rb") as estimator_handler: |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
228 estimator = load_model(estimator_handler) |
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 estimator = clean_params(estimator) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
231 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
232 # swap hyperparameter |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
233 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
|
234 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
|
235 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
|
236 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
237 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
|
238 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
239 # store read dataframe object |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
240 loaded_df = {} |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
241 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
242 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
|
243 # tabular input |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
244 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
|
245 header = "infer" if params["input_options"]["header1"] else None |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
246 column_option = params["input_options"]["column_selector_options_1"]["selected_column_selector_option"] |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
247 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
|
248 "by_index_number", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
249 "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
|
250 "by_header_name", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
251 "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
|
252 ]: |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
253 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
|
254 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
255 c = None |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
256 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
257 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
|
258 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
|
259 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
|
260 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
261 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
|
262 # sparse input |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
263 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
|
264 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
|
265 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
266 # 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 break |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
276 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
277 raise ValueError( |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
278 "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
|
279 "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
|
280 "KerasGBatchClassifier with " |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
281 "FastaDNABatchGenerator/FastaProteinBatchGenerator " |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
282 "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
|
283 "in pipeline!" |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
284 ) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
285 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
286 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
|
287 path_params = { |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
288 "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
|
289 "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
|
290 "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
|
291 } |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
292 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
|
293 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
|
294 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
|
295 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
296 # 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
|
297 header = "infer" if params["input_options"]["header2"] else None |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
298 column_option = params["input_options"]["column_selector_options_2"]["selected_column_selector_option2"] |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
299 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
|
300 "by_index_number", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
301 "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
|
302 "by_header_name", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
303 "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
|
304 ]: |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
305 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
|
306 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
307 c = None |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
308 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
309 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
|
310 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
|
311 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
|
312 else: |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
313 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
|
314 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
|
315 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
316 y = read_columns(infile2, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
317 c=c, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
318 c_option=column_option, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
319 sep='\t', |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
320 header=header, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
321 parse_dates=True) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
322 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
|
323 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
|
324 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
|
325 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
|
326 y = None |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
327 # end y |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
328 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
329 # load groups |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
330 if groups: |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
331 groups_selector = (params["experiment_schemes"]["test_split"]["split_algos"]).pop("groups_selector") |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
332 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
333 header = "infer" if groups_selector["header_g"] else None |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
334 column_option = groups_selector["column_selector_options_g"]["selected_column_selector_option_g"] |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
335 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
|
336 "by_index_number", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
337 "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
|
338 "by_header_name", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
339 "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
|
340 ]: |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
341 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
|
342 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
343 c = None |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
344 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
345 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
|
346 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
|
347 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
|
348 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
349 groups = read_columns(groups, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
350 c=c, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
351 c_option=column_option, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
352 sep='\t', |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
353 header=header, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
354 parse_dates=True) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
355 groups = groups.ravel() |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
356 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
357 # del loaded_df |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
358 del loaded_df |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
359 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
360 # 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
|
361 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
|
362 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
|
363 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
|
364 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
|
365 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
366 # handle scorer, convert to scorer dict |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
367 scoring = params['experiment_schemes']['metrics']['scoring'] |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
368 if scoring is not None: |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
369 # get_scoring() expects secondary_scoring to be a comma separated string (not a list) |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
370 # Check if secondary_scoring is specified |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
371 secondary_scoring = scoring.get("secondary_scoring", None) |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
372 if secondary_scoring is not None: |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
373 # If secondary_scoring is specified, convert the list into comman separated string |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
374 scoring["secondary_scoring"] = ",".join(scoring["secondary_scoring"]) |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
375 |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
376 scorer = get_scoring(scoring) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
377 scorer, _ = _check_multimetric_scoring(estimator, scoring=scorer) |
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 # 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
|
380 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
|
381 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
382 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
|
383 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
|
384 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
|
385 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
|
386 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
|
387 else: |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
388 raise ValueError("Stratified shuffle split is not " "applicable on empty target values!") |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
389 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
390 ( |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
391 X_train, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
392 X_test, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
393 y_train, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
394 y_test, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
395 groups_train, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
396 _groups_test, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
397 ) = train_test_split_none(X, y, groups, **test_split_options) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
398 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
399 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
|
400 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
401 # 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
|
402 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
|
403 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
|
404 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
405 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
|
406 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
|
407 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
|
408 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
|
409 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
|
410 else: |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
411 raise ValueError("Stratified shuffle split is not " "applicable on empty target values!") |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
412 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
413 ( |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
414 X_train, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
415 X_val, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
416 y_train, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
417 y_val, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
418 groups_train, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
419 _groups_val, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
420 ) = 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
|
421 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
422 # train and eval |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
423 if hasattr(estimator, "validation_data"): |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
424 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
|
425 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
|
426 else: |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
427 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
|
428 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
429 estimator.fit(X_train, y_train) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
430 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
431 if hasattr(estimator, "evaluate"): |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
432 steps = estimator.prediction_steps |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
433 batch_size = estimator.batch_size |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
434 generator = estimator.data_generator_.flow(X_test, y=y_test, batch_size=batch_size) |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
435 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
|
436 scores = _evaluate(y_true, predictions, scorer, is_multimetric=True) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
437 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
438 else: |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
439 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
|
440 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
|
441 else: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
442 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
|
443 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
444 y_true = y_test |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
445 scores = _score(estimator, X_test, y_test, scorer, is_multimetric=True) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
446 if outfile_y_true: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
447 try: |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
448 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
|
449 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
|
450 outfile_y_preds, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
451 sep="\t", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
452 index=False, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
453 float_format="%g", |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
454 chunksize=10000, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
455 ) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
456 except Exception as e: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
457 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
|
458 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
459 # handle output |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
460 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
|
461 scores[name] = [score] |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
462 df = pd.DataFrame(scores) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
463 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
|
464 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
|
465 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
466 memory.clear(warn=False) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
467 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
468 if outfile_object: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
469 main_est = estimator |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
470 if isinstance(estimator, Pipeline): |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
471 main_est = estimator.steps[-1][-1] |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
472 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
473 if hasattr(main_est, "model_") and hasattr(main_est, "save_weights"): |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
474 if outfile_weights: |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
475 main_est.save_weights(outfile_weights) |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
476 del main_est.model_ |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
477 del main_est.fit_params |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
478 del main_est.model_class_ |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
479 if getattr(main_est, "validation_data", None): |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
480 del main_est.validation_data |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
481 if getattr(main_est, "data_generator_", None): |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
482 del main_est.data_generator_ |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
483 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
484 with open(outfile_object, "wb") as output_handler: |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
485 pickle.dump(estimator, output_handler, pickle.HIGHEST_PROTOCOL) |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
486 |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
487 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
488 if __name__ == "__main__": |
15
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
489 aparser = argparse.ArgumentParser() |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
490 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
|
491 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
|
492 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
|
493 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
|
494 aparser.add_argument("-O", "--outfile_result", dest="outfile_result") |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
495 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
|
496 aparser.add_argument("-w", "--outfile_weights", dest="outfile_weights") |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
497 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
|
498 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
|
499 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
|
500 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
|
501 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
|
502 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
|
503 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
|
504 args = aparser.parse_args() |
2df8f5c30edc
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
diff
changeset
|
505 |
19
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
506 main( |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
507 args.inputs, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
508 args.infile_estimator, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
509 args.infile1, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
510 args.infile2, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
511 args.outfile_result, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
512 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
|
513 outfile_weights=args.outfile_weights, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
514 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
|
515 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
|
516 groups=args.groups, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
517 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
|
518 intervals=args.intervals, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
519 targets=args.targets, |
d67dcd63f6cb
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
15
diff
changeset
|
520 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
|
521 ) |