def load_data_modeled(len_packet, num_of_packets=20): # ARTIFICIAL DATASET ListName = ['qRs_4', 'QS_5', 'rRs_8', 'RS_9'] artificial_t = [] artificial_signals = [] labels = [] for name in ListName: for i in range(10): data = utils.read_file('data/signal_' + name + '_' + str(i)) my_ecg = fb.deserialize(data) for j in range(num_of_packets): artificial_t.append(name) artificial_signals.append(my_ecg.packets[j]) labels.append(my_ecg.packets[j].label) artificial = fb.ECG.build_from_packets(artificial_signals) artificial_signals = artificial.build_packets(len_packet) artificial_signals = artificial.packets return artificial_signals, labels
def restore_model(name): return fb.deserialize(utils.read_file(name))
heart_rate = np.mean(heart_rate) labels = [name for x in rpeaks] my_ecg = fb.ECG(input_signal=ecg_signal, indicators=rpeaks, labels=labels, is_filtered=False) if name == 'qRs_4': offset = int(intervals / 7) elif name == 'QS_5': offset = int(intervals / 7) elif name == 'rRs_8': offset = int(intervals / 7) elif name == 'RS_9': offset = int(intervals / 7) else: offset = int(intervals / 7) offset = 40 my_ecg.packets = my_ecg.build_packets(offset) utils.write_file('data/signal_' + name + '_' + str(i), my_ecg.serialize()) list_of_signals = [] for name in ListName: for i in range(10): data = utils.read_file('data/signal_' + name + '_' + str(i)) list_of_signals.append(fb.deserialize(data)) for i in range(len(list_of_signals)): plt.plot(list_of_signals[i].packets[0].input_signal) plt.show() plt.close()
len_packet = 35 list_ecg = my_ecg.build_packets(len_packet) list_ecg = my_ecg.packets return list_ecg if __name__ == '__main__': list_ecg = main() rd = fb.RandomExtraction(offset=35) for sig in list_ecg: rd.evaluete_signal(sig.input_signal) utils.write_file('teste', rd.serialize()) data = utils.read_file('teste') rd = fb.deserialize(data) table = rd.get_table_erros() t = [] for p in list_ecg: t.append(p.label) t = ['qRs_4' if x == 2 else x for x in t] t = ['QS_5' if x == 14 else x for x in t] t = ['rRs_8' if x == 10 else x for x in t] t = ['RS_9' if x == 5 else x for x in t] t = ['artifact' if x in [12, 11, 1, 18, 6, 15, -1] else x for x in t] X = table.values X_train, X_test, y_train, y_test = train_test_split(X, t,
def default_load(name): return fb.deserialize(utils.read_file(name)).get_table_erros().values