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))
my_ecg = fb.ECG.build_from_packets(list_of_packets) 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,
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()
my_ecg.packets = lst_of_packets return my_ecg if __name__ == '__main__': __spec__ = "ModuleSpec(name='builtins', loader=<class '_frozen_importlib.BuiltinImporter'>)" results = main() error = results.get_errors_table() param1 = results.get_param_table() [signals, models, names, errors, types] = results.get_signals_and_models(normalized=False, only_best=True) data = results.serialize() utils.write_file('outfile', data) data = utils.read_file('outfile') c = fb.deserialize(data) # t = [] # for p in results.packets: # t.append(p.label) # # error['types'] = [int(x) for x in types] # X = error.values # # # X_train, X_test, y_train, y_test = train_test_split( # X, t, test_size=0.4, random_state=0) # #
def default_load(name): return fb.deserialize(utils.read_file(name)).get_table_erros().values