#NEWLINE# def loadSVMdata( self , fname ) : #NEWLINE# #INDENT# " read svm sparse format from file 'fname' (with labels only)\n            output: [attributes[], labels[]] " #NEWLINE# x = [ ] #NEWLINE# y = [ ] #NEWLINE# nFeatMax = 0 #NEWLINE# for line in open ( fname , 'r' ) . readlines ( ) : #NEWLINE# #INDENT# if ( not line ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# line = line . split ( ) #NEWLINE# label = float ( line [ 0 ] ) #NEWLINE# feat = [ ] #NEWLINE# nextidx = 1 #NEWLINE# for r in line [ 1 : ] : #NEWLINE# #INDENT# ( idx , val ) = r . split ( ':' ) #NEWLINE# idx = int ( idx ) #NEWLINE# for _ in range ( nextidx , idx ) : #NEWLINE# #INDENT# feat . append ( 0 ) #NEWLINE# #UNINDENT# feat . append ( float ( val ) ) #NEWLINE# nextidx = ( idx + 1 ) #NEWLINE# #UNINDENT# nFeat = len ( feat ) #NEWLINE# if ( nFeatMax < nFeat ) : #NEWLINE# #INDENT# nFeatMax = nFeat #NEWLINE# #UNINDENT# x . append ( feat ) #NEWLINE# y . append ( [ label ] ) #NEWLINE# self . nSamples += 1 #NEWLINE# #UNINDENT# for xi in x : #NEWLINE# #INDENT# while ( len ( xi ) < nFeatMax ) : #NEWLINE# #INDENT# xi . append ( 0.0 ) #NEWLINE# #UNINDENT# #UNINDENT# self . _setDataFields ( x , y )