Esempio n. 1
0
def log_extract(dataSet):
    data, label = load_data(dataSet)
    m = len(data)
    n = len(data[0])
    for i in range(m):
        for j in range(n):
            distance = 10 ** (float(210 - data[i][j]) / 35)
            data[i][j] = int(float(data[i][j]) / distance)
    return list(data), label
Esempio n. 2
0
def cal_feature(dataSet):
    data, label = load_data(dataSet)
    data = np.array(data)
    y = np.array(label)
    x = []
    data_x = []
    for i in range(1, 17):
        x.append(data[y == str(i)])

    for k in range(16):
        for e in x[k]:
            e /= np.array(scale)[k]
            data_x.append(list(e))

    return data_x, label
Esempio n. 3
0
import serial
import os
from svmutil import *
from sklearn import neighbors
from visual import load_data

ser = serial.Serial('/dev/ttyUSB0', 38400, timeout=1)
y,x = svm_read_problem('train_ftrim')
m = svm_train(y,x, '-c 5')
j = 0
knn = neighbors.KNeighborsClassifier()
data, label = load_data('train_trim')
knn.fit(data,label)
while True:
    f = open('rssi', 'a')
    ser.write('bf1')
    line = ser.readline().strip()
    seg = line.split('#')
    seg = seg[1:]
    if len(seg) != 4: continue
    print line
    for i in range(len(seg)):
        e = seg[i][-4:]
        if i == 0: f.write('1 ')
        if i == 3:
            f.write('4:' + e[1:] + '\n')
            break
        f.write(str(i+1) + ':' + e)
    print 'ok'
    os.system('tail -n 1 rssi > sig')
    y, x = svm_read_problem('sig')