annotate search_model_validation.py @ 8:1a9d5a8fff12 draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
author bgruening
date Tue, 14 May 2019 18:03:50 -0400
parents 372582a7a34d
children 153f237ddb36
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
1 import argparse
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
2 import collections
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
3 import imblearn
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
4 import json
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
5 import numpy as np
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
6 import pandas
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
7 import pickle
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
8 import skrebate
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
9 import sklearn
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
10 import sys
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
11 import xgboost
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
12 import warnings
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
13 import iraps_classifier
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
14 import model_validations
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
15 import preprocessors
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
16 import feature_selectors
7
372582a7a34d 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
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
18 from scipy.io import mmread
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
19 from mlxtend import classifier, regressor
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
20 from sklearn import (cluster, compose, decomposition, ensemble,
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
21 feature_extraction, feature_selection,
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
22 gaussian_process, kernel_approximation, metrics,
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
23 model_selection, naive_bayes, neighbors,
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
24 pipeline, preprocessing, svm, linear_model,
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
25 tree, discriminant_analysis)
7
372582a7a34d 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
372582a7a34d 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
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
28 from sklearn.model_selection._validation import _score
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
29
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
30 from utils import (SafeEval, get_cv, get_scoring, get_X_y,
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
31 load_model, read_columns)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
32 from model_validations import train_test_split
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
33
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
34
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
35 N_JOBS = int(__import__('os').environ.get('GALAXY_SLOTS', 1))
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
36 CACHE_DIR = './cached'
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
37 NON_SEARCHABLE = ('n_jobs', 'pre_dispatch', 'memory', 'steps',
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
38 'nthread', 'verbose')
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
39
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
40
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
41 def _eval_search_params(params_builder):
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
42 search_params = {}
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
43
372582a7a34d 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']:
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
45 search_list = p['sp_list'].strip()
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
46 if search_list == '':
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
47 continue
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
48
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
49 param_name = p['sp_name']
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
50 if param_name.lower().endswith(NON_SEARCHABLE):
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
51 print("Warning: `%s` is not eligible for search and was "
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
52 "omitted!" % param_name)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
53 continue
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
54
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
55 if not search_list.startswith(':'):
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
56 safe_eval = SafeEval(load_scipy=True, load_numpy=True)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
57 ev = safe_eval(search_list)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
58 search_params[param_name] = ev
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
59 else:
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
60 # Have `:` before search list, asks for estimator evaluatio
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
61 safe_eval_es = SafeEval(load_estimators=True)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
62 search_list = search_list[1:].strip()
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
63 # TODO maybe add regular express check
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
64 ev = safe_eval_es(search_list)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
65 preprocessors = (
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
66 preprocessing.StandardScaler(), preprocessing.Binarizer(),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
67 preprocessing.Imputer(), preprocessing.MaxAbsScaler(),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
68 preprocessing.Normalizer(), preprocessing.MinMaxScaler(),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
69 preprocessing.PolynomialFeatures(),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
70 preprocessing.RobustScaler(), feature_selection.SelectKBest(),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
71 feature_selection.GenericUnivariateSelect(),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
72 feature_selection.SelectPercentile(),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
73 feature_selection.SelectFpr(), feature_selection.SelectFdr(),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
74 feature_selection.SelectFwe(),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
75 feature_selection.VarianceThreshold(),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
76 decomposition.FactorAnalysis(random_state=0),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
77 decomposition.FastICA(random_state=0),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
78 decomposition.IncrementalPCA(),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
79 decomposition.KernelPCA(random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
80 decomposition.LatentDirichletAllocation(
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
81 random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
82 decomposition.MiniBatchDictionaryLearning(
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
83 random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
84 decomposition.MiniBatchSparsePCA(
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
85 random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
86 decomposition.NMF(random_state=0),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
87 decomposition.PCA(random_state=0),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
88 decomposition.SparsePCA(random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
89 decomposition.TruncatedSVD(random_state=0),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
90 kernel_approximation.Nystroem(random_state=0),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
91 kernel_approximation.RBFSampler(random_state=0),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
92 kernel_approximation.AdditiveChi2Sampler(),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
93 kernel_approximation.SkewedChi2Sampler(random_state=0),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
94 cluster.FeatureAgglomeration(),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
95 skrebate.ReliefF(n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
96 skrebate.SURF(n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
97 skrebate.SURFstar(n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
98 skrebate.MultiSURF(n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
99 skrebate.MultiSURFstar(n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
100 imblearn.under_sampling.ClusterCentroids(
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
101 random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
102 imblearn.under_sampling.CondensedNearestNeighbour(
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
103 random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
104 imblearn.under_sampling.EditedNearestNeighbours(
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
105 random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
106 imblearn.under_sampling.RepeatedEditedNearestNeighbours(
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
107 random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
108 imblearn.under_sampling.AllKNN(random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
109 imblearn.under_sampling.InstanceHardnessThreshold(
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
110 random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
111 imblearn.under_sampling.NearMiss(
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
112 random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
113 imblearn.under_sampling.NeighbourhoodCleaningRule(
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
114 random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
115 imblearn.under_sampling.OneSidedSelection(
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
116 random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
117 imblearn.under_sampling.RandomUnderSampler(
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
118 random_state=0),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
119 imblearn.under_sampling.TomekLinks(
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
120 random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
121 imblearn.over_sampling.ADASYN(random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
122 imblearn.over_sampling.RandomOverSampler(random_state=0),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
123 imblearn.over_sampling.SMOTE(random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
124 imblearn.over_sampling.SVMSMOTE(random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
125 imblearn.over_sampling.BorderlineSMOTE(
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
126 random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
127 imblearn.over_sampling.SMOTENC(
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
128 categorical_features=[], random_state=0, n_jobs=N_JOBS),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
129 imblearn.combine.SMOTEENN(random_state=0),
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
130 imblearn.combine.SMOTETomek(random_state=0))
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
131 newlist = []
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
132 for obj in ev:
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
133 if obj is None:
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
134 newlist.append(None)
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
135 elif obj == 'all_0':
372582a7a34d 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])
372582a7a34d 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()
372582a7a34d 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])
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
139 elif obj == 'fs_all':
372582a7a34d 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])
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
141 elif obj == 'decomp_all':
372582a7a34d 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])
372582a7a34d 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':
372582a7a34d 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])
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
145 elif obj == 'reb_all':
372582a7a34d 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])
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
147 elif obj == 'imb_all':
372582a7a34d 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])
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
149 elif type(obj) is int and -1 < obj < len(preprocessors):
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
150 newlist.append(preprocessors[obj])
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
151 elif hasattr(obj, 'get_params'): # user uploaded object
7
372582a7a34d 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():
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
153 newlist.append(obj.set_params(n_jobs=N_JOBS))
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
154 else:
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
155 newlist.append(obj)
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
156 else:
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
157 sys.exit("Unsupported estimator type: %r" % (obj))
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
158
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
159 search_params[param_name] = newlist
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
160
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
161 return search_params
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
162
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
163
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
164 def main(inputs, infile_estimator, infile1, infile2,
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
165 outfile_result, outfile_object=None, groups=None):
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
166 """
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
167 Parameter
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
168 ---------
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
169 inputs : str
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
170 File path to galaxy tool parameter
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
171
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
172 infile_estimator : str
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
173 File path to estimator
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
174
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
175 infile1 : str
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
176 File path to dataset containing features
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
177
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
178 infile2 : str
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
179 File path to dataset containing target values
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
180
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
181 outfile_result : str
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
182 File path to save the results, either cv_results or test result
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
183
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
184 outfile_object : str, optional
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
185 File path to save searchCV object
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
186
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
187 groups : str
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
188 File path to dataset containing groups labels
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
189 """
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
190
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
191 warnings.simplefilter('ignore')
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
192
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
193 with open(inputs, 'r') as param_handler:
7
372582a7a34d 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)
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
195 if groups:
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
196 (params['search_schemes']['options']['cv_selector']
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
197 ['groups_selector']['infile_g']) = groups
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
198
372582a7a34d 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']
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
200
372582a7a34d 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']
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
202 if input_type == 'tabular':
372582a7a34d 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
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
204 column_option = (params['input_options']['column_selector_options_1']
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
205 ['selected_column_selector_option'])
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
206 if column_option in ['by_index_number', 'all_but_by_index_number',
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
207 'by_header_name', 'all_but_by_header_name']:
7
372582a7a34d 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']
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
209 else:
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
210 c = None
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
211 X = read_columns(
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
212 infile1,
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
213 c=c,
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
214 c_option=column_option,
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
215 sep='\t',
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
216 header=header,
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
217 parse_dates=True).astype(float)
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
218 else:
372582a7a34d 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'))
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
220
372582a7a34d 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
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
222 column_option = (params['input_options']['column_selector_options_2']
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
223 ['selected_column_selector_option2'])
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
224 if column_option in ['by_index_number', 'all_but_by_index_number',
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
225 'by_header_name', 'all_but_by_header_name']:
7
372582a7a34d 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']
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
227 else:
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
228 c = None
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
229 y = read_columns(
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
230 infile2,
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
231 c=c,
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
232 c_option=column_option,
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
233 sep='\t',
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
234 header=header,
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
235 parse_dates=True)
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
236 y = y.ravel()
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
237
372582a7a34d 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']
372582a7a34d 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)
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
240
372582a7a34d 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']
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
242
7
372582a7a34d 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'))
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
244 options['cv'] = splitter
7
372582a7a34d 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
372582a7a34d 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']
372582a7a34d 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'])
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
248 if options['error_score']:
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
249 options['error_score'] = 'raise'
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
250 else:
372582a7a34d 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
372582a7a34d 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):
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
253 options['refit'] = primary_scoring
7
372582a7a34d 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'] == '':
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
255 options['pre_dispatch'] = None
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
256
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
257 with open(infile_estimator, 'rb') as estimator_handler:
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
258 estimator = load_model(estimator_handler)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
259
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
260 memory = joblib.Memory(location=CACHE_DIR, verbose=0)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
261 # cache iraps_core fits could increase search speed significantly
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
262 if estimator.__class__.__name__ == 'IRAPSClassifier':
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
263 estimator.set_params(memory=memory)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
264 else:
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
265 for p, v in estimator.get_params().items():
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
266 if p.endswith('memory'):
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
267 if len(p) > 8 and p[:-8].endswith('irapsclassifier'):
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
268 # cache iraps_core fits could increase search
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
269 # speed significantly
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
270 new_params = {p: memory}
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
271 estimator.set_params(**new_params)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
272 elif v:
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
273 new_params = {p, None}
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
274 estimator.set_params(**new_params)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
275 elif p.endswith('n_jobs'):
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
276 new_params = {p: 1}
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
277 estimator.set_params(**new_params)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
278
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
279 param_grid = _eval_search_params(params_builder)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
280 searcher = optimizer(estimator, param_grid, **options)
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
281
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
282 # do train_test_split
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
283 do_train_test_split = params['train_test_split'].pop('do_split')
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
284 if do_train_test_split == 'yes':
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
285 # make sure refit is choosen
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
286 if not options['refit']:
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
287 raise ValueError("Refit must be `True` for shuffle splitting!")
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
288 split_options = params['train_test_split']
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
289
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
290 # splits
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
291 if split_options['shuffle'] == 'stratified':
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
292 split_options['labels'] = y
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
293 X, X_test, y, y_test = train_test_split(X, y, **split_options)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
294 elif split_options['shuffle'] == 'group':
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
295 if not groups:
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
296 raise ValueError("No group based CV option was "
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
297 "choosen for group shuffle!")
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
298 split_options['labels'] = groups
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
299 X, X_test, y, y_test, groups, _ =\
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
300 train_test_split(X, y, **split_options)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
301 else:
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
302 if split_options['shuffle'] == 'None':
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
303 split_options['shuffle'] = None
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
304 X, X_test, y, y_test =\
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
305 train_test_split(X, y, **split_options)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
306 # end train_test_split
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
307
372582a7a34d 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':
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
309 searcher.fit(X, y, groups=groups)
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
310 else:
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
311 warnings.simplefilter('always', FitFailedWarning)
372582a7a34d 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:
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
313 try:
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
314 searcher.fit(X, y, groups=groups)
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
315 except ValueError:
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
316 pass
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
317 for warning in w:
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
318 print(repr(warning.message))
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
319
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
320 if do_train_test_split == 'no':
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
321 # save results
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
322 cv_results = pandas.DataFrame(searcher.cv_results_)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
323 cv_results = cv_results[sorted(cv_results.columns)]
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
324 cv_results.to_csv(path_or_buf=outfile_result, sep='\t',
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
325 header=True, index=False)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
326
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
327 # output test result using best_estimator_
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
328 else:
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
329 best_estimator_ = searcher.best_estimator_
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
330 if isinstance(options['scoring'], collections.Mapping):
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
331 is_multimetric = True
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
332 else:
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
333 is_multimetric = False
7
372582a7a34d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57f4407e278a615f47a377a3328782b1d8e0b54d
bgruening
parents:
diff changeset
334
8
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
335 test_score = _score(best_estimator_, X_test,
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
336 y_test, options['scoring'],
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
337 is_multimetric=is_multimetric)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
338 if not is_multimetric:
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
339 test_score = {primary_scoring: test_score}
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
340 for key, value in test_score.items():
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
341 test_score[key] = [value]
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
342 result_df = pandas.DataFrame(test_score)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
343 result_df.to_csv(path_or_buf=outfile_result, sep='\t',
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
344 header=True, index=False)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
345
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
346 memory.clear(warn=False)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
347
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
348 if outfile_object:
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
349 with open(outfile_object, 'wb') as output_handler:
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
350 pickle.dump(searcher, output_handler, pickle.HIGHEST_PROTOCOL)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
351
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
352
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
353 if __name__ == '__main__':
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
354 aparser = argparse.ArgumentParser()
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
355 aparser.add_argument("-i", "--inputs", dest="inputs", required=True)
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
356 aparser.add_argument("-e", "--estimator", dest="infile_estimator")
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
357 aparser.add_argument("-X", "--infile1", dest="infile1")
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
358 aparser.add_argument("-y", "--infile2", dest="infile2")
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
359 aparser.add_argument("-r", "--outfile_result", dest="outfile_result")
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
360 aparser.add_argument("-o", "--outfile_object", dest="outfile_object")
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
361 aparser.add_argument("-g", "--groups", dest="groups")
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
362 args = aparser.parse_args()
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
363
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
364 main(args.inputs, args.infile_estimator, args.infile1, args.infile2,
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
365 args.outfile_result, outfile_object=args.outfile_object,
1a9d5a8fff12 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit c0a3a186966888e5787335a7628bf0a4382637e7
bgruening
parents: 7
diff changeset
366 groups=args.groups)