comparison ensemble.xml @ 0:31fd07e0acdb draft

planemo upload for repository https://github.com/bgruening/galaxytools/tools/sklearn commit 6c002ea2995c85f5f16adb2ef1c6be82dfbc5417
author bgruening
date Tue, 31 May 2016 16:50:56 -0400
parents
children a92c5991d959
comparison
equal deleted inserted replaced
-1:000000000000 0:31fd07e0acdb
1 <tool id="sklearn_ensemble" name="Ensemble methods" version="@VERSION@">
2 <description>for classification and regression</description>
3 <macros>
4 <import>main_macros.xml</import>
5 <!--macro name="priors"-->
6 </macros>
7 <expand macro="python_requirements"/>
8 <expand macro="macro_stdio"/>
9 <version_command>echo "@VERSION@"</version_command>
10 <command><![CDATA[
11 python "$ensemble_script" '$inputs'
12 ]]>
13 </command>
14 <configfiles>
15 <inputs name="inputs"/>
16 <configfile name="ensemble_script">
17 <![CDATA[
18 import sys
19 import json
20 import numpy as np
21 import sklearn.ensemble
22 import pandas
23 import pickle
24 from scipy.io import mmread
25
26 input_json_path = sys.argv[1]
27 params = json.load(open(input_json_path, "r"))
28
29 #if $selected_tasks.selected_task == "train":
30
31 algorithm = params["selected_tasks"]["selected_algorithms"]["selected_algorithm"]
32 options = params["selected_tasks"]["selected_algorithms"]["options"]
33 input_type = params["selected_tasks"]["selected_algorithms"]["input_options"]["selected_input"]
34 if input_type=="tabular":
35 col1 = params["selected_tasks"]["selected_algorithms"]["input_options"]["col1"]
36 col1 = list(map(lambda x: x - 1, col1))
37 f1 = pandas.read_csv("$selected_tasks.selected_algorithms.input_options.infile1", sep='\t', header=None, index_col=None, parse_dates=True, encoding=None, tupleize_cols=False )
38 X = f1.iloc[:,col1].values
39 else:
40 X = mmread(open("$selected_tasks.selected_algorithms.input_options.infile1", 'r'))
41
42 col2 = params["selected_tasks"]["selected_algorithms"]["input_options"]["col2"]
43 col2 = list(map(lambda x: x - 1, col2))
44 f2 = pandas.read_csv("$selected_tasks.selected_algorithms.input_options.infile2", sep='\t', header=None, index_col=None, parse_dates=True, encoding=None, tupleize_cols=False )
45 y = f2.iloc[:,col2].values
46
47 my_class = getattr(sklearn.ensemble, algorithm)
48 estimator = my_class(**options)
49 estimator.fit(X,y)
50 pickle.dump(estimator,open("$outfile_fit", 'w+'), pickle.HIGHEST_PROTOCOL)
51
52 #else:
53 classifier_object = pickle.load(open("$selected_tasks.infile_model", 'r'))
54 data = pandas.read_csv("$selected_tasks.infile_data", sep='\t', header=None, index_col=None, parse_dates=True, encoding=None, tupleize_cols=False )
55 prediction = classifier_object.predict(data)
56 prediction_df = pandas.DataFrame(prediction)
57 res = pandas.concat([data, prediction_df], axis=1)
58 res.to_csv(path_or_buf = "$outfile_predict", sep="\t", index=False)
59 #end if
60
61 ]]>
62 </configfile>
63 </configfiles>
64 <inputs>
65 <expand macro="sl_Conditional" model="zip">
66 <param name="selected_algorithm" type="select" label="Select an ensemble method:">
67 <option value="RandomForestClassifier" selected="true">Random forest classifier</option>
68 <option value="AdaBoostClassifier">Ada boost classifier</option>
69 <option value="RandomForestRegressor">Random forest regressor</option>
70 <option value="AdaBoostRegressor">Ada boost regressor</option>
71 </param>
72 <when value="RandomForestClassifier">
73 <expand macro="sl_mixed_input"/>
74 <section name="options" title="Advanced Options" expanded="False">
75 <expand macro="n_estimators"/>
76 <expand macro="criterion"/>
77 <expand macro="max_features"/>
78 <expand macro="max_depth"/>
79 <expand macro="min_samples_split"/>
80 <expand macro="min_samples_leaf"/>
81 <expand macro="min_weight_fraction_leaf"/>
82 <expand macro="max_leaf_nodes"/>
83 <expand macro="bootstrap"/>
84 <expand macro="warm_start" checked="false"/>
85 <expand macro="random_state"/>
86 <expand macro="oob_score"/>
87 <!--class_weight=None-->
88 </section>
89 </when>
90 <when value="AdaBoostClassifier">
91 <expand macro="sl_mixed_input"/>
92 <section name="options" title="Advanced Options" expanded="False">
93 <!--base_estimator=None-->
94 <expand macro="n_estimators" default_value="50"/>
95 <expand macro="learning_rate"/>
96 <param argument="algorithm" type="select" label="Boosting algorithm" help=" ">
97 <option value="SAMME.R" selected="true">SAMME.R</option>
98 <option value="SAMME">SAMME</option>
99 </param>
100 <expand macro="random_state"/>
101 </section>
102 </when>
103 <when value="RandomForestRegressor">
104 <expand macro="sl_mixed_input"/>
105 <section name="options" title="Advanced Options" expanded="False">
106 <expand macro="n_estimators"/>
107 <expand macro="max_features"/>
108 <expand macro="max_depth"/>
109 <expand macro="min_samples_split"/>
110 <expand macro="min_samples_leaf"/>
111 <expand macro="min_weight_fraction_leaf"/>
112 <expand macro="max_leaf_nodes"/>
113 <expand macro="bootstrap"/>
114 <expand macro="warm_start" checked="false"/>
115 <expand macro="random_state"/>
116 <expand macro="oob_score"/>
117 </section>
118 </when>
119 <when value="AdaBoostRegressor">
120 <expand macro="sl_mixed_input"/>
121 <section name="options" title="Advanced Options" expanded="False">
122 <!--base_estimator=None-->
123 <expand macro="n_estimators" default_value="50"/>
124 <expand macro="learning_rate"/>
125 <param argument="loss" type="select" label="Loss function" optional="true" help="Used when updating the weights after each boosting iteration. ">
126 <option value="linear" selected="true">linear</option>
127 <option value="square">square</option>
128 <option value="exponential">exponential</option>
129 </param>
130 <expand macro="random_state"/>
131 </section>
132 </when>
133 </expand>
134 </inputs>
135 <outputs>
136 <data format="tabular" name="outfile_predict">
137 <filter>selected_tasks['selected_task'] == 'load'</filter>
138 </data>
139 <data format="zip" name="outfile_fit">
140 <filter>selected_tasks['selected_task'] == 'train'</filter>
141 </data>
142 </outputs>
143 <tests>
144 <test>
145 <param name="infile1" value="train.tabular" ftype="tabular"/>
146 <param name="infile2" value="train.tabular" ftype="tabular"/>
147 <param name="col1" value="1,2,3,4"/>
148 <param name="col2" value="5"/>
149 <param name="selected_task" value="train"/>
150 <param name="selected_algorithm" value="RandomForestClassifier"/>
151 <param name="random_state" value="10"/>
152 <output name="outfile_fit" file="rfc_model01" compare="sim_size" delta="500"/>
153 </test>
154 <test>
155 <param name="infile_model" value="rfc_model01" ftype="zip"/>
156 <param name="infile_data" value="test.tabular" ftype="tabular"/>
157 <param name="selected_task" value="load"/>
158 <output name="outfile_predict" file="rfc_result01"/>
159 </test>
160
161 <test>
162 <param name="infile1" value="regression_train.tabular" ftype="tabular"/>
163 <param name="infile2" value="regression_train.tabular" ftype="tabular"/>
164 <param name="col1" value="1,2,3,4,5"/>
165 <param name="col2" value="6"/>
166 <param name="selected_task" value="train"/>
167 <param name="selected_algorithm" value="RandomForestRegressor"/>
168 <param name="random_state" value="10"/>
169 <output name="outfile_fit" file="rfr_model01" compare="sim_size" delta="500"/>
170 </test>
171 <test>
172 <param name="infile_model" value="rfr_model01" ftype="zip"/>
173 <param name="infile_data" value="regression_test.tabular" ftype="tabular"/>
174 <param name="selected_task" value="load"/>
175 <output name="outfile_predict" file="rfr_result01"/>
176 </test>
177 </tests>
178 <help><![CDATA[
179 ***What it does***
180 The goal of ensemble methods is to combine the predictions of several base estimators built with a given learning algorithm in order to improve generalizability / robustness over a single estimator. This tool offers two sets of ensemble algorithms for classification and regression: random forests and ADA boosting which are based on sklearn.ensemble library from Scikit-learn. Here you can find out about the input, output and methods presented in the tools. For information about ensemble methods and parameters settings please refer to `Scikit-learn ensemble`_.
181
182 .. _`Scikit-learn ensemble`: http://scikit-learn.org/stable/modules/ensemble.html
183
184 **1 - Methods**
185 There are two groups of operations available:
186
187 1 - Train a model : A training set containing samples and their respective labels (or predicted values) are input. Based on the selected algorithm and options, an estimator object is fit to the data and is returned.
188
189 2 - Load a model and predict : An existing model predicts the class labels (or regression values) for a new dataset.
190
191 **2 - Trainig input**
192 When you choose to train a model, you need a features dataset X and a labels set y. This tool expects tabular or sparse data for X and a single column for y (tabular). You can select a subset of columns in a tabular dataset as your features dataset or labels column. Below you find some examples:
193
194 **Sample tabular features dataset**
195 The following training dataset contains 3 feature columns and a column containing class labels. You can simply select the first 3 columns as features and the last column as labels:
196
197 ::
198
199 4.01163365529 -6.10797684314 8.29829894763 1
200 10.0788438916 1.59539821454 10.0684278289 0
201 -5.17607775503 -0.878286135332 6.92941850665 2
202 4.00975406235 -7.11847496542 9.3802423585 1
203 4.61204065139 -5.71217537352 9.12509610964 1
204
205
206 **Sample sparse features dataset**
207 In this case you cannot specifiy a column range.
208
209 ::
210
211 4 1048577 8738
212 1 271 0.02083333333333341
213 1 1038 0.02461995616119806
214 2 829017 0.01629088031127686
215 2 829437 0.01209127083516686
216 2 830752 0.02535100632816968
217 3 1047487 0.01485722929945572
218 3 1047980 0.02640566620767753
219 3 1048475 0.01665869913262564
220 4 608 0.01662975263094352
221 4 1651 0.02519674277562741
222 4 4053 0.04223659971350601
223
224
225 **2 - Trainig output**
226 The trained model is generated and output in the form of a binary file.
227
228
229 **3 - Prediction input**
230
231 When you choose to load a model and do prediction, the tool expects an already trained estimator and a tabular dataset as input. The dataset contains new samples which you want to classify or predict regression values for.
232
233
234 .. class:: warningmark
235
236 The number of feature columns must be the same in training and prediction datasets!
237
238
239 **3 - Prediction output**
240 The tool predicts the class labels for new samples and adds them as the last column to the prediction dataset. The new dataset then is output as a tabular file. The prediction output format should look like the training dataset.
241
242 ]]></help>
243 <expand macro="sklearn_citation"/>
244 </tool>