(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...)
 
Line 1: Line 1:
 +
* Script to convert data from the LIBSVM to the FANN format
 +
<source lang="python">
 
#!/usr/bin/python
 
#!/usr/bin/python
  
Line 32: Line 34:
 
# Close file
 
# Close file
 
inFile.close()
 
inFile.close()
 +
</source>

Revision as of 04:17, 3 April 2008

  • Script to convert data from the LIBSVM to the 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

Abstract algebra continues the conceptual developments of linear algebra, on an even grander scale.

Dr. Paul Garrett