annotate search_model_validation.py @ 26:9bb505eafac9 draft

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