Mercurial > repos > bgruening > sklearn_svm_classifier
comparison svm.xml @ 25:b878e4cdd63a draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
author | bgruening |
---|---|
date | Wed, 09 Aug 2023 12:24:57 +0000 |
parents | d67dcd63f6cb |
children |
comparison
equal
deleted
inserted
replaced
24:b7c3e9a3b954 | 25:b878e4cdd63a |
---|---|
1 <tool id="sklearn_svm_classifier" name="Support vector machines (SVMs)" version="@VERSION@" profile="20.05"> | 1 <tool id="sklearn_svm_classifier" name="Support vector machines (SVMs)" version="@VERSION@" profile="@PROFILE@"> |
2 <description>for classification</description> | 2 <description>for classification</description> |
3 <macros> | 3 <macros> |
4 <import>main_macros.xml</import> | 4 <import>main_macros.xml</import> |
5 <!-- macro name="class_weight" argument="class_weight"--> | 5 <!-- macro name="class_weight" argument="class_weight"--> |
6 </macros> | 6 </macros> |
17 <![CDATA[ | 17 <![CDATA[ |
18 import sys | 18 import sys |
19 import json | 19 import json |
20 import sklearn.svm | 20 import sklearn.svm |
21 import pandas | 21 import pandas |
22 import pickle | 22 |
23 | 23 from galaxy_ml.model_persist import dump_model_to_h5, load_model_from_h5 |
24 from galaxy_ml.utils import load_model, get_X_y | 24 from galaxy_ml.utils import clean_params, get_X_y |
25 | 25 |
26 | 26 |
27 input_json_path = sys.argv[1] | 27 input_json_path = sys.argv[1] |
28 with open(input_json_path, "r") as param_handler: | 28 with open(input_json_path, "r") as param_handler: |
29 params = json.load(param_handler) | 29 params = json.load(param_handler) |
31 #if $selected_tasks.selected_task == "load": | 31 #if $selected_tasks.selected_task == "load": |
32 | 32 |
33 header = 'infer' if params["selected_tasks"]["header"] else None | 33 header = 'infer' if params["selected_tasks"]["header"] else None |
34 data = pandas.read_csv("$selected_tasks.infile_data", sep='\t', header=header, index_col=None, parse_dates=True, encoding=None) | 34 data = pandas.read_csv("$selected_tasks.infile_data", sep='\t', header=header, index_col=None, parse_dates=True, encoding=None) |
35 | 35 |
36 with open("$infile_model", 'rb') as model_handler: | 36 classifier_object = load_model_from_h5('$infile_model') |
37 classifier_object = load_model(model_handler) | 37 classifier_object = clean_params(classifier_object) |
38 | 38 |
39 prediction = classifier_object.predict(data) | 39 prediction = classifier_object.predict(data) |
40 prediction_df = pandas.DataFrame(prediction) | 40 prediction_df = pandas.DataFrame(prediction) |
41 res = pandas.concat([data, prediction_df], axis=1) | 41 res = pandas.concat([data, prediction_df], axis=1) |
42 res.to_csv(path_or_buf = "$outfile_predict", sep="\t", index=False) | 42 res.to_csv(path_or_buf = "$outfile_predict", sep="\t", index=False) |
54 | 54 |
55 my_class = getattr(sklearn.svm, selected_algorithm) | 55 my_class = getattr(sklearn.svm, selected_algorithm) |
56 classifier_object = my_class(**options) | 56 classifier_object = my_class(**options) |
57 classifier_object.fit(X, y) | 57 classifier_object.fit(X, y) |
58 | 58 |
59 with open("$outfile_fit", 'wb') as out_handler: | 59 dump_model_to_h5(classifier_object, '$outfile_fit') |
60 pickle.dump(classifier_object, out_handler) | |
61 | 60 |
62 #end if | 61 #end if |
63 | 62 |
64 ]]> | 63 ]]> |
65 </configfile> | 64 </configfile> |
66 </configfiles> | 65 </configfiles> |
67 <inputs> | 66 <inputs> |
68 <expand macro="sl_Conditional" model="zip"> | 67 <expand macro="sl_Conditional" model="h5mlm"> |
69 <param name="selected_algorithm" type="select" label="Classifier type"> | 68 <param name="selected_algorithm" type="select" label="Classifier type"> |
70 <option value="SVC">C-Support Vector Classification</option> | 69 <option value="SVC">C-Support Vector Classification</option> |
71 <option value="NuSVC">Nu-Support Vector Classification</option> | 70 <option value="NuSVC">Nu-Support Vector Classification</option> |
72 <option value="LinearSVC">Linear Support Vector Classification</option> | 71 <option value="LinearSVC">Linear Support Vector Classification</option> |
73 </param> | 72 </param> |
147 <param name="selected_algorithm" value="LinearSVC" /> | 146 <param name="selected_algorithm" value="LinearSVC" /> |
148 <param name="random_state" value="5" /> | 147 <param name="random_state" value="5" /> |
149 <output name="outfile_fit" file="svc_model03" compare="sim_size" /> | 148 <output name="outfile_fit" file="svc_model03" compare="sim_size" /> |
150 </test> | 149 </test> |
151 <test> | 150 <test> |
152 <param name="infile_model" value="svc_model01" ftype="zip" /> | 151 <param name="infile_model" value="svc_model01" ftype="h5mlm" /> |
153 <param name="infile_data" value="test_set.tabular" ftype="tabular" /> | 152 <param name="infile_data" value="test_set.tabular" ftype="tabular" /> |
154 <param name="header" value="True" /> | 153 <param name="header" value="True" /> |
155 <param name="selected_task" value="load" /> | 154 <param name="selected_task" value="load" /> |
156 <output name="outfile_predict" file="svc_prediction_result01.tabular" /> | 155 <output name="outfile_predict" file="svc_prediction_result01.tabular" /> |
157 </test> | 156 </test> |
158 <test> | 157 <test> |
159 <param name="infile_model" value="svc_model02" ftype="zip" /> | 158 <param name="infile_model" value="svc_model02" ftype="h5mlm" /> |
160 <param name="infile_data" value="test_set.tabular" ftype="tabular" /> | 159 <param name="infile_data" value="test_set.tabular" ftype="tabular" /> |
161 <param name="header" value="True" /> | 160 <param name="header" value="True" /> |
162 <param name="selected_task" value="load" /> | 161 <param name="selected_task" value="load" /> |
163 <output name="outfile_predict" file="svc_prediction_result02.tabular" /> | 162 <output name="outfile_predict" file="svc_prediction_result02.tabular" /> |
164 </test> | 163 </test> |
165 <test> | 164 <test> |
166 <param name="infile_model" value="svc_model03" ftype="zip" /> | 165 <param name="infile_model" value="svc_model03" ftype="h5mlm" /> |
167 <param name="infile_data" value="test_set.tabular" ftype="tabular" /> | 166 <param name="infile_data" value="test_set.tabular" ftype="tabular" /> |
168 <param name="header" value="True" /> | |
169 <param name="selected_task" value="load" /> | 167 <param name="selected_task" value="load" /> |
170 <output name="outfile_predict" file="svc_prediction_result03.tabular" /> | 168 <output name="outfile_predict" file="svc_prediction_result03.tabular" /> |
171 </test> | 169 </test> |
172 <!-- The following test is expected to fail, it is testing the whitelist/blacklist filtering. | 170 <!-- The following test is expected to fail, it is testing the whitelist/blacklist filtering. |
173 It loads a pickle with malicious content that we do not accept. --> | 171 It loads a pickle with malicious content that we do not accept. --> |
174 <test expect_failure="true"> | 172 <test expect_failure="true"> |
175 <param name="infile_model" value="pickle_blacklist" ftype="zip" /> | 173 <param name="infile_model" value="unsafe_model.h5mlm" /> |
176 <param name="infile_data" value="test_set.tabular" ftype="tabular" /> | 174 <param name="infile_data" value="test_set.tabular" ftype="tabular" /> |
177 <param name="header" value="True" /> | 175 <param name="header" value="True" /> |
178 <param name="selected_task" value="load" /> | 176 <param name="selected_task" value="load" /> |
179 </test> | 177 </test> |
180 </tests> | 178 </tests> |