Skip to content

Instantly share code, notes, and snippets.

View csaguiar's full-sized avatar

Cristiano Aguiar csaguiar

View GitHub Profile
jupyter labextension install jupyterlab-plotly@1.2.0
jupyter lab build
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", "?"
]
# 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):
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
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,
model.fit(
X_train,
y_train,
batch_size=128,
epochs=15,
validation_data=(X_val, y_val)
)
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([
@csaguiar
csaguiar / install_xelatex_on_mac.txt
Last active September 10, 2022 18:34 — forked from peterhurford/install_xelatex_on_mac.txt
How to install latex and xelatex on Mac so that Jupyter "Download as PDF" will work
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
@csaguiar
csaguiar / data-1.py
Created August 31, 2023 13:49
Data module (load)
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
)