comparison svm.xml @ 0:7bee4014724a draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 8cbb681224f23fa95783514f949c97d6c2c60966
author bgruening
date Sat, 04 Aug 2018 12:46:28 -0400
parents
children 297541cc26d0
comparison
equal deleted inserted replaced
-1:000000000000 0:7bee4014724a
1 <tool id="sklearn_svm_classifier" name="Support vector machines (SVMs)" version="@VERSION@">
2 <description>for classification</description>
3 <macros>
4 <import>main_macros.xml</import>
5 <!-- macro name="class_weight" argument="class_weight"-->
6 </macros>
7 <expand macro="python_requirements"/>
8 <expand macro="macro_stdio"/>
9 <version_command>echo "@VERSION@"</version_command>
10 <command><![CDATA[
11 python '$svc_script' '$inputs'
12 ]]>
13 </command>
14 <configfiles>
15 <inputs name="inputs"/>
16 <configfile name="svc_script">
17 <![CDATA[
18 import sys
19 import json
20 import numpy as np
21 import sklearn.svm
22 import pandas
23 import pickle
24
25 @COLUMNS_FUNCTION@
26 @GET_X_y_FUNCTION@
27
28 input_json_path = sys.argv[1]
29 with open(input_json_path, "r") as param_handler:
30 params = json.load(param_handler)
31
32 #if $selected_tasks.selected_task == "load":
33
34 with open("$infile_model", 'rb') as model_handler:
35 classifier_object = pickle.load(model_handler)
36
37 header = 'infer' if params["selected_tasks"]["header"] else None
38 data = pandas.read_csv("$selected_tasks.infile_data", sep='\t', header=header, index_col=None, parse_dates=True, encoding=None, tupleize_cols=False)
39 prediction = classifier_object.predict(data)
40 prediction_df = pandas.DataFrame(prediction)
41 res = pandas.concat([data, prediction_df], axis=1)
42 res.to_csv(path_or_buf = "$outfile_predict", sep="\t", index=False)
43
44 #else:
45
46 X, y = get_X_y(params, "$selected_tasks.selected_algorithms.input_options.infile1" ,"$selected_tasks.selected_algorithms.input_options.infile2")
47
48 options = params["selected_tasks"]["selected_algorithms"]["options"]
49 selected_algorithm = params["selected_tasks"]["selected_algorithms"]["selected_algorithm"]
50
51 if not(selected_algorithm=="LinearSVC"):
52 if options["kernel"]:
53 options["kernel"] = str(options["kernel"])
54
55 my_class = getattr(sklearn.svm, selected_algorithm)
56 classifier_object = my_class(**options)
57 classifier_object.fit(X, y)
58
59 with open("$outfile_fit", 'wb') as out_handler:
60 pickle.dump(classifier_object, out_handler)
61
62 #end if
63
64 ]]>
65 </configfile>
66 </configfiles>
67 <inputs>
68 <expand macro="sl_Conditional" model="zip">
69 <param name="selected_algorithm" type="select" label="Classifier type">
70 <option value="SVC">C-Support Vector Classification</option>
71 <option value="NuSVC">Nu-Support Vector Classification</option>
72 <option value="LinearSVC">Linear Support Vector Classification</option>
73 </param>
74 <when value="SVC">
75 <expand macro="sl_mixed_input"/>
76 <expand macro="svc_advanced_options">
77 <expand macro="C"/>
78 </expand>
79 </when>
80 <when value="NuSVC">
81 <expand macro="sl_mixed_input"/>
82 <expand macro="svc_advanced_options">
83 <param argument="nu" type="float" optional="true" value="0.5" label="Nu control parameter" help="Controls the number of support vectors. Should be in the interval (0, 1]. "/>
84 </expand>
85 </when>
86 <when value="LinearSVC">
87 <expand macro="sl_mixed_input"/>
88 <section name="options" title="Advanced Options" expanded="False">
89 <expand macro="C"/>
90 <expand macro="tol" default_value="0.001" help_text="Tolerance for stopping criterion. "/>
91 <expand macro="random_state" help_text="Integer number. The seed of the pseudo random number generator to use when shuffling the data for probability estimation. A fixed seed allows reproducible results."/>
92 <!--expand macro="class_weight"/-->
93 <param argument="max_iter" type="integer" optional="true" value="1000" label="Maximum number of iterations" help="The maximum number of iterations to be run."/>
94 <param argument="loss" type="select" label="Loss function" help="Specifies the loss function. ''squared_hinge'' is the square of the hinge loss.">
95 <option value="squared_hinge" selected="true">Squared hinge</option>
96 <option value="hinge">Hinge</option>
97 </param>
98 <param argument="penalty" type="select" label="Penalization norm" help=" ">
99 <option value="l1" >l1</option>
100 <option value="l2" selected="true">l2</option>
101 </param>
102 <param argument="dual" type="boolean" optional="true" truevalue="booltrue" falsevalue="boolflase" checked="true" label="Use the shrinking heuristic" help="Select the algorithm to either solve the dual or primal optimization problem. Prefer dual=False when n_samples > n_features."/>
103 <param argument="multi_class" type="select" label="Multi-class strategy" help="Determines the multi-class strategy if y contains more than two classes.">
104 <option value="ovr" selected="true">ovr</option>
105 <option value="crammer_singer" >crammer_singer</option>
106 </param>
107 <param argument="fit_intercept" type="boolean" optional="true" truevalue="booltrue" falsevalue="boolflase" checked="true" label="Calculate the intercept for this model" help="If set to false, data is expected to be already centered."/>
108 <param argument="intercept_scaling" type="float" optional="true" value="1" label="Add synthetic feature to the instance vector" help=" "/>
109 </section>
110 </when>
111 </expand>
112 </inputs>
113
114 <expand macro="output"/>
115
116 <tests>
117 <test>
118 <param name="infile1" value="train_set.tabular" ftype="tabular"/>
119 <param name="infile2" value="train_set.tabular" ftype="tabular"/>
120 <param name="header1" value="True"/>
121 <param name="header2" value="True"/>
122 <param name="col1" value="1,2,3,4"/>
123 <param name="col2" value="5"/>
124 <param name="selected_task" value="train"/>
125 <param name="selected_algorithm" value="SVC"/>
126 <param name="random_state" value="5"/>
127 <output name="outfile_fit" file="svc_model01.txt"/>
128 </test>
129 <test>
130 <param name="infile1" value="train_set.tabular" ftype="tabular"/>
131 <param name="infile2" value="train_set.tabular" ftype="tabular"/>
132 <param name="header1" value="True"/>
133 <param name="header2" value="True"/>
134 <param name="col1" value="1,2,3,4"/>
135 <param name="col2" value="5"/>
136 <param name="selected_task" value="train"/>
137 <param name="selected_algorithm" value="NuSVC"/>
138 <param name="random_state" value="5"/>
139 <output name="outfile_fit" file="svc_model02.txt"/>
140 </test>
141 <test>
142 <param name="infile1" value="train_set.tabular" ftype="tabular"/>
143 <param name="infile2" value="train_set.tabular" ftype="tabular"/>
144 <param name="header1" value="True"/>
145 <param name="header2" value="True"/>
146 <param name="col1" value="1,2,3,4"/>
147 <param name="col2" value="5"/>
148 <param name="selected_task" value="train"/>
149 <param name="selected_algorithm" value="LinearSVC"/>
150 <param name="random_state" value="5"/>
151 <output name="outfile_fit" file="svc_model03.txt"/>
152 </test>
153 <test>
154 <param name="infile_model" value="svc_model01.txt" ftype="txt"/>
155 <param name="infile_data" value="test_set.tabular" ftype="tabular"/>
156 <param name="header" value="True"/>
157 <param name="selected_task" value="load"/>
158 <output name="outfile_predict" file="svc_prediction_result01.tabular"/>
159 </test>
160 <test>
161 <param name="infile_model" value="svc_model02.txt" ftype="txt"/>
162 <param name="infile_data" value="test_set.tabular" ftype="tabular"/>
163 <param name="header" value="True"/>
164 <param name="selected_task" value="load"/>
165 <output name="outfile_predict" file="svc_prediction_result02.tabular"/>
166 </test>
167 <test>
168 <param name="infile_model" value="svc_model03.txt" ftype="txt"/>
169 <param name="infile_data" value="test_set.tabular" ftype="tabular"/>
170 <param name="header" value="True"/>
171 <param name="selected_task" value="load"/>
172 <output name="outfile_predict" file="svc_prediction_result03.tabular"/>
173 </test>
174 </tests>
175 <help><![CDATA[
176 **What it does**
177 This module implements the Support Vector Machine (SVM) classification algorithms.
178 Support vector machines (SVMs) are a set of supervised learning methods used for classification, regression and outliers detection.
179
180 **The advantages of support vector machines are:**
181
182 1- Effective in high dimensional spaces.
183
184 2- Still effective in cases where number of dimensions is greater than the number of samples.
185
186 3- Uses a subset of training points in the decision function (called support vectors), so it is also memory efficient.
187
188 4- Versatile: different Kernel functions can be specified for the decision function. Common kernels are provided, but it is also possible to specify custom kernels.
189
190 **The disadvantages of support vector machines include:**
191
192 1- If the number of features is much greater than the number of samples, the method is likely to give poor performances.
193
194 2- SVMs do not directly provide probability estimates, these are calculated using an expensive five-fold cross-validation
195
196 For more information check http://scikit-learn.org/stable/modules/neighbors.html
197
198 ]]>
199 </help>
200 <expand macro="sklearn_citation"/>
201 </tool>