Last active
February 14, 2020 00:58
-
-
Save csaguiar/85f1372e45f049e7a75899c29ebe717a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| all_sequences = [] | |
| all_labels = [] | |
| window_sec = 3 | |
| subject_map = [] | |
| for subject in records: | |
| record = wfdb.rdrecord(f'mit-bih-arrhythmia-database-1.0.0/{subject}') | |
| annotation = wfdb.rdann(f'mit-bih-arrhythmia-database-1.0.0/{subject}', 'atr') | |
| atr_symbol = annotation.symbol | |
| atr_sample = annotation.sample | |
| fs = record.fs | |
| # Normalizing by mean and standard deviation | |
| scaler = StandardScaler() | |
| signal = scaler.fit_transform(record.p_signal) | |
| subject_labels = [] | |
| for i, i_sample in enumerate(atr_sample): | |
| label = classify_beat(atr_symbol[i]) | |
| sequence = get_sequence(signal, i_sample, window_sec, fs) | |
| if label is not None and sequence.size > 0: | |
| all_sequences.append(sequence) | |
| subject_labels.append(label) | |
| normal_percentage = sum(subject_labels) / len(subject_labels) | |
| subject_map.append({ | |
| "subject": subject, | |
| "percentage": normal_percentage, | |
| "num_seq": len(subject_labels), | |
| "start": len(all_labels), | |
| "end": len(all_labels)+len(subject_labels) | |
| }) | |
| all_labels.extend(subject_labels) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment