(New page: #!/usr/bin/python # Syntax: convert.py inputFile nData nFeature nOutput import sys import string import Numeric # Open input file inFile = open(sys.argv[1], 'r') # Print out the first l...)
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 +
* Script to convert LIBSVM data to FANN format
 +
<source lang="python">
 
#!/usr/bin/python
 
#!/usr/bin/python
  
Line 32: Line 34:
 
# Close file
 
# Close file
 
inFile.close()
 
inFile.close()
 +
</source>

Latest revision as of 03:18, 3 April 2008

  • Script to convert LIBSVM data to FANN format
#!/usr/bin/python
 
# Syntax: convert.py inputFile nData nFeature nOutput
import sys
import string
import Numeric
 
# Open input file
inFile = open(sys.argv[1], 'r')
 
# Print out the first line
print sys.argv[2], sys.argv[3], sys.argv[4]
 
for line in inFile:
    # Initialize feature vector to all zero
    feature = Numeric.zeros(int(sys.argv[3]))
    sline = string.split(line)
 
    # Iterate through and update the value for the feature
    for num in sline[2:]:
        snum = string.split(num,":")
        feature[int(snum[0])-1] = float(snum[1])
 
    # Print out the feature vector
    for a in feature:
        print a,
 
    # Print out the output
    print
    print sline[0]
 
# Close file
inFile.close()

Alumni Liaison

ECE462 Survivor

Seraj Dosenbach