def obtain_test_data():
    ''' Obtain testing data for the classifier'''
    featureList = []
    tweets = []
    with open('../data/preprocessedTesting.data','rb') as f:   
        reader = csv.reader(f, delimiter='\t')
        l = list(reader)
    for row in l:
        sentiment = row[2]
        tweet = row[3]
        tweet = tweet[:-2]            # ignoring hashcounts
        featureVector = featureExtraction.getFeatureVector(tweet)
#        featureList.extend(featureVector)
        tweets.append((featureVector, sentiment))
    with open('../data/preprocessedTraining.data','rb') as f:   
        reader = csv.reader(f, delimiter='\t')
        l = list(reader)

    for row in l:
        sentiment = row[2]
        tweet = row[3]
        tweet = tweet[:-2]            # ignoring hashcounts
        featureVector = featureExtraction.getFeatureVector(tweet)
        featureList.extend(featureVector)

    # Remove featureList duplicates
    featureList = list(set(featureList))    
    result = featureExtraction.getFeatureListAndLabels(tweets, featureList)
    return result
Esempio n. 2
0
def obtain_test_data():
    ''' Obtain testing data for the classifier'''
    featureList = []
    tweets = []
    with open('../data/preprocessedTesting.data', 'rb') as f:
        reader = csv.reader(f, delimiter='\t')
        l = list(reader)
    for row in l:
        sentiment = row[2]
        tweet = row[3]
        tweet = tweet[:-2]  # ignoring hashcounts
        featureVector = featureExtraction.getFeatureVector(tweet)
        #        featureList.extend(featureVector)
        tweets.append((featureVector, sentiment))
    with open('../data/preprocessedTraining.data', 'rb') as f:
        reader = csv.reader(f, delimiter='\t')
        l = list(reader)

    for row in l:
        sentiment = row[2]
        tweet = row[3]
        tweet = tweet[:-2]  # ignoring hashcounts
        featureVector = featureExtraction.getFeatureVector(tweet)
        featureList.extend(featureVector)

    # Remove featureList duplicates
    featureList = list(set(featureList))
    result = featureExtraction.getFeatureListAndLabels(tweets, featureList)
    return result
Esempio n. 3
0
def getFeatures(folder):
    features = []
    with open(os.path.join(folder,"calibration.csv")) as csvfile:
        reader = csv.reader(csvfile)
        low = [ float(x) for x in reader.next()]
        high = [ float(x) for x in reader.next()]
        green = fe.colourFilter(tuple(low),tuple(high))
        low = [ float(x) for x in reader.next()]
        high = [ float(x) for x in reader.next()]
        blue = fe.colourFilter(tuple(low),tuple(high))

    for f in os.listdir(folder):
        if os.path.splitext(f)[1] == ".ppm":
            imbgr = cv2.imread(os.path.join(folder,f))
            hull = green.getColourHull(imbgr)

            features.append(fe.getFeatureVector(hull,['central']))
            hull = blue.getColourHull(imbgr)
            features.append(fe.getFeatureVector(hull,['central']))
    return features
#     if temp<minimumValue:
#         minimumValue=temp

isLog = True
featureMatrix = []
labelMatrix = []
featureVector = []
for index in csvData.keys():
    print(len(csvData[index]))
    if isLog:
        featureLog = './' + index + '_feature.csv'
        fl = open(featureLog, 'w')
    if True:
        actionLength = len(csvData[index])
        for i in range(actionLength):
            featureVector = getFeatureVector(csvData[index][i])

            # if len(featureVector)!=21:
            #     print('wrong length -- discarded')
            #     continue
            # print(len(featureVector))
            featureMatrix.append(featureVector)
            labelMatrix.append(labelSwitch(index))
            if isLog:
                for item in featureVector:
                    fl.write(str(item))
                    fl.write(',')
                fl.write(str(index))
                fl.write('\n')
        # if index=='fi':
        #     print(len(featureVector))
                # f = open(path, 'w')
                # for i in range(len(signalSegment[2])):
                #     f.write(str(signalSegment[0][i]))
                #     f.write(',')
                #     f.write(str(signalSegment[1][i]))
                #     f.write(',')
                #     f.write(str(signalSegment[2][i]))
                #     f.write('\n')
                #     f.close()
                #     f = open(path, 'a')

                # fl = open(featureLog, 'a')
                # pl = open(predictionLog, 'a')
                
                ### SVM
                featureVector = feature.getFeatureVector(signalSegment)
                featureArray = np.array(featureVector)
                featureArray = featureArray.reshape((1,len(featureVector)))
                featureArray = tools.standardise(featureArray,meanValue,stdValue)
                svmOutput = model.predict(featureArray)
                print(rr.printOutput(svmOutput))
                f=open('result.txt','w')
                f.write(str(svmOutput))
                f.close()


                ### ANN:
                '''featureVector = feature.getFeatureVector(signalSegment)
                print(len(featureVector))
                featureArray = np.array(featureVector)
                featureArray = featureArray.reshape((1,len(featureVector)))
Esempio n. 6
0
    labels = pickle.load(modelfile)
    running = deque([])

    with open(sys.argv[1]) as csvfile:
        reader = csv.reader(csvfile)
        low = [ float(x) for x in reader.next()]
        high = [ float(x) for x in reader.next()]

    green = fe.colourFilter(tuple(low),tuple(high))

    while 1:
        try:
            imbgr = fe.get_video()
            hull = green.getColourHull(imbgr)
            if len(hull):
                features = fe.getFeatureVector(hull,['central'])

                imbgrclass = model.predict([features])
                imbgrclass = imbgrclass[0]
                
                if len(running) < 10:
                    sign = imbgrclass
                    running.append(sign)
                else:
                    _ = running.popleft()
                    running.append(imbgrclass)
                    sign = median(running)

                sign = int(round(sign))

                letter = labels[sign]