<jupyter_start><jupyter_text>Importing Packges<jupyter_code>%matplotlib inline

import numpy as np

import joblib


import pandas as pd
import matplotlib.pyplot as plt
import math
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import GridSearchCV
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score, f1_score, recall_score,precision_score, classification_report, confusion_matrix
import collections
from sklearn.model_selection import cross_val_predict
from sklearn.metrics import precision_recall_curve, roc_curve
from sklearn.multiclass import OneVsRestClassifier
from sklearn.preprocessing import label_binarize

np.random.seed(1337)  # for reproducibility



from sklearn.ensemble import VotingClassifier<jupyter_output><empty_output><jupyter_text>Loading data (CTTD features and Labels)<jupyter_code>X_train = np.load('../data/train/X_train.npy') 

Y_train = np.load('../data/train/Y_train.npy')

X_test = np.load('../data/test/set1/X_test.npy')

Y_test = np.load('../data/test/set1/Y_test.npy')

X_test2 = np.load('../data/test/set2/X_test2.npy')

Y_test2 = np.load('../data/test/set2/Y_test2.npy')<jupyter_output><empty_output><jupyter_text>Scaling features<jupyter_code>scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.fit_transform(X_test)
X_test2 = scaler.fit_transform(X_test2)
print(X_train.shape)
print(Y_train.shape)

print(X_test.shape)
print(Y_test.shape)


print(X_test2.shape)
print(Y_test2.shape)<jupyter_output>(28368, 42)
(28368,)
(12168, 42)
(12168,)
(7040, 42)
(7040,)<jupyter_text>Loading models<jupyter_code>SVM_clf = joblib.load('../models/svm_emg_clf.pkl')

LR_clf = joblib.load('../models/LR_emg_clf.pkl')

RF_clf = joblib.load('../models/RF_emg_clf.pkl')

ET_clf = joblib.load('../models/ET_emg_clf.pkl')
estimators=[('LR',LR_clf),('SVM',SVM_clf),('RF',RF_clf),('ET',ET_clf)]
voting_clf=VotingClassifier(estimators,voting='soft')
voting_clf.fit(X_train,Y_train)
Y_predict = voting_clf.predict(X_test)
accuracy_score(Y_test, Y_predict)<jupyter_output><empty_output><jupyter_text>SVC class don't compute probability by default, so we have to train the model by setting the parameter probability=True.<jupyter_code>SVM_clf = SVC(kernel = 'rbf', C = 35.4, gamma= 'scale', class_weight = 'balanced',probability=True)
SVM_clf.fit(X_train, Y_train)<jupyter_output><empty_output><jupyter_text>Evaluation on Test set 1<jupyter_code>for clf in (LR_clf,SVM_clf,RF_clf,ET_clf,voting_clf):
    y_predict=clf.predict(X_test)
    print(clf.__class__.__name__,accuracy_score(Y_test, y_predict))<jupyter_output>LogisticRegression 0.9178994082840237
SVC 0.9231591058514136
RandomForestClassifier 0.9059007232084155
ExtraTreesClassifier 0.9275147928994083
VotingClassifier 0.9326101249178173<jupyter_text>Evaluation on Test set 2<jupyter_code>for clf in (LR_clf,SVM_clf,RF_clf,ET_clf,voting_clf):
    y_predict=clf.predict(X_test2)
    print(clf.__class__.__name__,accuracy_score(Y_test2, y_predict))<jupyter_output>LogisticRegression 0.9676136363636364
SVC 0.9762784090909091
RandomForestClassifier 0.953125
ExtraTreesClassifier 0.9627840909090909
VotingClassifier 0.9738636363636364
{'fraction_non_alphanumeric': 0.11520302171860246, 'fraction_numerical': 0.06861819326408561, 'mean_word_length': 8.002832861189802, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '508210', 'license': 'FSFAP', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1269, 'n_words': 184, 'path': 'notebooks/.ipynb_checkpoints/demo_voting_classifier-checkpoint.ipynb', 'repo_name': 'sumansamui/EMG_Signal_Classification', 'size': '3177'}