Mercurial > repos > bgruening > sklearn_nn_classifier
annotate search_model_validation.py @ 15:fa2d8618bab0 draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit eb703290e2589561ea215c84aa9f71bcfe1712c6"
author | bgruening |
---|---|
date | Fri, 01 Nov 2019 17:24:58 -0400 |
parents | fbc38059bb8f |
children | 699024d5c451 |
rev | line source |
---|---|
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
1 import argparse |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
2 import collections |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
3 import imblearn |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
4 import joblib |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
5 import json |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
6 import numpy as np |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
7 import pandas as pd |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
8 import pickle |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
9 import skrebate |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
10 import sklearn |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
11 import sys |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
12 import xgboost |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
13 import warnings |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
14 from imblearn import under_sampling, over_sampling, combine |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
15 from scipy.io import mmread |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
16 from mlxtend import classifier, regressor |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
17 from sklearn.base import clone |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
18 from sklearn import (cluster, compose, decomposition, ensemble, |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
19 feature_extraction, feature_selection, |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
20 gaussian_process, kernel_approximation, metrics, |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
21 model_selection, naive_bayes, neighbors, |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
22 pipeline, preprocessing, svm, linear_model, |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
23 tree, discriminant_analysis) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
24 from sklearn.exceptions import FitFailedWarning |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
25 from sklearn.model_selection._validation import _score, cross_validate |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
26 from sklearn.model_selection import _search, _validation |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
27 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
28 from galaxy_ml.utils import (SafeEval, get_cv, get_scoring, load_model, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
29 read_columns, try_get_attr, get_module) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
30 |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
31 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
32 _fit_and_score = try_get_attr('galaxy_ml.model_validations', '_fit_and_score') |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
33 setattr(_search, '_fit_and_score', _fit_and_score) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
34 setattr(_validation, '_fit_and_score', _fit_and_score) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
35 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
36 N_JOBS = int(__import__('os').environ.get('GALAXY_SLOTS', 1)) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
37 CACHE_DIR = './cached' |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
38 NON_SEARCHABLE = ('n_jobs', 'pre_dispatch', 'memory', '_path', |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
39 'nthread', 'callbacks') |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
40 ALLOWED_CALLBACKS = ('EarlyStopping', 'TerminateOnNaN', 'ReduceLROnPlateau', |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
41 'CSVLogger', 'None') |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
42 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
43 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
44 def _eval_search_params(params_builder): |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
45 search_params = {} |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
46 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
47 for p in params_builder['param_set']: |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
48 search_list = p['sp_list'].strip() |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
49 if search_list == '': |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
50 continue |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
51 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
52 param_name = p['sp_name'] |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
53 if param_name.lower().endswith(NON_SEARCHABLE): |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
54 print("Warning: `%s` is not eligible for search and was " |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
55 "omitted!" % param_name) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
56 continue |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
57 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
58 if not search_list.startswith(':'): |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
59 safe_eval = SafeEval(load_scipy=True, load_numpy=True) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
60 ev = safe_eval(search_list) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
61 search_params[param_name] = ev |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
62 else: |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
63 # Have `:` before search list, asks for estimator evaluatio |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
64 safe_eval_es = SafeEval(load_estimators=True) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
65 search_list = search_list[1:].strip() |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
66 # TODO maybe add regular express check |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
67 ev = safe_eval_es(search_list) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
68 preprocessings = ( |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
69 preprocessing.StandardScaler(), preprocessing.Binarizer(), |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
70 preprocessing.MaxAbsScaler(), |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
71 preprocessing.Normalizer(), preprocessing.MinMaxScaler(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
72 preprocessing.PolynomialFeatures(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
73 preprocessing.RobustScaler(), feature_selection.SelectKBest(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
74 feature_selection.GenericUnivariateSelect(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
75 feature_selection.SelectPercentile(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
76 feature_selection.SelectFpr(), feature_selection.SelectFdr(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
77 feature_selection.SelectFwe(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
78 feature_selection.VarianceThreshold(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
79 decomposition.FactorAnalysis(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
80 decomposition.FastICA(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
81 decomposition.IncrementalPCA(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
82 decomposition.KernelPCA(random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
83 decomposition.LatentDirichletAllocation( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
84 random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
85 decomposition.MiniBatchDictionaryLearning( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
86 random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
87 decomposition.MiniBatchSparsePCA( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
88 random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
89 decomposition.NMF(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
90 decomposition.PCA(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
91 decomposition.SparsePCA(random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
92 decomposition.TruncatedSVD(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
93 kernel_approximation.Nystroem(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
94 kernel_approximation.RBFSampler(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
95 kernel_approximation.AdditiveChi2Sampler(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
96 kernel_approximation.SkewedChi2Sampler(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
97 cluster.FeatureAgglomeration(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
98 skrebate.ReliefF(n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
99 skrebate.SURF(n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
100 skrebate.SURFstar(n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
101 skrebate.MultiSURF(n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
102 skrebate.MultiSURFstar(n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
103 imblearn.under_sampling.ClusterCentroids( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
104 random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
105 imblearn.under_sampling.CondensedNearestNeighbour( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
106 random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
107 imblearn.under_sampling.EditedNearestNeighbours( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
108 random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
109 imblearn.under_sampling.RepeatedEditedNearestNeighbours( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
110 random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
111 imblearn.under_sampling.AllKNN(random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
112 imblearn.under_sampling.InstanceHardnessThreshold( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
113 random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
114 imblearn.under_sampling.NearMiss( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
115 random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
116 imblearn.under_sampling.NeighbourhoodCleaningRule( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
117 random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
118 imblearn.under_sampling.OneSidedSelection( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
119 random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
120 imblearn.under_sampling.RandomUnderSampler( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
121 random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
122 imblearn.under_sampling.TomekLinks( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
123 random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
124 imblearn.over_sampling.ADASYN(random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
125 imblearn.over_sampling.RandomOverSampler(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
126 imblearn.over_sampling.SMOTE(random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
127 imblearn.over_sampling.SVMSMOTE(random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
128 imblearn.over_sampling.BorderlineSMOTE( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
129 random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
130 imblearn.over_sampling.SMOTENC( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
131 categorical_features=[], random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
132 imblearn.combine.SMOTEENN(random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
133 imblearn.combine.SMOTETomek(random_state=0)) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
134 newlist = [] |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
135 for obj in ev: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
136 if obj is None: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
137 newlist.append(None) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
138 elif obj == 'all_0': |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
139 newlist.extend(preprocessings[0:35]) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
140 elif obj == 'sk_prep_all': # no KernalCenter() |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
141 newlist.extend(preprocessings[0:7]) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
142 elif obj == 'fs_all': |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
143 newlist.extend(preprocessings[7:14]) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
144 elif obj == 'decomp_all': |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
145 newlist.extend(preprocessings[14:25]) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
146 elif obj == 'k_appr_all': |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
147 newlist.extend(preprocessings[25:29]) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
148 elif obj == 'reb_all': |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
149 newlist.extend(preprocessings[30:35]) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
150 elif obj == 'imb_all': |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
151 newlist.extend(preprocessings[35:54]) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
152 elif type(obj) is int and -1 < obj < len(preprocessings): |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
153 newlist.append(preprocessings[obj]) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
154 elif hasattr(obj, 'get_params'): # user uploaded object |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
155 if 'n_jobs' in obj.get_params(): |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
156 newlist.append(obj.set_params(n_jobs=N_JOBS)) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
157 else: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
158 newlist.append(obj) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
159 else: |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
160 sys.exit("Unsupported estimator type: %r" % (obj)) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
161 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
162 search_params[param_name] = newlist |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
163 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
164 return search_params |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
165 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
166 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
167 def main(inputs, infile_estimator, infile1, infile2, |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
168 outfile_result, outfile_object=None, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
169 outfile_weights=None, groups=None, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
170 ref_seq=None, intervals=None, targets=None, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
171 fasta_path=None): |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
172 """ |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
173 Parameter |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
174 --------- |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
175 inputs : str |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
176 File path to galaxy tool parameter |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
177 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
178 infile_estimator : str |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
179 File path to estimator |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
180 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
181 infile1 : str |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
182 File path to dataset containing features |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
183 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
184 infile2 : str |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
185 File path to dataset containing target values |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
186 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
187 outfile_result : str |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
188 File path to save the results, either cv_results or test result |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
189 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
190 outfile_object : str, optional |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
191 File path to save searchCV object |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
192 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
193 outfile_weights : str, optional |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
194 File path to save model weights |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
195 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
196 groups : str |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
197 File path to dataset containing groups labels |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
198 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
199 ref_seq : str |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
200 File path to dataset containing genome sequence file |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
201 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
202 intervals : str |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
203 File path to dataset containing interval file |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
204 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
205 targets : str |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
206 File path to dataset compressed target bed file |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
207 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
208 fasta_path : str |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
209 File path to dataset containing fasta file |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
210 """ |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
211 warnings.simplefilter('ignore') |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
212 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
213 with open(inputs, 'r') as param_handler: |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
214 params = json.load(param_handler) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
215 |
13
fbc38059bb8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
12
diff
changeset
|
216 # conflict param checker |
fbc38059bb8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
12
diff
changeset
|
217 if params['outer_split']['split_mode'] == 'nested_cv' \ |
fbc38059bb8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
12
diff
changeset
|
218 and params['save'] != 'nope': |
fbc38059bb8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
12
diff
changeset
|
219 raise ValueError("Save best estimator is not possible for nested CV!") |
fbc38059bb8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
12
diff
changeset
|
220 |
fbc38059bb8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
12
diff
changeset
|
221 if not (params['search_schemes']['options']['refit']) \ |
fbc38059bb8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
12
diff
changeset
|
222 and params['save'] != 'nope': |
fbc38059bb8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
12
diff
changeset
|
223 raise ValueError("Save best estimator is not possible when refit " |
fbc38059bb8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
12
diff
changeset
|
224 "is False!") |
fbc38059bb8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents:
12
diff
changeset
|
225 |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
226 params_builder = params['search_schemes']['search_params_builder'] |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
227 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
228 with open(infile_estimator, 'rb') as estimator_handler: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
229 estimator = load_model(estimator_handler) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
230 estimator_params = estimator.get_params() |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
231 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
232 # store read dataframe object |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
233 loaded_df = {} |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
234 |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
235 input_type = params['input_options']['selected_input'] |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
236 # tabular input |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
237 if input_type == 'tabular': |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
238 header = 'infer' if params['input_options']['header1'] else None |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
239 column_option = (params['input_options']['column_selector_options_1'] |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
240 ['selected_column_selector_option']) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
241 if column_option in ['by_index_number', 'all_but_by_index_number', |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
242 'by_header_name', 'all_but_by_header_name']: |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
243 c = params['input_options']['column_selector_options_1']['col1'] |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
244 else: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
245 c = None |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
246 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
247 df_key = infile1 + repr(header) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
248 df = pd.read_csv(infile1, sep='\t', header=header, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
249 parse_dates=True) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
250 loaded_df[df_key] = df |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
251 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
252 X = read_columns(df, c=c, c_option=column_option).astype(float) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
253 # sparse input |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
254 elif input_type == 'sparse': |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
255 X = mmread(open(infile1, 'r')) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
256 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
257 # fasta_file input |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
258 elif input_type == 'seq_fasta': |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
259 pyfaidx = get_module('pyfaidx') |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
260 sequences = pyfaidx.Fasta(fasta_path) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
261 n_seqs = len(sequences.keys()) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
262 X = np.arange(n_seqs)[:, np.newaxis] |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
263 for param in estimator_params.keys(): |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
264 if param.endswith('fasta_path'): |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
265 estimator.set_params( |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
266 **{param: fasta_path}) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
267 break |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
268 else: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
269 raise ValueError( |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
270 "The selected estimator doesn't support " |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
271 "fasta file input! Please consider using " |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
272 "KerasGBatchClassifier with " |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
273 "FastaDNABatchGenerator/FastaProteinBatchGenerator " |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
274 "or having GenomeOneHotEncoder/ProteinOneHotEncoder " |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
275 "in pipeline!") |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
276 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
277 elif input_type == 'refseq_and_interval': |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
278 path_params = { |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
279 'data_batch_generator__ref_genome_path': ref_seq, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
280 'data_batch_generator__intervals_path': intervals, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
281 'data_batch_generator__target_path': targets |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
282 } |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
283 estimator.set_params(**path_params) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
284 n_intervals = sum(1 for line in open(intervals)) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
285 X = np.arange(n_intervals)[:, np.newaxis] |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
286 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
287 # Get target y |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
288 header = 'infer' if params['input_options']['header2'] else None |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
289 column_option = (params['input_options']['column_selector_options_2'] |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
290 ['selected_column_selector_option2']) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
291 if column_option in ['by_index_number', 'all_but_by_index_number', |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
292 'by_header_name', 'all_but_by_header_name']: |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
293 c = params['input_options']['column_selector_options_2']['col2'] |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
294 else: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
295 c = None |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
296 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
297 df_key = infile2 + repr(header) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
298 if df_key in loaded_df: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
299 infile2 = loaded_df[df_key] |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
300 else: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
301 infile2 = pd.read_csv(infile2, sep='\t', |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
302 header=header, parse_dates=True) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
303 loaded_df[df_key] = infile2 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
304 |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
305 y = read_columns( |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
306 infile2, |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
307 c=c, |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
308 c_option=column_option, |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
309 sep='\t', |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
310 header=header, |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
311 parse_dates=True) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
312 if len(y.shape) == 2 and y.shape[1] == 1: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
313 y = y.ravel() |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
314 if input_type == 'refseq_and_interval': |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
315 estimator.set_params( |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
316 data_batch_generator__features=y.ravel().tolist()) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
317 y = None |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
318 # end y |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
319 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
320 optimizer = params['search_schemes']['selected_search_scheme'] |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
321 optimizer = getattr(model_selection, optimizer) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
322 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
323 # handle gridsearchcv options |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
324 options = params['search_schemes']['options'] |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
325 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
326 if groups: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
327 header = 'infer' if (options['cv_selector']['groups_selector'] |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
328 ['header_g']) else None |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
329 column_option = (options['cv_selector']['groups_selector'] |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
330 ['column_selector_options_g'] |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
331 ['selected_column_selector_option_g']) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
332 if column_option in ['by_index_number', 'all_but_by_index_number', |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
333 'by_header_name', 'all_but_by_header_name']: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
334 c = (options['cv_selector']['groups_selector'] |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
335 ['column_selector_options_g']['col_g']) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
336 else: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
337 c = None |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
338 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
339 df_key = groups + repr(header) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
340 if df_key in loaded_df: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
341 groups = loaded_df[df_key] |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
342 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
343 groups = read_columns( |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
344 groups, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
345 c=c, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
346 c_option=column_option, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
347 sep='\t', |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
348 header=header, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
349 parse_dates=True) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
350 groups = groups.ravel() |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
351 options['cv_selector']['groups_selector'] = groups |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
352 |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
353 splitter, groups = get_cv(options.pop('cv_selector')) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
354 options['cv'] = splitter |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
355 options['n_jobs'] = N_JOBS |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
356 primary_scoring = options['scoring']['primary_scoring'] |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
357 options['scoring'] = get_scoring(options['scoring']) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
358 if options['error_score']: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
359 options['error_score'] = 'raise' |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
360 else: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
361 options['error_score'] = np.NaN |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
362 if options['refit'] and isinstance(options['scoring'], dict): |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
363 options['refit'] = primary_scoring |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
364 if 'pre_dispatch' in options and options['pre_dispatch'] == '': |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
365 options['pre_dispatch'] = None |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
366 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
367 # del loaded_df |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
368 del loaded_df |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
369 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
370 # handle memory |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
371 memory = joblib.Memory(location=CACHE_DIR, verbose=0) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
372 # cache iraps_core fits could increase search speed significantly |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
373 if estimator.__class__.__name__ == 'IRAPSClassifier': |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
374 estimator.set_params(memory=memory) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
375 else: |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
376 # For iraps buried in pipeline |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
377 for p, v in estimator_params.items(): |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
378 if p.endswith('memory'): |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
379 # for case of `__irapsclassifier__memory` |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
380 if len(p) > 8 and p[:-8].endswith('irapsclassifier'): |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
381 # cache iraps_core fits could increase search |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
382 # speed significantly |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
383 new_params = {p: memory} |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
384 estimator.set_params(**new_params) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
385 # security reason, we don't want memory being |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
386 # modified unexpectedly |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
387 elif v: |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
388 new_params = {p, None} |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
389 estimator.set_params(**new_params) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
390 # For now, 1 CPU is suggested for iprasclassifier |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
391 elif p.endswith('n_jobs'): |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
392 new_params = {p: 1} |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
393 estimator.set_params(**new_params) |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
394 # for security reason, types of callbacks are limited |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
395 elif p.endswith('callbacks'): |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
396 for cb in v: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
397 cb_type = cb['callback_selection']['callback_type'] |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
398 if cb_type not in ALLOWED_CALLBACKS: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
399 raise ValueError( |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
400 "Prohibited callback type: %s!" % cb_type) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
401 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
402 param_grid = _eval_search_params(params_builder) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
403 searcher = optimizer(estimator, param_grid, **options) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
404 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
405 # do nested split |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
406 split_mode = params['outer_split'].pop('split_mode') |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
407 # nested CV, outer cv using cross_validate |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
408 if split_mode == 'nested_cv': |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
409 outer_cv, _ = get_cv(params['outer_split']['cv_selector']) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
410 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
411 if options['error_score'] == 'raise': |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
412 rval = cross_validate( |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
413 searcher, X, y, scoring=options['scoring'], |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
414 cv=outer_cv, n_jobs=N_JOBS, verbose=0, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
415 error_score=options['error_score']) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
416 else: |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
417 warnings.simplefilter('always', FitFailedWarning) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
418 with warnings.catch_warnings(record=True) as w: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
419 try: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
420 rval = cross_validate( |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
421 searcher, X, y, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
422 scoring=options['scoring'], |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
423 cv=outer_cv, n_jobs=N_JOBS, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
424 verbose=0, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
425 error_score=options['error_score']) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
426 except ValueError: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
427 pass |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
428 for warning in w: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
429 print(repr(warning.message)) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
430 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
431 keys = list(rval.keys()) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
432 for k in keys: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
433 if k.startswith('test'): |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
434 rval['mean_' + k] = np.mean(rval[k]) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
435 rval['std_' + k] = np.std(rval[k]) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
436 if k.endswith('time'): |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
437 rval.pop(k) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
438 rval = pd.DataFrame(rval) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
439 rval = rval[sorted(rval.columns)] |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
440 rval.to_csv(path_or_buf=outfile_result, sep='\t', |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
441 header=True, index=False) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
442 else: |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
443 if split_mode == 'train_test_split': |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
444 train_test_split = try_get_attr( |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
445 'galaxy_ml.model_validations', 'train_test_split') |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
446 # make sure refit is choosen |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
447 # this could be True for sklearn models, but not the case for |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
448 # deep learning models |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
449 if not options['refit'] and \ |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
450 not all(hasattr(estimator, attr) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
451 for attr in ('config', 'model_type')): |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
452 warnings.warn("Refit is change to `True` for nested " |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
453 "validation!") |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
454 setattr(searcher, 'refit', True) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
455 split_options = params['outer_split'] |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
456 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
457 # splits |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
458 if split_options['shuffle'] == 'stratified': |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
459 split_options['labels'] = y |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
460 X, X_test, y, y_test = train_test_split(X, y, **split_options) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
461 elif split_options['shuffle'] == 'group': |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
462 if groups is None: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
463 raise ValueError("No group based CV option was " |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
464 "choosen for group shuffle!") |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
465 split_options['labels'] = groups |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
466 if y is None: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
467 X, X_test, groups, _ =\ |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
468 train_test_split(X, groups, **split_options) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
469 else: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
470 X, X_test, y, y_test, groups, _ =\ |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
471 train_test_split(X, y, groups, **split_options) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
472 else: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
473 if split_options['shuffle'] == 'None': |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
474 split_options['shuffle'] = None |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
475 X, X_test, y, y_test =\ |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
476 train_test_split(X, y, **split_options) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
477 # end train_test_split |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
478 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
479 # shared by both train_test_split and non-split |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
480 if options['error_score'] == 'raise': |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
481 searcher.fit(X, y, groups=groups) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
482 else: |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
483 warnings.simplefilter('always', FitFailedWarning) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
484 with warnings.catch_warnings(record=True) as w: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
485 try: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
486 searcher.fit(X, y, groups=groups) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
487 except ValueError: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
488 pass |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
489 for warning in w: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
490 print(repr(warning.message)) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
491 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
492 # no outer split |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
493 if split_mode == 'no': |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
494 # save results |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
495 cv_results = pd.DataFrame(searcher.cv_results_) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
496 cv_results = cv_results[sorted(cv_results.columns)] |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
497 cv_results.to_csv(path_or_buf=outfile_result, sep='\t', |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
498 header=True, index=False) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
499 |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
500 # train_test_split, output test result using best_estimator_ |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
501 # or rebuild the trained estimator using weights if applicable. |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
502 else: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
503 scorer_ = searcher.scorer_ |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
504 if isinstance(scorer_, collections.Mapping): |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
505 is_multimetric = True |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
506 else: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
507 is_multimetric = False |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
508 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
509 best_estimator_ = getattr(searcher, 'best_estimator_', None) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
510 if not best_estimator_: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
511 raise ValueError("GridSearchCV object has no " |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
512 "`best_estimator_` when `refit`=False!") |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
513 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
514 if best_estimator_.__class__.__name__ == 'KerasGBatchClassifier' \ |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
515 and hasattr(estimator.data_batch_generator, 'target_path'): |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
516 test_score = best_estimator_.evaluate( |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
517 X_test, scorer=scorer_, is_multimetric=is_multimetric) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
518 else: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
519 test_score = _score(best_estimator_, X_test, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
520 y_test, scorer_, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
521 is_multimetric=is_multimetric) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
522 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
523 if not is_multimetric: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
524 test_score = {primary_scoring: test_score} |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
525 for key, value in test_score.items(): |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
526 test_score[key] = [value] |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
527 result_df = pd.DataFrame(test_score) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
528 result_df.to_csv(path_or_buf=outfile_result, sep='\t', |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
529 header=True, index=False) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
530 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
531 memory.clear(warn=False) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
532 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
533 if outfile_object: |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
534 best_estimator_ = getattr(searcher, 'best_estimator_', None) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
535 if not best_estimator_: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
536 warnings.warn("GridSearchCV object has no attribute " |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
537 "'best_estimator_', because either it's " |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
538 "nested gridsearch or `refit` is False!") |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
539 return |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
540 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
541 main_est = best_estimator_ |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
542 if isinstance(best_estimator_, pipeline.Pipeline): |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
543 main_est = best_estimator_.steps[-1][-1] |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
544 |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
545 if hasattr(main_est, 'model_') \ |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
546 and hasattr(main_est, 'save_weights'): |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
547 if outfile_weights: |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
548 main_est.save_weights(outfile_weights) |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
549 del main_est.model_ |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
550 del main_est.fit_params |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
551 del main_est.model_class_ |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
552 del main_est.validation_data |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
553 if getattr(main_est, 'data_generator_', None): |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
554 del main_est.data_generator_ |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
555 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
556 with open(outfile_object, 'wb') as output_handler: |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
557 pickle.dump(best_estimator_, output_handler, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
558 pickle.HIGHEST_PROTOCOL) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
559 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
560 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
561 if __name__ == '__main__': |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
562 aparser = argparse.ArgumentParser() |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
563 aparser.add_argument("-i", "--inputs", dest="inputs", required=True) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
564 aparser.add_argument("-e", "--estimator", dest="infile_estimator") |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
565 aparser.add_argument("-X", "--infile1", dest="infile1") |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
566 aparser.add_argument("-y", "--infile2", dest="infile2") |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
567 aparser.add_argument("-O", "--outfile_result", dest="outfile_result") |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
568 aparser.add_argument("-o", "--outfile_object", dest="outfile_object") |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
569 aparser.add_argument("-w", "--outfile_weights", dest="outfile_weights") |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
570 aparser.add_argument("-g", "--groups", dest="groups") |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
571 aparser.add_argument("-r", "--ref_seq", dest="ref_seq") |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
572 aparser.add_argument("-b", "--intervals", dest="intervals") |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
573 aparser.add_argument("-t", "--targets", dest="targets") |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
574 aparser.add_argument("-f", "--fasta_path", dest="fasta_path") |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
575 args = aparser.parse_args() |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
576 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
577 main(args.inputs, args.infile_estimator, args.infile1, args.infile2, |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
578 args.outfile_result, outfile_object=args.outfile_object, |
12
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
579 outfile_weights=args.outfile_weights, groups=args.groups, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
580 ref_seq=args.ref_seq, intervals=args.intervals, |
d0efc68a3ddb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
10
diff
changeset
|
581 targets=args.targets, fasta_path=args.fasta_path) |