Mercurial > repos > bgruening > sklearn_nn_classifier
annotate search_model_validation.py @ 22:34d31bd995e9 draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
author | bgruening |
---|---|
date | Tue, 13 Apr 2021 22:12:07 +0000 |
parents | 1d3447c2203c |
children | 823ecc0bce45 |
rev | line source |
---|---|
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
1 import argparse |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
2 import collections |
22
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
3 import json |
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
4 import os |
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
5 import pickle |
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
6 import sys |
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
7 import warnings |
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
8 |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
9 import imblearn |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
10 import joblib |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
11 import numpy as np |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
12 import pandas as pd |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
13 import skrebate |
22
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
14 from galaxy_ml.utils import ( |
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
15 clean_params, |
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
16 get_cv, |
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
17 get_main_estimator, |
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
18 get_module, |
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
19 get_scoring, |
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
20 load_model, |
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
21 read_columns, |
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
22 SafeEval, |
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
23 try_get_attr |
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
24 ) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
25 from scipy.io import mmread |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
26 from sklearn import ( |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
27 cluster, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
28 decomposition, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
29 feature_selection, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
30 kernel_approximation, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
31 model_selection, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
32 preprocessing, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
33 ) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
34 from sklearn.exceptions import FitFailedWarning |
22
34d31bd995e9
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents:
21
diff
changeset
|
35 from sklearn.model_selection import _search, _validation |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
36 from sklearn.model_selection._validation import _score, cross_validate |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
37 |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
38 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
39 _fit_and_score = try_get_attr("galaxy_ml.model_validations", "_fit_and_score") |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
40 setattr(_search, "_fit_and_score", _fit_and_score) |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
41 setattr(_validation, "_fit_and_score", _fit_and_score) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
42 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
43 N_JOBS = int(os.environ.get("GALAXY_SLOTS", 1)) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
44 # handle disk cache |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
45 CACHE_DIR = os.path.join(os.getcwd(), "cached") |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
46 del os |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
47 NON_SEARCHABLE = ("n_jobs", "pre_dispatch", "memory", "_path", "nthread", "callbacks") |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
48 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
49 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
50 def _eval_search_params(params_builder): |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
51 search_params = {} |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
52 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
53 for p in params_builder["param_set"]: |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
54 search_list = p["sp_list"].strip() |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
55 if search_list == "": |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
56 continue |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
57 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
58 param_name = p["sp_name"] |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
59 if param_name.lower().endswith(NON_SEARCHABLE): |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
60 print("Warning: `%s` is not eligible for search and was " "omitted!" % param_name) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
61 continue |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
62 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
63 if not search_list.startswith(":"): |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
64 safe_eval = SafeEval(load_scipy=True, load_numpy=True) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
65 ev = safe_eval(search_list) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
66 search_params[param_name] = ev |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
67 else: |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
68 # Have `:` before search list, asks for estimator evaluatio |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
69 safe_eval_es = SafeEval(load_estimators=True) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
70 search_list = search_list[1:].strip() |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
71 # TODO maybe add regular express check |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
72 ev = safe_eval_es(search_list) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
73 preprocessings = ( |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
74 preprocessing.StandardScaler(), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
75 preprocessing.Binarizer(), |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
76 preprocessing.MaxAbsScaler(), |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
77 preprocessing.Normalizer(), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
78 preprocessing.MinMaxScaler(), |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
79 preprocessing.PolynomialFeatures(), |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
80 preprocessing.RobustScaler(), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
81 feature_selection.SelectKBest(), |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
82 feature_selection.GenericUnivariateSelect(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
83 feature_selection.SelectPercentile(), |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
84 feature_selection.SelectFpr(), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
85 feature_selection.SelectFdr(), |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
86 feature_selection.SelectFwe(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
87 feature_selection.VarianceThreshold(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
88 decomposition.FactorAnalysis(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
89 decomposition.FastICA(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
90 decomposition.IncrementalPCA(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
91 decomposition.KernelPCA(random_state=0, n_jobs=N_JOBS), |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
92 decomposition.LatentDirichletAllocation(random_state=0, n_jobs=N_JOBS), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
93 decomposition.MiniBatchDictionaryLearning(random_state=0, n_jobs=N_JOBS), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
94 decomposition.MiniBatchSparsePCA(random_state=0, n_jobs=N_JOBS), |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
95 decomposition.NMF(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
96 decomposition.PCA(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
97 decomposition.SparsePCA(random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
98 decomposition.TruncatedSVD(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
99 kernel_approximation.Nystroem(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
100 kernel_approximation.RBFSampler(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
101 kernel_approximation.AdditiveChi2Sampler(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
102 kernel_approximation.SkewedChi2Sampler(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
103 cluster.FeatureAgglomeration(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
104 skrebate.ReliefF(n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
105 skrebate.SURF(n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
106 skrebate.SURFstar(n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
107 skrebate.MultiSURF(n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
108 skrebate.MultiSURFstar(n_jobs=N_JOBS), |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
109 imblearn.under_sampling.ClusterCentroids(random_state=0, n_jobs=N_JOBS), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
110 imblearn.under_sampling.CondensedNearestNeighbour(random_state=0, n_jobs=N_JOBS), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
111 imblearn.under_sampling.EditedNearestNeighbours(random_state=0, n_jobs=N_JOBS), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
112 imblearn.under_sampling.RepeatedEditedNearestNeighbours(random_state=0, n_jobs=N_JOBS), |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
113 imblearn.under_sampling.AllKNN(random_state=0, n_jobs=N_JOBS), |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
114 imblearn.under_sampling.InstanceHardnessThreshold(random_state=0, n_jobs=N_JOBS), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
115 imblearn.under_sampling.NearMiss(random_state=0, n_jobs=N_JOBS), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
116 imblearn.under_sampling.NeighbourhoodCleaningRule(random_state=0, n_jobs=N_JOBS), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
117 imblearn.under_sampling.OneSidedSelection(random_state=0, n_jobs=N_JOBS), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
118 imblearn.under_sampling.RandomUnderSampler(random_state=0), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
119 imblearn.under_sampling.TomekLinks(random_state=0, n_jobs=N_JOBS), |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
120 imblearn.over_sampling.ADASYN(random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
121 imblearn.over_sampling.RandomOverSampler(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
122 imblearn.over_sampling.SMOTE(random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
123 imblearn.over_sampling.SVMSMOTE(random_state=0, n_jobs=N_JOBS), |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
124 imblearn.over_sampling.BorderlineSMOTE(random_state=0, n_jobs=N_JOBS), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
125 imblearn.over_sampling.SMOTENC(categorical_features=[], random_state=0, n_jobs=N_JOBS), |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
126 imblearn.combine.SMOTEENN(random_state=0), |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
127 imblearn.combine.SMOTETomek(random_state=0), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
128 ) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
129 newlist = [] |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
130 for obj in ev: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
131 if obj is None: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
132 newlist.append(None) |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
133 elif obj == "all_0": |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
134 newlist.extend(preprocessings[0:35]) |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
135 elif obj == "sk_prep_all": # no KernalCenter() |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
136 newlist.extend(preprocessings[0:7]) |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
137 elif obj == "fs_all": |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
138 newlist.extend(preprocessings[7:14]) |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
139 elif obj == "decomp_all": |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
140 newlist.extend(preprocessings[14:25]) |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
141 elif obj == "k_appr_all": |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
142 newlist.extend(preprocessings[25:29]) |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
143 elif obj == "reb_all": |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
144 newlist.extend(preprocessings[30:35]) |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
145 elif obj == "imb_all": |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
146 newlist.extend(preprocessings[35:54]) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
147 elif type(obj) is int and -1 < obj < len(preprocessings): |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
148 newlist.append(preprocessings[obj]) |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
149 elif hasattr(obj, "get_params"): # user uploaded object |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
150 if "n_jobs" in obj.get_params(): |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
151 newlist.append(obj.set_params(n_jobs=N_JOBS)) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
152 else: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
153 newlist.append(obj) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
154 else: |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
155 sys.exit("Unsupported estimator type: %r" % (obj)) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
156 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
157 search_params[param_name] = newlist |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
158 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
159 return search_params |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
160 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
161 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
162 def _handle_X_y( |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
163 estimator, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
164 params, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
165 infile1, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
166 infile2, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
167 loaded_df={}, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
168 ref_seq=None, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
169 intervals=None, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
170 targets=None, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
171 fasta_path=None, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
172 ): |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
173 """read inputs |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
174 |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
175 Params |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
176 ------- |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
177 estimator : estimator object |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
178 params : dict |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
179 Galaxy tool parameter inputs |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
180 infile1 : str |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
181 File path to dataset containing features |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
182 infile2 : str |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
183 File path to dataset containing target values |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
184 loaded_df : dict |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
185 Contains loaded DataFrame objects with file path as keys |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
186 ref_seq : str |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
187 File path to dataset containing genome sequence file |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
188 interval : str |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
189 File path to dataset containing interval file |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
190 targets : str |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
191 File path to dataset compressed target bed file |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
192 fasta_path : str |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
193 File path to dataset containing fasta file |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
194 |
13
fbc38059bb8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
12
diff
changeset
|
195 |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
196 Returns |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
197 ------- |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
198 estimator : estimator object after setting new attributes |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
199 X : numpy array |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
200 y : numpy array |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
201 """ |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
202 estimator_params = estimator.get_params() |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
203 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
204 input_type = params["input_options"]["selected_input"] |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
205 # tabular input |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
206 if input_type == "tabular": |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
207 header = "infer" if params["input_options"]["header1"] else None |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
208 column_option = params["input_options"]["column_selector_options_1"]["selected_column_selector_option"] |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
209 if column_option in [ |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
210 "by_index_number", |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
211 "all_but_by_index_number", |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
212 "by_header_name", |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
213 "all_but_by_header_name", |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
214 ]: |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
215 c = params["input_options"]["column_selector_options_1"]["col1"] |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
216 else: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
217 c = None |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
218 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
219 df_key = infile1 + repr(header) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
220 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
221 if df_key in loaded_df: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
222 infile1 = loaded_df[df_key] |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
223 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
224 df = pd.read_csv(infile1, sep="\t", header=header, parse_dates=True) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
225 loaded_df[df_key] = df |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
226 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
227 X = read_columns(df, c=c, c_option=column_option).astype(float) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
228 # sparse input |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
229 elif input_type == "sparse": |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
230 X = mmread(open(infile1, "r")) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
231 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
232 # fasta_file input |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
233 elif input_type == "seq_fasta": |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
234 pyfaidx = get_module("pyfaidx") |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
235 sequences = pyfaidx.Fasta(fasta_path) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
236 n_seqs = len(sequences.keys()) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
237 X = np.arange(n_seqs)[:, np.newaxis] |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
238 for param in estimator_params.keys(): |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
239 if param.endswith("fasta_path"): |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
240 estimator.set_params(**{param: fasta_path}) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
241 break |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
242 else: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
243 raise ValueError( |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
244 "The selected estimator doesn't support " |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
245 "fasta file input! Please consider using " |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
246 "KerasGBatchClassifier with " |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
247 "FastaDNABatchGenerator/FastaProteinBatchGenerator " |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
248 "or having GenomeOneHotEncoder/ProteinOneHotEncoder " |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
249 "in pipeline!" |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
250 ) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
251 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
252 elif input_type == "refseq_and_interval": |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
253 path_params = { |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
254 "data_batch_generator__ref_genome_path": ref_seq, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
255 "data_batch_generator__intervals_path": intervals, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
256 "data_batch_generator__target_path": targets, |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
257 } |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
258 estimator.set_params(**path_params) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
259 n_intervals = sum(1 for line in open(intervals)) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
260 X = np.arange(n_intervals)[:, np.newaxis] |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
261 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
262 # Get target y |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
263 header = "infer" if params["input_options"]["header2"] else None |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
264 column_option = params["input_options"]["column_selector_options_2"]["selected_column_selector_option2"] |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
265 if column_option in [ |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
266 "by_index_number", |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
267 "all_but_by_index_number", |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
268 "by_header_name", |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
269 "all_but_by_header_name", |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
270 ]: |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
271 c = params["input_options"]["column_selector_options_2"]["col2"] |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
272 else: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
273 c = None |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
274 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
275 df_key = infile2 + repr(header) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
276 if df_key in loaded_df: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
277 infile2 = loaded_df[df_key] |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
278 else: |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
279 infile2 = pd.read_csv(infile2, sep="\t", header=header, parse_dates=True) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
280 loaded_df[df_key] = infile2 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
281 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
282 y = read_columns(infile2, c=c, c_option=column_option, sep="\t", header=header, parse_dates=True) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
283 if len(y.shape) == 2 and y.shape[1] == 1: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
284 y = y.ravel() |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
285 if input_type == "refseq_and_interval": |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
286 estimator.set_params(data_batch_generator__features=y.ravel().tolist()) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
287 y = None |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
288 # end y |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
289 |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
290 return estimator, X, y |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
291 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
292 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
293 def _do_outer_cv(searcher, X, y, outer_cv, scoring, error_score="raise", outfile=None): |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
294 """Do outer cross-validation for nested CV |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
295 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
296 Parameters |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
297 ---------- |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
298 searcher : object |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
299 SearchCV object |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
300 X : numpy array |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
301 Containing features |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
302 y : numpy array |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
303 Target values or labels |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
304 outer_cv : int or CV splitter |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
305 Control the cv splitting |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
306 scoring : object |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
307 Scorer |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
308 error_score: str, float or numpy float |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
309 Whether to raise fit error or return an value |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
310 outfile : str |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
311 File path to store the restuls |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
312 """ |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
313 if error_score == "raise": |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
314 rval = cross_validate( |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
315 searcher, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
316 X, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
317 y, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
318 scoring=scoring, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
319 cv=outer_cv, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
320 n_jobs=N_JOBS, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
321 verbose=0, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
322 error_score=error_score, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
323 ) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
324 else: |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
325 warnings.simplefilter("always", FitFailedWarning) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
326 with warnings.catch_warnings(record=True) as w: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
327 try: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
328 rval = cross_validate( |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
329 searcher, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
330 X, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
331 y, |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
332 scoring=scoring, |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
333 cv=outer_cv, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
334 n_jobs=N_JOBS, |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
335 verbose=0, |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
336 error_score=error_score, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
337 ) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
338 except ValueError: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
339 pass |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
340 for warning in w: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
341 print(repr(warning.message)) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
342 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
343 keys = list(rval.keys()) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
344 for k in keys: |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
345 if k.startswith("test"): |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
346 rval["mean_" + k] = np.mean(rval[k]) |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
347 rval["std_" + k] = np.std(rval[k]) |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
348 if k.endswith("time"): |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
349 rval.pop(k) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
350 rval = pd.DataFrame(rval) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
351 rval = rval[sorted(rval.columns)] |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
352 rval.to_csv(path_or_buf=outfile, sep="\t", header=True, index=False) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
353 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
354 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
355 def _do_train_test_split_val( |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
356 searcher, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
357 X, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
358 y, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
359 params, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
360 error_score="raise", |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
361 primary_scoring=None, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
362 groups=None, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
363 outfile=None, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
364 ): |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
365 """do train test split, searchCV validates on the train and then use |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
366 the best_estimator_ to evaluate on the test |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
367 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
368 Returns |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
369 -------- |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
370 Fitted SearchCV object |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
371 """ |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
372 train_test_split = try_get_attr("galaxy_ml.model_validations", "train_test_split") |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
373 split_options = params["outer_split"] |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
374 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
375 # splits |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
376 if split_options["shuffle"] == "stratified": |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
377 split_options["labels"] = y |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
378 X, X_test, y, y_test = train_test_split(X, y, **split_options) |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
379 elif split_options["shuffle"] == "group": |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
380 if groups is None: |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
381 raise ValueError("No group based CV option was choosen for " "group shuffle!") |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
382 split_options["labels"] = groups |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
383 if y is None: |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
384 X, X_test, groups, _ = train_test_split(X, groups, **split_options) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
385 else: |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
386 X, X_test, y, y_test, groups, _ = train_test_split(X, y, groups, **split_options) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
387 else: |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
388 if split_options["shuffle"] == "None": |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
389 split_options["shuffle"] = None |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
390 X, X_test, y, y_test = train_test_split(X, y, **split_options) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
391 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
392 if error_score == "raise": |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
393 searcher.fit(X, y, groups=groups) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
394 else: |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
395 warnings.simplefilter("always", FitFailedWarning) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
396 with warnings.catch_warnings(record=True) as w: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
397 try: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
398 searcher.fit(X, y, groups=groups) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
399 except ValueError: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
400 pass |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
401 for warning in w: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
402 print(repr(warning.message)) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
403 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
404 scorer_ = searcher.scorer_ |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
405 if isinstance(scorer_, collections.Mapping): |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
406 is_multimetric = True |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
407 else: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
408 is_multimetric = False |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
409 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
410 best_estimator_ = getattr(searcher, "best_estimator_") |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
411 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
412 # TODO Solve deep learning models in pipeline |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
413 if best_estimator_.__class__.__name__ == "KerasGBatchClassifier": |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
414 test_score = best_estimator_.evaluate(X_test, scorer=scorer_, is_multimetric=is_multimetric) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
415 else: |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
416 test_score = _score(best_estimator_, X_test, y_test, scorer_, is_multimetric=is_multimetric) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
417 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
418 if not is_multimetric: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
419 test_score = {primary_scoring: test_score} |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
420 for key, value in test_score.items(): |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
421 test_score[key] = [value] |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
422 result_df = pd.DataFrame(test_score) |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
423 result_df.to_csv(path_or_buf=outfile, sep="\t", header=True, index=False) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
424 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
425 return searcher |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
426 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
427 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
428 def main( |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
429 inputs, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
430 infile_estimator, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
431 infile1, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
432 infile2, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
433 outfile_result, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
434 outfile_object=None, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
435 outfile_weights=None, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
436 groups=None, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
437 ref_seq=None, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
438 intervals=None, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
439 targets=None, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
440 fasta_path=None, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
441 ): |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
442 """ |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
443 Parameter |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
444 --------- |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
445 inputs : str |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
446 File path to galaxy tool parameter |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
447 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
448 infile_estimator : str |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
449 File path to estimator |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
450 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
451 infile1 : str |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
452 File path to dataset containing features |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
453 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
454 infile2 : str |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
455 File path to dataset containing target values |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
456 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
457 outfile_result : str |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
458 File path to save the results, either cv_results or test result |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
459 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
460 outfile_object : str, optional |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
461 File path to save searchCV object |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
462 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
463 outfile_weights : str, optional |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
464 File path to save model weights |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
465 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
466 groups : str |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
467 File path to dataset containing groups labels |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
468 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
469 ref_seq : str |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
470 File path to dataset containing genome sequence file |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
471 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
472 intervals : str |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
473 File path to dataset containing interval file |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
474 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
475 targets : str |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
476 File path to dataset compressed target bed file |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
477 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
478 fasta_path : str |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
479 File path to dataset containing fasta file |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
480 """ |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
481 warnings.simplefilter("ignore") |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
482 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
483 # store read dataframe object |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
484 loaded_df = {} |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
485 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
486 with open(inputs, "r") as param_handler: |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
487 params = json.load(param_handler) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
488 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
489 # Override the refit parameter |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
490 params["search_schemes"]["options"]["refit"] = True if params["save"] != "nope" else False |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
491 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
492 with open(infile_estimator, "rb") as estimator_handler: |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
493 estimator = load_model(estimator_handler) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
494 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
495 optimizer = params["search_schemes"]["selected_search_scheme"] |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
496 optimizer = getattr(model_selection, optimizer) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
497 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
498 # handle gridsearchcv options |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
499 options = params["search_schemes"]["options"] |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
500 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
501 if groups: |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
502 header = "infer" if (options["cv_selector"]["groups_selector"]["header_g"]) else None |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
503 column_option = options["cv_selector"]["groups_selector"]["column_selector_options_g"][ |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
504 "selected_column_selector_option_g" |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
505 ] |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
506 if column_option in [ |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
507 "by_index_number", |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
508 "all_but_by_index_number", |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
509 "by_header_name", |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
510 "all_but_by_header_name", |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
511 ]: |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
512 c = options["cv_selector"]["groups_selector"]["column_selector_options_g"]["col_g"] |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
513 else: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
514 c = None |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
515 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
516 df_key = groups + repr(header) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
517 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
518 groups = pd.read_csv(groups, sep="\t", header=header, parse_dates=True) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
519 loaded_df[df_key] = groups |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
520 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
521 groups = read_columns( |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
522 groups, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
523 c=c, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
524 c_option=column_option, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
525 sep="\t", |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
526 header=header, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
527 parse_dates=True, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
528 ) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
529 groups = groups.ravel() |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
530 options["cv_selector"]["groups_selector"] = groups |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
531 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
532 splitter, groups = get_cv(options.pop("cv_selector")) |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
533 options["cv"] = splitter |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
534 primary_scoring = options["scoring"]["primary_scoring"] |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
535 # get_scoring() expects secondary_scoring to be a comma separated string (not a list) |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
536 # Check if secondary_scoring is specified |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
537 secondary_scoring = options["scoring"].get("secondary_scoring", None) |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
538 if secondary_scoring is not None: |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
539 # If secondary_scoring is specified, convert the list into comman separated string |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
540 options["scoring"]["secondary_scoring"] = ",".join(options["scoring"]["secondary_scoring"]) |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
541 options["scoring"] = get_scoring(options["scoring"]) |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
542 if options["error_score"]: |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
543 options["error_score"] = "raise" |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
544 else: |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
545 options["error_score"] = np.NaN |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
546 if options["refit"] and isinstance(options["scoring"], dict): |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
547 options["refit"] = primary_scoring |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
548 if "pre_dispatch" in options and options["pre_dispatch"] == "": |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
549 options["pre_dispatch"] = None |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
550 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
551 params_builder = params["search_schemes"]["search_params_builder"] |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
552 param_grid = _eval_search_params(params_builder) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
553 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
554 estimator = clean_params(estimator) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
555 |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
556 # save the SearchCV object without fit |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
557 if params["save"] == "save_no_fit": |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
558 searcher = optimizer(estimator, param_grid, **options) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
559 print(searcher) |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
560 with open(outfile_object, "wb") as output_handler: |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
561 pickle.dump(searcher, output_handler, pickle.HIGHEST_PROTOCOL) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
562 return 0 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
563 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
564 # read inputs and loads new attributes, like paths |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
565 estimator, X, y = _handle_X_y( |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
566 estimator, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
567 params, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
568 infile1, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
569 infile2, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
570 loaded_df=loaded_df, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
571 ref_seq=ref_seq, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
572 intervals=intervals, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
573 targets=targets, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
574 fasta_path=fasta_path, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
575 ) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
576 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
577 # cache iraps_core fits could increase search speed significantly |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
578 memory = joblib.Memory(location=CACHE_DIR, verbose=0) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
579 main_est = get_main_estimator(estimator) |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
580 if main_est.__class__.__name__ == "IRAPSClassifier": |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
581 main_est.set_params(memory=memory) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
582 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
583 searcher = optimizer(estimator, param_grid, **options) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
584 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
585 split_mode = params["outer_split"].pop("split_mode") |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
586 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
587 if split_mode == "nested_cv": |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
588 # make sure refit is choosen |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
589 # this could be True for sklearn models, but not the case for |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
590 # deep learning models |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
591 if not options["refit"] and not all(hasattr(estimator, attr) for attr in ("config", "model_type")): |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
592 warnings.warn("Refit is change to `True` for nested validation!") |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
593 setattr(searcher, "refit", True) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
594 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
595 outer_cv, _ = get_cv(params["outer_split"]["cv_selector"]) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
596 # nested CV, outer cv using cross_validate |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
597 if options["error_score"] == "raise": |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
598 rval = cross_validate( |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
599 searcher, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
600 X, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
601 y, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
602 scoring=options["scoring"], |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
603 cv=outer_cv, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
604 n_jobs=N_JOBS, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
605 verbose=options["verbose"], |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
606 return_estimator=(params["save"] == "save_estimator"), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
607 error_score=options["error_score"], |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
608 return_train_score=True, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
609 ) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
610 else: |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
611 warnings.simplefilter("always", FitFailedWarning) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
612 with warnings.catch_warnings(record=True) as w: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
613 try: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
614 rval = cross_validate( |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
615 searcher, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
616 X, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
617 y, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
618 scoring=options["scoring"], |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
619 cv=outer_cv, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
620 n_jobs=N_JOBS, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
621 verbose=options["verbose"], |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
622 return_estimator=(params["save"] == "save_estimator"), |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
623 error_score=options["error_score"], |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
624 return_train_score=True, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
625 ) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
626 except ValueError: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
627 pass |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
628 for warning in w: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
629 print(repr(warning.message)) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
630 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
631 fitted_searchers = rval.pop("estimator", []) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
632 if fitted_searchers: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
633 import os |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
634 |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
635 pwd = os.getcwd() |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
636 save_dir = os.path.join(pwd, "cv_results_in_folds") |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
637 try: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
638 os.mkdir(save_dir) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
639 for idx, obj in enumerate(fitted_searchers): |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
640 target_name = "cv_results_" + "_" + "split%d" % idx |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
641 target_path = os.path.join(pwd, save_dir, target_name) |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
642 cv_results_ = getattr(obj, "cv_results_", None) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
643 if not cv_results_: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
644 print("%s is not available" % target_name) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
645 continue |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
646 cv_results_ = pd.DataFrame(cv_results_) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
647 cv_results_ = cv_results_[sorted(cv_results_.columns)] |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
648 cv_results_.to_csv(target_path, sep="\t", header=True, index=False) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
649 except Exception as e: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
650 print(e) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
651 finally: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
652 del os |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
653 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
654 keys = list(rval.keys()) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
655 for k in keys: |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
656 if k.startswith("test"): |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
657 rval["mean_" + k] = np.mean(rval[k]) |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
658 rval["std_" + k] = np.std(rval[k]) |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
659 if k.endswith("time"): |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
660 rval.pop(k) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
661 rval = pd.DataFrame(rval) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
662 rval = rval[sorted(rval.columns)] |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
663 rval.to_csv(path_or_buf=outfile_result, sep="\t", header=True, index=False) |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
664 # deprecate train test split mode |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
665 """searcher = _do_train_test_split_val( |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
666 searcher, X, y, params, |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
667 primary_scoring=primary_scoring, |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
668 error_score=options['error_score'], |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
669 groups=groups, |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
670 outfile=outfile_result)""" |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
671 return 0 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
672 |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
673 # no outer split |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
674 else: |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
675 searcher.set_params(n_jobs=N_JOBS) |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
676 if options["error_score"] == "raise": |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
677 searcher.fit(X, y, groups=groups) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
678 else: |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
679 warnings.simplefilter("always", FitFailedWarning) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
680 with warnings.catch_warnings(record=True) as w: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
681 try: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
682 searcher.fit(X, y, groups=groups) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
683 except ValueError: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
684 pass |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
685 for warning in w: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
686 print(repr(warning.message)) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
687 |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
688 cv_results = pd.DataFrame(searcher.cv_results_) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
689 cv_results = cv_results[sorted(cv_results.columns)] |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
690 cv_results.to_csv(path_or_buf=outfile_result, sep="\t", header=True, index=False) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
691 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
692 memory.clear(warn=False) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
693 |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
694 # output best estimator, and weights if applicable |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
695 if outfile_object: |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
696 best_estimator_ = getattr(searcher, "best_estimator_", None) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
697 if not best_estimator_: |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
698 warnings.warn( |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
699 "GridSearchCV object has no attribute " |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
700 "'best_estimator_', because either it's " |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
701 "nested gridsearch or `refit` is False!" |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
702 ) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
703 return |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
704 |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
705 # clean prams |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
706 best_estimator_ = clean_params(best_estimator_) |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
707 |
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
708 main_est = get_main_estimator(best_estimator_) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
709 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
710 if hasattr(main_est, "model_") and hasattr(main_est, "save_weights"): |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
711 if outfile_weights: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
712 main_est.save_weights(outfile_weights) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
713 del main_est.model_ |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
714 del main_est.fit_params |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
715 del main_est.model_class_ |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
716 del main_est.validation_data |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
717 if getattr(main_est, "data_generator_", None): |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
718 del main_est.data_generator_ |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
719 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
720 with open(outfile_object, "wb") as output_handler: |
17
699024d5c451
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents:
13
diff
changeset
|
721 print("Best estimator is saved: %s " % repr(best_estimator_)) |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
722 pickle.dump(best_estimator_, output_handler, pickle.HIGHEST_PROTOCOL) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
723 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
724 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
725 if __name__ == "__main__": |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
726 aparser = argparse.ArgumentParser() |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
727 aparser.add_argument("-i", "--inputs", dest="inputs", required=True) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
728 aparser.add_argument("-e", "--estimator", dest="infile_estimator") |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
729 aparser.add_argument("-X", "--infile1", dest="infile1") |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
730 aparser.add_argument("-y", "--infile2", dest="infile2") |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
731 aparser.add_argument("-O", "--outfile_result", dest="outfile_result") |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
732 aparser.add_argument("-o", "--outfile_object", dest="outfile_object") |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
733 aparser.add_argument("-w", "--outfile_weights", dest="outfile_weights") |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
734 aparser.add_argument("-g", "--groups", dest="groups") |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
735 aparser.add_argument("-r", "--ref_seq", dest="ref_seq") |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
736 aparser.add_argument("-b", "--intervals", dest="intervals") |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
737 aparser.add_argument("-t", "--targets", dest="targets") |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
738 aparser.add_argument("-f", "--fasta_path", dest="fasta_path") |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
739 args = aparser.parse_args() |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
740 |
21
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
741 main( |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
742 args.inputs, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
743 args.infile_estimator, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
744 args.infile1, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
745 args.infile2, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
746 args.outfile_result, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
747 outfile_object=args.outfile_object, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
748 outfile_weights=args.outfile_weights, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
749 groups=args.groups, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
750 ref_seq=args.ref_seq, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
751 intervals=args.intervals, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
752 targets=args.targets, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
753 fasta_path=args.fasta_path, |
1d3447c2203c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents:
17
diff
changeset
|
754 ) |