<jupyter_start><jupyter_text>Decision Tree:<jupyter_code>import pandas as pd
import numpy as np
import os
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier, ExtraTreesClassifier
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
%%time
afd = pd.read_csv('/hdd/physio/af/hugedf5secfeatures.csv')
chd = pd.read_csv('/hdd/physio/af2/finaldfs/2017features.csv')
afd = chd
# x = afd[afd.columns[1:]].sample(15000)
# y = afd[afd.columns[0]]

# x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.2, random_state = 0)

_0 = afd[afd.af == 0].sample(n = 15000).reset_index(drop = True)
_1 = afd[afd.af == 1].sample(n = 15000).reset_index(drop = True)
train = pd.concat([_0, _1], axis = 0).sample(frac = 1).reset_index(drop = True)
x_train = train[train.columns[1:]]
y_train = train[train.columns[0]]
train = train.to_numpy()
_0 = afd[afd.af == 0].sample(n = 1000).reset_index(drop = True)
_1 = afd[afd.af == 1].sample(n = 1000).reset_index(drop = True)
test = pd.concat([_0, _1], axis = 0).sample(frac = 1).reset_index(drop = True)
x_test = test[test.columns[1:]]
y_test = test[test.columns[0]]
test = test.to_numpy()
# Support Vector Classifier

svc = SVC(random_state = 0)
svc.fit(x_train, y_train)

# Decision Tree Classifier

dt = DecisionTreeClassifier(random_state = 0)
dt.fit(x_train, y_train)

# Random Forest Classifier

rf = RandomForestClassifier(random_state = 0)
rf.fit(x_train, y_train)

# Extra Trees Classifier

et = ExtraTreesClassifier(random_state = 0)
et.fit(x_train, y_train)
# AFDB

for i, j in zip([svc, dt, rf, et], ["SVC", "DT", "RF", "ET"]):
    print(j + '\n' + classification_report(y_test, i.predict(x_test)))
# CHDB

for i, j in zip([svc, dt, rf, et], ["SVC", "DT", "RF", "ET"]):
    print(j + '\n' + classification_report(y_test, i.predict(x_test)))
import joblib

for i, j in zip([svc, dt, rf, et], ["SV", "DT", "RF", "ET"]):
    joblib.dump(i, "chdb_" + j + ".joblib")
for i, j in zip([svc, dt, rf, et], ["SV", "DT", "RF", "ET"]):
    print(j + ':\n' + str(np.round(os.path.getsize('chdb_' + j + '.joblib') / 1024 / 1024, 2))+"MB")
joblib.dump(svc, "RandomForest_100_trees.joblib") 
print(f"Random Forest size: {np.round(os.path.getsize('RandomForest_100_trees.joblib') / 1024 / 1024, 2) } MB")
dt = DecisionTreeClassifier()
dt.fit(x_train, y_train)
joblib.dump(dt, "RandomForest_100_trees.joblib") 
print(f"Random Forest size: {np.round(os.path.getsize('RandomForest_100_trees.joblib') / 1024 / 1024, 2) } MB")
d = pd.read_csv('/hdd/physio/af/finalscore.csv')
d
x_train, x_test, y_train, y_test = train_test_split(d[d.columns[1:]], d[d.columns[0]], test_size = 0.2, random_state = 0)
dt = DecisionTreeClassifier()
dt.fit(x_train, y_train)
pred = dt.predict(x_test)
print(classification_report(y_test, pred))<jupyter_output>precision    recall  f1-score   support

           0       0.88      0.89      0.89      3573
           1       0.89      0.88      0.89      3627

    accuracy                           0.89      7200
   macro avg       0.89      0.89      0.89      7200
weighted avg       0.89      0.89      0.89      7200
{'fraction_non_alphanumeric': 0.16142100342785914, 'fraction_numerical': 0.05110626363353069, 'mean_word_length': 3.9922239502332815, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '392266', 'license': 'MIT', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1274, 'n_words': 276, 'path': 'baseline.ipynb', 'repo_name': 'shanthakumar21/OptimizedArrhythmiaDetection', 'size': '3209'}