• 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

Questions/answers with a recent ECE grad

Ryne Rayburn