Mercurial > repos > bgruening > sklearn_nn_classifier
annotate search_model_validation.py @ 10:e9ba818e7877 draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
author | bgruening |
---|---|
date | Tue, 14 May 2019 18:09:43 -0400 |
parents | ed7b1654e841 |
children | d0efc68a3ddb |
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 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
4 import json |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
5 import numpy as np |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
6 import pandas |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
7 import pickle |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
8 import skrebate |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
9 import sklearn |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
10 import sys |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
11 import xgboost |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
12 import warnings |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
13 import iraps_classifier |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
14 import model_validations |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
15 import preprocessors |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
16 import feature_selectors |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
17 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
|
18 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
|
19 from mlxtend import classifier, regressor |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
20 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 tree, discriminant_analysis) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
26 from sklearn.exceptions import FitFailedWarning |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
27 from sklearn.externals import joblib |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
28 from sklearn.model_selection._validation import _score |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
29 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
30 from utils import (SafeEval, get_cv, get_scoring, get_X_y, |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
31 load_model, read_columns) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
32 from model_validations import train_test_split |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
33 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
34 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
35 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
|
36 CACHE_DIR = './cached' |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
37 NON_SEARCHABLE = ('n_jobs', 'pre_dispatch', 'memory', 'steps', |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
38 'nthread', 'verbose') |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
39 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
40 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
41 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
|
42 search_params = {} |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
43 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
44 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
|
45 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
|
46 if search_list == '': |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
47 continue |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
48 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
49 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
|
50 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
|
51 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
|
52 "omitted!" % param_name) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
53 continue |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
54 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 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
|
59 else: |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
60 # 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
|
61 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
|
62 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
|
63 # 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
|
64 ev = safe_eval_es(search_list) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
65 preprocessors = ( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
66 preprocessing.StandardScaler(), preprocessing.Binarizer(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
67 preprocessing.Imputer(), preprocessing.MaxAbsScaler(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
68 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
|
69 preprocessing.PolynomialFeatures(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
70 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
|
71 feature_selection.GenericUnivariateSelect(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
72 feature_selection.SelectPercentile(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
73 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
|
74 feature_selection.SelectFwe(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
75 feature_selection.VarianceThreshold(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
76 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
|
77 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
|
78 decomposition.IncrementalPCA(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
79 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
|
80 decomposition.LatentDirichletAllocation( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
81 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
|
82 decomposition.MiniBatchDictionaryLearning( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
83 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
|
84 decomposition.MiniBatchSparsePCA( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 kernel_approximation.AdditiveChi2Sampler(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
93 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
|
94 cluster.FeatureAgglomeration(), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
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.NearMiss( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 random_state=0), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
119 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
|
120 random_state=0, n_jobs=N_JOBS), |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
121 imblearn.over_sampling.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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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.SMOTENC( |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
128 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
|
129 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
|
130 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
|
131 newlist = [] |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
132 for obj in ev: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
133 if obj is None: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
134 newlist.append(None) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
135 elif obj == 'all_0': |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
136 newlist.extend(preprocessors[0:36]) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
137 elif obj == 'sk_prep_all': # no KernalCenter() |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
138 newlist.extend(preprocessors[0:8]) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
139 elif obj == 'fs_all': |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
140 newlist.extend(preprocessors[8:15]) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
141 elif obj == 'decomp_all': |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
142 newlist.extend(preprocessors[15:26]) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
143 elif obj == 'k_appr_all': |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
144 newlist.extend(preprocessors[26:30]) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
145 elif obj == 'reb_all': |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
146 newlist.extend(preprocessors[31:36]) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
147 elif obj == 'imb_all': |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
148 newlist.extend(preprocessors[36:55]) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
149 elif type(obj) is int and -1 < obj < len(preprocessors): |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
150 newlist.append(preprocessors[obj]) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
151 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
|
152 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
|
153 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
|
154 else: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
155 newlist.append(obj) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
156 else: |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
157 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
|
158 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
159 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
|
160 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
161 return search_params |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
162 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
163 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
164 def main(inputs, infile_estimator, infile1, infile2, |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
165 outfile_result, outfile_object=None, groups=None): |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
166 """ |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
167 Parameter |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
168 --------- |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
169 inputs : str |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
170 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
|
171 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
172 infile_estimator : str |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
173 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
|
174 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
175 infile1 : 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 dataset containing features |
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 infile2 : 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 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
|
180 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
181 outfile_result : 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 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
|
183 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
184 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
|
185 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
|
186 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
187 groups : 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 dataset containing groups labels |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
189 """ |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
190 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
191 warnings.simplefilter('ignore') |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
192 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
193 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
|
194 params = json.load(param_handler) |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
195 if groups: |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
196 (params['search_schemes']['options']['cv_selector'] |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
197 ['groups_selector']['infile_g']) = groups |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
198 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
199 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
|
200 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
201 input_type = params['input_options']['selected_input'] |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
202 if input_type == 'tabular': |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
203 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
|
204 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
|
205 ['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
|
206 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
|
207 '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
|
208 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
|
209 else: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
210 c = None |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
211 X = read_columns( |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
212 infile1, |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
213 c=c, |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
214 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
|
215 sep='\t', |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
216 header=header, |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
217 parse_dates=True).astype(float) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
218 else: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
219 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
|
220 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
221 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
|
222 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
|
223 ['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
|
224 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
|
225 '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
|
226 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
|
227 else: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
228 c = None |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
229 y = read_columns( |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
230 infile2, |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
231 c=c, |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
232 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
|
233 sep='\t', |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
234 header=header, |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
235 parse_dates=True) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
236 y = y.ravel() |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
237 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
238 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
|
239 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
|
240 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
241 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
|
242 |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
243 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
|
244 options['cv'] = splitter |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
245 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
|
246 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
|
247 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
|
248 if options['error_score']: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
249 options['error_score'] = 'raise' |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
250 else: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
251 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
|
252 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
|
253 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
|
254 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
|
255 options['pre_dispatch'] = None |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
256 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
257 with open(infile_estimator, 'rb') as estimator_handler: |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
258 estimator = load_model(estimator_handler) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
259 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
260 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
|
261 # 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
|
262 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
|
263 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
|
264 else: |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
265 for p, v in estimator.get_params().items(): |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
266 if p.endswith('memory'): |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
267 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
|
268 # 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
|
269 # speed significantly |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
270 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
|
271 estimator.set_params(**new_params) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
272 elif v: |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
273 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
|
274 estimator.set_params(**new_params) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
275 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
|
276 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
|
277 estimator.set_params(**new_params) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
278 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
279 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
|
280 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
|
281 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
282 # do train_test_split |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
283 do_train_test_split = params['train_test_split'].pop('do_split') |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
284 if do_train_test_split == 'yes': |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
285 # make sure refit is choosen |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
286 if not options['refit']: |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
287 raise ValueError("Refit must be `True` for shuffle splitting!") |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
288 split_options = params['train_test_split'] |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
289 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
290 # splits |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
291 if split_options['shuffle'] == 'stratified': |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
292 split_options['labels'] = y |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
293 X, X_test, y, y_test = train_test_split(X, y, **split_options) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
294 elif split_options['shuffle'] == 'group': |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
295 if not groups: |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
296 raise ValueError("No group based CV option was " |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
297 "choosen for group shuffle!") |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
298 split_options['labels'] = groups |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
299 X, X_test, y, y_test, groups, _ =\ |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
300 train_test_split(X, y, **split_options) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
301 else: |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
302 if split_options['shuffle'] == 'None': |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
303 split_options['shuffle'] = None |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
304 X, X_test, y, y_test =\ |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
305 train_test_split(X, y, **split_options) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
306 # end train_test_split |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
307 |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
308 if options['error_score'] == 'raise': |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
309 searcher.fit(X, y, groups=groups) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
310 else: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
311 warnings.simplefilter('always', FitFailedWarning) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
312 with warnings.catch_warnings(record=True) as w: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
313 try: |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
314 searcher.fit(X, y, groups=groups) |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
315 except ValueError: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
316 pass |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
317 for warning in w: |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
318 print(repr(warning.message)) |
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
319 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
320 if do_train_test_split == 'no': |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
321 # save results |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
322 cv_results = pandas.DataFrame(searcher.cv_results_) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
323 cv_results = cv_results[sorted(cv_results.columns)] |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
324 cv_results.to_csv(path_or_buf=outfile_result, sep='\t', |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
325 header=True, index=False) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
326 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
327 # output test result using best_estimator_ |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
328 else: |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
329 best_estimator_ = searcher.best_estimator_ |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
330 if isinstance(options['scoring'], collections.Mapping): |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
331 is_multimetric = True |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
332 else: |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
333 is_multimetric = False |
9
ed7b1654e841
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff
changeset
|
334 |
10
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
335 test_score = _score(best_estimator_, X_test, |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
336 y_test, options['scoring'], |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
337 is_multimetric=is_multimetric) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
338 if not is_multimetric: |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
339 test_score = {primary_scoring: test_score} |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
340 for key, value in test_score.items(): |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
341 test_score[key] = [value] |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
342 result_df = pandas.DataFrame(test_score) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
343 result_df.to_csv(path_or_buf=outfile_result, sep='\t', |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
344 header=True, index=False) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
345 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
346 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
|
347 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
348 if outfile_object: |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
349 with open(outfile_object, 'wb') as output_handler: |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
350 pickle.dump(searcher, output_handler, pickle.HIGHEST_PROTOCOL) |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
351 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
352 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
353 if __name__ == '__main__': |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
354 aparser = argparse.ArgumentParser() |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
355 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
|
356 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
|
357 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
|
358 aparser.add_argument("-y", "--infile2", dest="infile2") |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
359 aparser.add_argument("-r", "--outfile_result", dest="outfile_result") |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
360 aparser.add_argument("-o", "--outfile_object", dest="outfile_object") |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
361 aparser.add_argument("-g", "--groups", dest="groups") |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
362 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
|
363 |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
364 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
|
365 args.outfile_result, outfile_object=args.outfile_object, |
e9ba818e7877
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents:
9
diff
changeset
|
366 groups=args.groups) |