import sys import os import math for file in os.listdir(os.getcwd()): if file.endswith('.feat'): name = file[:file.find('.feat')] outName = name + '.regfeat' outF = open(outName, 'w') feats = open(file, 'r') for line in feats: info = line[line.find('#'):].split() allItems = line.split() exampClass = allItems[0] #class value of the original example distVal = allItems[-1] #euclidean distance of the original example realTargetVal = (1 / (1 + math.pow((float(distVal) / 3), 2))) line = line.rstrip() newLine = str(realTargetVal) + ' ' + line[line.find('1:'):] + ' origClass ' + exampClass outF.write(newLine + '\n') outF.close()