if __name__ == '__main__': # global parameters for distance measures (Manhatten/Euclidean, sym. gem) squared, symmetric = True, True # read dataset number and split number try: datasetN, splitN = int(sys.argv[1]), int(sys.argv[2]) except: raise Exception \ ("python2 1NNResampledTest.py datasetnumber(int) splitnumber(int)") # read the dataset (testLabels, testSet), (trainLabels, trainSet) = ucr.read(datasetN) # merge dataset labels, items = ucr.merge(testLabels, testSet, trainLabels, trainSet) # open file for the logging of results f = open("./results/dn_%s-sn_%s-sq_%s-sy_%s" % (datasetN, splitN, squared, symmetric), "w") # if splitN == 0 use UCR-split else use random split if splitN > 0: # determine split ratio from UCR canonical split and resample rho = float(len(trainSet))/(len(trainSet)+len(testSet)) sss = st.StratifiedShuffleSplit(labels, 500, test_size=rho, random_state=0) test_index, train_index = list(sss)[splitN-1]
bestlp, bestfulldtw, bestconstdtw, bestgem = None, None, None, None for line in f: if "BESTLP=" in line: bestlp=eval(line.split("=")[1]) if "BESTFULLDTW=" in line: bestfulldtw=eval(line.split("=")[1]) if "BESTCONSDTW=" in line: bestconsdtw=eval(line.split("=")[1]) if "BESTGEM=" in line: bestgem=eval(line.split("=")[1]) gainresult.append((bestconsdtw[2]-bestgem[2])) cdtwresult.append(bestconsdtw[2]) gemresult.append(bestgem[2]) eucresult.append(bestlp[2]) dtwresult.append(bestfulldtw[2]) if np.mean(gainresult) < 0: print datasetN, "\t", ucr.datasetName(datasetN), "%1.4f +/- %1.4f" % (np.mean(gainresult), np.std(gainresult)), \ " %1.4f" % (np.mean(gainresult)/np.std(gainresult)), else: print datasetN, "\t", ucr.datasetName(datasetN), " %1.4f +/- %1.4f" % (np.mean(gainresult),np.std(gainresult)), \ " %1.4f" % (np.mean(gainresult)/np.std(gainresult)), print " %1.4f +/- %1.4f" % (np.mean(cdtwresult), np.std(cdtwresult)), print " %1.4f +/- %1.4f" % (np.mean(gemresult), np.std(gemresult)), print " %1.4f +/- %1.4f" % (np.mean(eucresult), np.std(eucresult)), print " %1.4f +/- %1.4f" % (np.mean(dtwresult), np.std(dtwresult))
import utils.kNNClassifier as cl if __name__ == '__main__': # global parameters for distance measures (Manhatten/Euclidean, sym. gem) squared, symmetric = True, True # read dataset number and split number try: datasetN, splitN = int(sys.argv[1]), int(sys.argv[2]) except: raise Exception \ ("python2 1NNResampledTest.py datasetnumber(int) splitnumber(int)") # read the dataset (testLabels, testSet), (trainLabels, trainSet) = ucr.read(datasetN) # merge dataset labels, items = ucr.merge(testLabels, testSet, trainLabels, trainSet) # open file for the logging of results f = open( "./results/dn_%s-sn_%s-sq_%s-sy_%s" % (datasetN, splitN, squared, symmetric), "w") # if splitN == 0 use UCR-split else use random split if splitN > 0: # determine split ratio from UCR canonical split and resample rho = float(len(trainSet)) / (len(trainSet) + len(testSet)) sss = st.StratifiedShuffleSplit(labels, 500,
bestlp, bestfulldtw, bestconstdtw, bestgem = None, None, None, None for line in f: if "BESTLP=" in line: bestlp = eval(line.split("=")[1]) if "BESTFULLDTW=" in line: bestfulldtw = eval(line.split("=")[1]) if "BESTCONSDTW=" in line: bestconsdtw = eval(line.split("=")[1]) if "BESTGEM=" in line: bestgem = eval(line.split("=")[1]) gainresult.append((bestconsdtw[2] - bestgem[2])) cdtwresult.append(bestconsdtw[2]) gemresult.append(bestgem[2]) eucresult.append(bestlp[2]) dtwresult.append(bestfulldtw[2]) if np.mean(gainresult) < 0: print datasetN, "\t", ucr.datasetName(datasetN), "%1.4f +/- %1.4f" % (np.mean(gainresult), np.std(gainresult)), \ " %1.4f" % (np.mean(gainresult)/np.std(gainresult)), else: print datasetN, "\t", ucr.datasetName(datasetN), " %1.4f +/- %1.4f" % (np.mean(gainresult),np.std(gainresult)), \ " %1.4f" % (np.mean(gainresult)/np.std(gainresult)), print " %1.4f +/- %1.4f" % (np.mean(cdtwresult), np.std(cdtwresult)), print " %1.4f +/- %1.4f" % (np.mean(gemresult), np.std(gemresult)), print " %1.4f +/- %1.4f" % (np.mean(eucresult), np.std(eucresult)), print " %1.4f +/- %1.4f" % (np.mean(dtwresult), np.std(dtwresult))