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
| CSV_URL = "https://raw.githubusercontent.com/mlflow/mlflow/master/tests/datasets/winequality-red.csv" | |
| def load_data() -> pd.DataFrame: | |
| try: | |
| data = pd.read_csv(CSV_URL, sep=";") | |
| except Exception as e: | |
| logger.exception( | |
| "Unable to download training & test CSV, " | |
| "check your internet connection. Error: %s", e | |
| ) |
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
| brew install pandoc | |
| brew tap homebrew/cask | |
| brew install basictex | |
| eval "$(/usr/libexec/path_helper)" | |
| # Update $PATH to include `/usr/local/texlive/2020basic/bin/x86_64-darwin` | |
| sudo tlmgr update --self | |
| sudo tlmgr install texliveonfly | |
| sudo tlmgr install xelatex | |
| sudo tlmgr install adjustbox | |
| sudo tlmgr install tcolorbox |
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
| sequence_size = X_train.shape[1] | |
| n_features = 1 | |
| n_subsequences = 4 | |
| subsequence_size = int(sequence_size / n_subsequences) | |
| # Reshaping to be (samples, subsequences, sequence, feature) | |
| X_train = X_train.reshape(-1, n_subsequences, subsequence_size, n_features) | |
| X_val = X_val.reshape(-1, n_subsequences, subsequence_size, n_features) | |
| cnn_lstm_model = Sequential([ |
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
| model.fit( | |
| X_train, | |
| y_train, | |
| batch_size=128, | |
| epochs=15, | |
| validation_data=(X_val, y_val) | |
| ) |
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
| from keras.models import Sequential | |
| from keras.layers import Conv1D, Flatten, Dense, Dropout | |
| from keras.optimizers import Adam | |
| sequence_size = X_train.shape[1] | |
| n_features = 1 | |
| model = Sequential([ | |
| Conv1D( | |
| filters=8, |
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 |
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
| # Function to classify beats in normal (0) / abnormal (1) | |
| def classify_beat(symbol): | |
| if symbol in abnormal_beats: | |
| return 1 | |
| elif symbol == "N" or symbol == ".": | |
| return 0 | |
| # Function to return a sequence surrounding a beat | |
| # with window_size for each side | |
| def get_sequence(signal, beat_loc, window_sec, fs): |
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
| invalid_beat = [ | |
| "[", "!", "]", "x", "(", ")", "p", "t", | |
| "u", "`", "'", "^", "|", "~", "+", "s", | |
| "T", "*", "D", "=", '"', "@" | |
| ] | |
| abnormal_beats = [ | |
| "L", "R", "B", "A", "a", "J", "S", "V", | |
| "r", "F", "e", "j", "n", "E", "/", "f", "Q", "?" | |
| ] |
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
| jupyter labextension install jupyterlab-plotly@1.2.0 | |
| jupyter lab build |