Example #1
0
        ar.sort()
        flag = np.concatenate(([True], ar[1:] != ar[:-1]))
        return ar[flag]


###############################################################################
# end sklearn (http://scikit-learn.org/)
###############################################################################

if __name__ == '__main__':

    import UCRDatabase as ucr
    import pylab as pl

    # read data set from UCR database
    (testLabels, testSet), (trainLabels, trainSet) = ucr.read(3)
    rho = float(len(testSet)) / (len(trainSet) + len(testSet))

    # union of labels and items
    labels, items = ucr.merge(testLabels, testSet, trainLabels, trainSet)

    # check histograms
    sss = StratifiedShuffleSplit(labels, 15, test_size=rho, random_state=0)
    for train_index, test_index in sss:

        print("TRAIN:", train_index, "TEST:", test_index)

        pl.hist(labels)
        pl.hist(labels[train_index])
        pl.show()
Example #2
0
        ar.sort()
        flag = np.concatenate(([True], ar[1:] != ar[:-1]))
        return ar[flag]

###############################################################################
# end sklearn (http://scikit-learn.org/)
###############################################################################


if __name__ == '__main__': 

    import UCRDatabase as ucr
    import pylab as pl
    
    # read data set from UCR database
    (testLabels, testSet), (trainLabels, trainSet)  = ucr.read(3)
    rho = float(len(testSet))/(len(trainSet)+len(testSet))
    
    
    
    # union of labels and items
    labels, items = ucr.merge(testLabels, testSet, trainLabels, trainSet)
    
    # check histograms
    sss = StratifiedShuffleSplit(labels, 15, test_size=rho, random_state=0)
    for train_index, test_index in sss:
        
        print("TRAIN:", train_index, "TEST:", test_index)
        
        pl.hist(labels)
        pl.hist(labels[train_index])
Example #3
0
                print errors[-1]

    errs = list(sorted(errors, key=lambda x: x[0][0]))

    # pick only the best and take parameter in the "middle"
    best = filter(lambda (x, y): x[0] == errs[0][0][0], errs)
    best.sort(key=lambda (x, y): y[2])
    best = best[len(best) / 2]

    return best, errs


if __name__ == "__main__":

    import UCRDatabase as ucr
    import sys

    for number in [int(sys.argv[1])]:
        # read data set from UCR database
        (testLabels, testSet), (trainLabels, trainSet) = ucr.read(number)

        # z-normalize
        testSet = np.array(map(ucr.znormalize, testSet))
        trainSet = np.array(map(ucr.znormalize, trainSet))

        best_dtw = learn_cdtw(trainLabels, trainSet, False)[0]
        best_gem = learn_gem(trainLabels, trainSet, False, False)[0]

        print "dtw params", best_dtw
        print "gem params", best_gem
Example #4
0
                print errors[-1]
                
    errs = list(sorted(errors, key=lambda x: x[0][0]))
    
    # pick only the best and take parameter in the "middle"
    best = filter(lambda (x, y): x[0]==errs[0][0][0], errs)
    best.sort(key=lambda (x, y): y[2])
    best = best[len(best)/2]
   
    return best, errs


if __name__ == "__main__":

    import UCRDatabase as ucr
    import sys
    
    for number in [int(sys.argv[1])]:
        # read data set from UCR database
        (testLabels, testSet), (trainLabels, trainSet)  = ucr.read(number)
    
        # z-normalize
        testSet  = np.array(map(ucr.znormalize, testSet))
        trainSet = np.array(map(ucr.znormalize, trainSet))
    
        best_dtw = learn_cdtw(trainLabels, trainSet, False)[0]
        best_gem = learn_gem(trainLabels, trainSet, False, False)[0]

        print "dtw params", best_dtw
        print "gem params", best_gem