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