<jupyter_start><jupyter_text><jupyter_code># IMPORTING REQUIRED LIBRARIES
from google.colab import drive
from collections import Counter
from shutil import copyfile
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import pickle
import zipfile
import os, sys

%load_ext autoreload
%matplotlib inline
# DOWNLOAD AND LOAD PREPROCESSED TRAINING DATA

%cd /content

!gdown --id 1j7Yk0-W9uonQiyyG2B9ZAw5jjZA-UeMS

import pickle
data_dict = pickle.load(open("challenge2017.pkl","rb"))
data = data_dict["data"]
labels = data_dict['label']
df = pd.DataFrame(data,columns=["ts"])\
      .assign(label = pd.Series(labels))#.replace({"N":"Normal","A":"Atrial Fibrillation","O":"Other Rhythm","~":"Noise"}))
df
df.label.value_counts()
# Download the repository of the model
%cd /content/
!git clone https://github.com/hsd1503/ENCASE

%cd /content/ENCASE/
!bash setup.sh

sys.path.append("/content/ENCASE/code")

# edit files that have dependency errors
%aimport -FeatureExtract -preprocess_data -dill
%autoreload 1 

with open("code/FeatureExtract.py","r+") as f:
  lines = f.readlines()
lines[22] = "#from BasicCLF import MyXGB\n"
lines[23] = "#from BasicCLF import MyLR\n"
lines[24] = "#from BasicCLF import MyRF\n"
with open("code/FeatureExtract.py","w+") as f:
  f.writelines(lines)

with open("code/preprocess_data.py","r+") as f:
  lines = f.readlines()
lines[11] = "#import hickle\n"
with open("code/preprocess_data.py","w+") as f:
  f.writelines(lines)

# make code/ a module
with open("code/__init__.py","w"):
  pass

%aimport code
with open('model/v2.5_xgb5_all_v2.pkl', 'rb') as f:
  model = pickle.load(f)
model
# model.predict(df["ts"].to_numpy()[0])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15158636897767333, 'fraction_numerical': 0.017038777908343124, 'mean_word_length': 5.575289575289576, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '315984', 'license': 'MIT', 'n_tokens_mistral': 665, 'n_tokens_neox': 640, 'n_words': 152, 'path': 'notebooks/simon-ENCASE.ipynb', 'repo_name': 'simonsanvil/ECG-classification-MLH', 'size': '1702'}