awk - How to convert sparse matrix data into WEKA's arff file format? -


i have sparse matrix .txt file, containing many numbers, 0's. here sample .txt file:

0 0 0.271178 0 0 0 0.538776 0 -0.631228 0 0 -0.501485 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.438643 0 0 0 0 0 0.287754 0 0 0 0 0 0 0 0 0 0 0 0 -0.498918 0 0 0 0 0 0.475561 0 0 0 0 0 0 0 0 0 0 0 0.370479 0 -0.300765 0 -1.10987 0 0 0.163637 0 0 0 0 0 0 0.304006 0 0.181697 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.261758 0 0 0 0.153415 0.17412 0 -0.129725 0 0.17598 0 0 0 0 0 0 0 0.56053 0 0 -0.211302 0 0 0 0 0 0 0 0.213277 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0698458 0 0 0 0.661972 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.376654 0 0 -0.604655 0 0 0 0 0 0.301025 0 0 -0.431324 0 0 -0.139445 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.404718 0.610013 -0.286108 0 0.46045 0 0 0 0 0 0 -0.193543 0 0 0 0 0 0 0 0.315063 0 0 -0.285598 0 0 0.206607 0

what need able go through file , convert data weka's recognizable file format, .arff, can run data-mining algorithms on data set. know how this? found few similar questions on stackoverflow similar problem, however, using script in awk language, , have never used .awk programs before, not programs run correctly. here links posts: 1 2

had @ the arff file format , questions linked.

you can embed awk programs inside shell script pretty easily, can this:

#!/bin/sh file=$1 awk '     begin {print "@relation something\n"}      {         data = sep = ""         (i=1; i<=nf; i++) {             if ($i != 0) {                 printf "@attribute a_%d numeric\n",                 data = data sep $i                 sep = ","             }         print ""         print "@data"         print data     } ' "$file" 

call script with: bash script.sh data_file , see

@relation  @attribute a_3 numeric @attribute a_7 numeric @attribute a_9 numeric @attribute a_12 numeric @attribute a_33 numeric @attribute a_39 numeric @attribute a_52 numeric @attribute a_58 numeric @attribute a_70 numeric @attribute a_72 numeric @attribute a_74 numeric @attribute a_77 numeric @attribute a_84 numeric @attribute a_86 numeric @attribute a_124 numeric @attribute a_128 numeric @attribute a_129 numeric @attribute a_131 numeric @attribute a_133 numeric @attribute a_141 numeric @attribute a_144 numeric @attribute a_152 numeric @attribute a_185 numeric @attribute a_189 numeric @attribute a_207 numeric @attribute a_210 numeric @attribute a_216 numeric @attribute a_219 numeric @attribute a_222 numeric @attribute a_238 numeric @attribute a_239 numeric @attribute a_240 numeric @attribute a_242 numeric @attribute a_249 numeric @attribute a_257 numeric @attribute a_260 numeric @attribute a_263 numeric  @data 0.271178,0.538776,-0.631228,-0.501485,0.438643,0.287754,-0.498918,0.475561,0.370479,-0.300765,-1.10987,0.163637,0.304006,0.181697,-0.261758,0.153415,0.17412,-0.129725,0.17598,0.56053,-0.211302,0.213277,0.0698458,0.661972,0.376654,-0.604655,0.301025,-0.431324,-0.139445,0.404718,0.610013,-0.286108,0.46045,-0.193543,0.315063,-0.285598,0.206607 

but you'll have let know if that's want output.


Comments

Popular posts from this blog

Why can rails not find a route created by a helper? -

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -