annotate stacking_ensembles.py @ 15:b7d104ede67e draft default tip

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
author bgruening
date Sun, 05 Nov 2023 15:41:30 +0000
parents 364234f65507
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
1 import argparse
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
2 import ast
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
3 import json
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
4 import sys
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
5 import warnings
9
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
6 from distutils.version import LooseVersion as Version
4
aff86cee673c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 3
diff changeset
7
aff86cee673c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 3
diff changeset
8 import mlxtend.classifier
aff86cee673c "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 3
diff changeset
9 import mlxtend.regressor
9
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
10 from galaxy_ml import __version__ as galaxy_ml_version
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
11 from galaxy_ml.model_persist import dump_model_to_h5, load_model_from_h5
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
12 from galaxy_ml.utils import get_cv, get_estimator
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
13
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
14 warnings.filterwarnings("ignore")
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
15
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
16 N_JOBS = int(__import__("os").environ.get("GALAXY_SLOTS", 1))
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
17
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
18
9
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
19 def main(inputs_path, output_obj, base_paths=None, meta_path=None):
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
20 """
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
21 Parameter
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
22 ---------
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
23 inputs_path : str
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
24 File path for Galaxy parameters
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
25
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
26 output_obj : str
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
27 File path for ensemble estimator ouput
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
28
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
29 base_paths : str
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
30 File path or paths concatenated by comma.
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
31
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
32 meta_path : str
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
33 File path
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
34 """
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
35 with open(inputs_path, "r") as param_handler:
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
36 params = json.load(param_handler)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
37
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
38 estimator_type = params["algo_selection"]["estimator_type"]
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
39 # get base estimators
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
40 base_estimators = []
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
41 for idx, base_file in enumerate(base_paths.split(",")):
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
42 if base_file and base_file != "None":
9
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
43 model = load_model_from_h5(base_file)
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
44 else:
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
45 estimator_json = params["base_est_builder"][idx]["estimator_selector"]
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
46 model = get_estimator(estimator_json)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
47
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
48 if estimator_type.startswith("sklearn"):
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
49 named = model.__class__.__name__.lower()
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
50 named = "base_%d_%s" % (idx, named)
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
51 base_estimators.append((named, model))
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
52 else:
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
53 base_estimators.append(model)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
54
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
55 # get meta estimator, if applicable
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
56 if estimator_type.startswith("mlxtend"):
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
57 if meta_path:
9
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
58 meta_estimator = load_model_from_h5(meta_path)
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
59 else:
5
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
60 estimator_json = params["algo_selection"]["meta_estimator"][
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
61 "estimator_selector"
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
62 ]
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
63 meta_estimator = get_estimator(estimator_json)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
64
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
65 options = params["algo_selection"]["options"]
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
66
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
67 cv_selector = options.pop("cv_selector", None)
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
68 if cv_selector:
9
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
69 if Version(galaxy_ml_version) < Version("0.8.3"):
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
70 cv_selector.pop("n_stratification_bins", None)
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
71 splitter, groups = get_cv(cv_selector)
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
72 options["cv"] = splitter
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
73 # set n_jobs
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
74 options["n_jobs"] = N_JOBS
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
75
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
76 weights = options.pop("weights", None)
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
77 if weights:
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
78 weights = ast.literal_eval(weights)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
79 if weights:
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
80 options["weights"] = weights
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
81
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
82 mod_and_name = estimator_type.split("_")
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
83 mod = sys.modules[mod_and_name[0]]
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
84 klass = getattr(mod, mod_and_name[1])
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
85
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
86 if estimator_type.startswith("sklearn"):
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
87 options["n_jobs"] = N_JOBS
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
88 ensemble_estimator = klass(base_estimators, **options)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
89
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
90 elif mod == mlxtend.classifier:
5
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
91 ensemble_estimator = klass(
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
92 classifiers=base_estimators, meta_classifier=meta_estimator, **options
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
93 )
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
94
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
95 else:
5
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
96 ensemble_estimator = klass(
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
97 regressors=base_estimators, meta_regressor=meta_estimator, **options
c48ffc96fe79 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
bgruening
parents: 4
diff changeset
98 )
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
99
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
100 print(ensemble_estimator)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
101 for base_est in base_estimators:
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
102 print(base_est)
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
103
9
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
104 dump_model_to_h5(ensemble_estimator, output_obj)
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
105
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
106
3
c3bafda50176 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit e2a5eade6d0e5ddf3a47630381a0ad90d80e8a04"
bgruening
parents: 0
diff changeset
107 if __name__ == "__main__":
0
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
108 aparser = argparse.ArgumentParser()
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
109 aparser.add_argument("-b", "--bases", dest="bases")
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
110 aparser.add_argument("-m", "--meta", dest="meta")
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
111 aparser.add_argument("-i", "--inputs", dest="inputs")
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
112 aparser.add_argument("-o", "--outfile", dest="outfile")
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
113 args = aparser.parse_args()
13226b2ddfb4 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 756f8be9c3cd437e131e6410cd625c24fe078e8c"
bgruening
parents:
diff changeset
114
9
364234f65507 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
bgruening
parents: 5
diff changeset
115 main(args.inputs, args.outfile, base_paths=args.bases, meta_path=args.meta)