annotate stacking_ensembles.py @ 17:cf9aa11b91c8 draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
author bgruening
date Wed, 15 May 2019 07:42:07 -0400
parents
children efbec977a47d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
1 import argparse
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
2 import json
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
3 import pandas as pd
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
4 import pickle
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
5 import xgboost
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
6 import warnings
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
7 from sklearn import (cluster, compose, decomposition, ensemble,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
8 feature_extraction, feature_selection,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
9 gaussian_process, kernel_approximation, metrics,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
10 model_selection, naive_bayes, neighbors,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
11 pipeline, preprocessing, svm, linear_model,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
12 tree, discriminant_analysis)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
13 from sklearn.model_selection._split import check_cv
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
14 from feature_selectors import (DyRFE, DyRFECV,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
15 MyPipeline, MyimbPipeline)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
16 from iraps_classifier import (IRAPSCore, IRAPSClassifier,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
17 BinarizeTargetClassifier,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
18 BinarizeTargetRegressor)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
19 from preprocessors import Z_RandomOverSampler
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
20 from utils import load_model, get_cv, get_estimator, get_search_params
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
21
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
22 from mlxtend.regressor import StackingCVRegressor, StackingRegressor
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
23 from mlxtend.classifier import StackingCVClassifier, StackingClassifier
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
24
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
25
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
26 warnings.filterwarnings('ignore')
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
27
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
28 N_JOBS = int(__import__('os').environ.get('GALAXY_SLOTS', 1))
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
29
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
30
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
31 def main(inputs_path, output_obj, base_paths=None, meta_path=None,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
32 outfile_params=None):
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
33 """
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
34 Parameter
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
35 ---------
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
36 inputs_path : str
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
37 File path for Galaxy parameters
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
38
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
39 output_obj : str
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
40 File path for ensemble estimator ouput
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
41
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
42 base_paths : str
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
43 File path or paths concatenated by comma.
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
44
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
45 meta_path : str
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
46 File path
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
47
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
48 outfile_params : str
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
49 File path for params output
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
50 """
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
51 with open(inputs_path, 'r') as param_handler:
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
52 params = json.load(param_handler)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
53
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
54 base_estimators = []
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
55 for idx, base_file in enumerate(base_paths.split(',')):
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
56 if base_file and base_file != 'None':
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
57 with open(base_file, 'rb') as handler:
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
58 model = load_model(handler)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
59 else:
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
60 estimator_json = (params['base_est_builder'][idx]
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
61 ['estimator_selector'])
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
62 model = get_estimator(estimator_json)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
63 base_estimators.append(model)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
64
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
65 if meta_path:
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
66 with open(meta_path, 'rb') as f:
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
67 meta_estimator = load_model(f)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
68 else:
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
69 estimator_json = params['meta_estimator']['estimator_selector']
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
70 meta_estimator = get_estimator(estimator_json)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
71
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
72 options = params['algo_selection']['options']
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
73
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
74 cv_selector = options.pop('cv_selector', None)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
75 if cv_selector:
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
76 splitter, groups = get_cv(cv_selector)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
77 options['cv'] = splitter
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
78 # set n_jobs
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
79 options['n_jobs'] = N_JOBS
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
80
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
81 if params['algo_selection']['estimator_type'] == 'StackingCVClassifier':
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
82 ensemble_estimator = StackingCVClassifier(
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
83 classifiers=base_estimators,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
84 meta_classifier=meta_estimator,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
85 **options)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
86
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
87 elif params['algo_selection']['estimator_type'] == 'StackingClassifier':
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
88 ensemble_estimator = StackingClassifier(
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
89 classifiers=base_estimators,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
90 meta_classifier=meta_estimator,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
91 **options)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
92
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
93 elif params['algo_selection']['estimator_type'] == 'StackingCVRegressor':
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
94 ensemble_estimator = StackingCVRegressor(
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
95 regressors=base_estimators,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
96 meta_regressor=meta_estimator,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
97 **options)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
98
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
99 else:
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
100 ensemble_estimator = StackingRegressor(
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
101 regressors=base_estimators,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
102 meta_regressor=meta_estimator,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
103 **options)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
104
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
105 print(ensemble_estimator)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
106 for base_est in base_estimators:
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
107 print(base_est)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
108
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
109 with open(output_obj, 'wb') as out_handler:
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
110 pickle.dump(ensemble_estimator, out_handler, pickle.HIGHEST_PROTOCOL)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
111
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
112 if params['get_params'] and outfile_params:
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
113 results = get_search_params(ensemble_estimator)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
114 df = pd.DataFrame(results, columns=['', 'Parameter', 'Value'])
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
115 df.to_csv(outfile_params, sep='\t', index=False)
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
116
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
117
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
118 if __name__ == '__main__':
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
119 aparser = argparse.ArgumentParser()
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
120 aparser.add_argument("-b", "--bases", dest="bases")
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
121 aparser.add_argument("-m", "--meta", dest="meta")
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
122 aparser.add_argument("-i", "--inputs", dest="inputs")
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
123 aparser.add_argument("-o", "--outfile", dest="outfile")
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
124 aparser.add_argument("-p", "--outfile_params", dest="outfile_params")
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
125 args = aparser.parse_args()
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
126
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
127 main(args.inputs, args.outfile, base_paths=args.bases,
cf9aa11b91c8 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ab963ec9498bd05d2fb2f24f75adb2fccae7958c
bgruening
parents:
diff changeset
128 meta_path=args.meta, outfile_params=args.outfile_params)