Пример #1
0
cwd = os.getcwd()
cwd = cwd[0:len(cwd) - 11]
os.chdir(cwd)

from import_data import get, coeff
from sklearn.model_selection import train_test_split, LeaveOneOut, KFold
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import confusion_matrix
from sklearn import metrics
import matplotlib.pyplot as plt
import numpy as np

#%% mostrar el rendimiento del sistema
if not os.path.exists('resultados/knn'):
    os.makedirs('resultados/knn')
data, target = get('data', random=2)
for i in range(3):

    random = i
    X_train, X_test, y_train, y_test = get("cross", random)
    k_range = range(1, 13, 2)
    acc = []
    acc1 = []
    print(i)
    sens = []
    pre = []
    for j in k_range:

        knn = KNeighborsClassifier(n_neighbors=j)
        knn.fit(X_train, y_train)
Пример #2
0
# dn = pd.concat([ds,dx], axis = 1)
# dn = pd.concat([dn,dw], axis = 1)
# [f, c] = dn.shape
# c = c - 1

# data  = np.zeros((f,c))
# target = dn.get('label').values
# columns = dn.columns

# for i in range(len(columns) - 1):

#     data[:,i] = dn.get(columns[i]).values
knn = KNeighborsClassifier(n_neighbors=5)

X_train, X_test, y_train, y_test = get('cross', 2, pca=True)

knn.fit(X_train, y_train)

print(knn.score(X_test, y_test))

X_train, X_test, y_train, y_test = get('cross', 2, pca=False)

knn.fit(X_train, y_train)

print(knn.score(X_test, y_test))
"""
test 3

X_train, X_test, y_train, y_test = get('cross', random = 2)
Пример #3
0
def app(**kwargs):
    start_args.update(kwargs)
    view_mode = start_args['view_mode']
    data_mode = start_args['data_mode']
    data_length = start_args['data_length']
    has_bool = start_args['has_bool']

    if data_mode == enums.DataMode.TEST and data_length is None:
        print("Please specify data_length!")
        return

    if enums.ViewMode.EEL in view_mode:
        import eel # pylint: disable=import-outside-toplevel
        import eel_func # pylint: disable=import-outside-toplevel
        eel.init("view")
        eel.start("index.html", port=0, block=False, close_callback=eel_func.close)
        eel.sleep(start_args['eel_start_delay'])

    if enums.ViewMode.GRAPH in view_mode:
        import plot_func # pylint: disable=import-outside-toplevel
        plot_func.init()

    if enums.ViewMode.CREATE_DATA in view_mode:
        import create_data # pylint: disable=import-outside-toplevel
        f = create_data.init(start_args['create_file_name'])

    if data_mode == enums.DataMode.SERIAL:
        import serial_func # pylint: disable=import-outside-toplevel
        ser = serial_func.start(start_args['port'], view_mode)
        if ser is None:
            sys.exit()
    elif data_mode == enums.DataMode.TEST:
        import import_data # pylint: disable=import-outside-toplevel
        init_data = import_data.init(start_args['import_file_name'])
        j = 0

    if data_mode == enums.DataMode.SERIAL:
        data = serial_func.get_data(ser)
        if data_length is None:
            data_length = (len(data) - 1) / 2 if has_bool else len(data) - 1
        while len(data) == 0:
            print(data)
            data = serial_func.get_data(ser)
    elif data_mode == enums.DataMode.TEST:
        data = import_data.get(data_length, j, init_data, has_bool)
        j += 1

    t, ys, tInt = np_func.init(data, start_args['size'], data_length)
    old_result = None

    if has_bool:
        bools = np_func.bool_init(data_length, start_args['size'])
        bools = np_func.set_bool_data(bools, data, data_length)
        data = data[:(data_length + 1)]
    while True:
        try:
            if data_mode == enums.DataMode.SERIAL:
                data = serial_func.get_data(ser)
            elif data_mode == enums.DataMode.TEST:
                data = import_data.get(data_length, j, init_data, has_bool)
                j += 1

            if has_bool:
                bools = np_func.set_bool_data(bools, data, data_length)
                data = data[:(data_length + 1)]

            if enums.ViewMode.TERMINAL in view_mode:
                print(data)
            if enums.ViewMode.CREATE_DATA in view_mode:
                create_data.write(f, data)
            if len(data) != data_length + 1:
                continue

            t, ys = np_func.set_data(data, t, ys, tInt, data_length)
            if enums.ViewMode.GRAPH in view_mode:
                plot_func.update(t, ys, data_length)
            if not enums.ViewMode.CREATE_DATA in view_mode:
                if has_bool:
                    result, draw = start_args['check_function'](t, ys, data_length, bools)
                else:
                    result, draw = start_args['check_function'](t, ys, data_length)
                if enums.ViewMode.TERMINAL in view_mode:
                    print("check result is ")
                    print(result)

            if not enums.ViewMode.CREATE_DATA in view_mode:
                if enums.ViewMode.EEL in view_mode:
                    if old_result is not None:
                        if not np_func.equal(result, old_result):
                            eel_func.render(result, data_length)
                    elif draw:
                        eel_func.render(result, data_length)
            
            old_result = np_func.copy(result)

        except KeyboardInterrupt:
            # FIX ME: 一発で抜けてくれない。matplotlibのtkinterが悪そう。
            if data_mode == enums.DataMode.SERIAL:
                ser.close()
            if enums.ViewMode.EEL in view_mode:
                eel.close_page() # pylint: disable=no-member
            if enums.ViewMode.CREATE_DATA in view_mode:
                f.close()

            break
Пример #4
0
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 15 17:20:44 2020

@author: Matador
"""
import os

cwd = os.getcwd()
cwd = cwd[0:len(cwd) - 11]
os.chdir(cwd)

from import_data import get
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
import matplotlib.pyplot as plt

data, target = get('data', 2, pca=True)
X_train, X_test, y_train, y_test = train_test_split(data,
                                                    target,
                                                    random_state=0,
                                                    test_size=0.2)

svm = SVC(degree=5).fit(X_train, y_train)
y_pred = svm.predict(X_test)

score = []
matrix_c = confusion_matrix(y_test, y_pred)
score.append(svm.score(X_test, y_test))
Пример #5
0
    
    axes = ax[i]
    axes.set_title(titles[i])
    axes.plot(time,variables[names[i]])
    axes.grid()
    axes.set_ylabel('voltage (mv)')

axes.set_xlabel('tiempo (seg)')
if not os.path.exists("info/orders"):
    os.makedirs("info/orders", exist_ok = True)

fig.savefig('info/orders/tratamiento_de_la_señal.png')

#%% generar la matriz de correlacion

data = get('Dataframe' , random = 2, pca = False)
plot_corr(data)

plt.savefig('info/orders/matriz_correlacion.png')
plt.close('all')

#%% generar grafica de dispersion

X_train, X_test, y_train, y_test = get('cross', random = 2, pca = False)

iris_dataframe = pd.DataFrame(X_train)

grr = pd.plotting.scatter_matrix(iris_dataframe, c=y_train, figsize=(15, 15), marker='o',
 hist_kwds={'bins': 20}, s=60, alpha=.8)

plt.savefig('info/orders/diagrama de dispersion.png')