<jupyter_start><jupyter_text>Feature extraction<jupyter_code># Loading Data
Adata = np.load("Adata.npz")["Adata"]
Y = np.load("Adata.npz")["Y"]
import matplotlib.pyplot as plt
%matplotlib inline
print(np.sum(Y<0)) #Checking number of "right" events
Adata.max()
ARight = np.average(Adata[0:112], axis = 0)
AFoot = np.average(Adata[112:], axis = 0)
fig = plt.figure()
f = plt.pcolormesh(ARight, vmin=-0.3, vmax=0.3)
plt.colorbar(f)
fig = plt.figure()
f = plt.pcolormesh(AFoot, vmin=-0.3, vmax=0.3)
plt.colorbar(f)<jupyter_output><empty_output><jupyter_text>Applying ML<jupyter_code>X = np.stack([np.concatenate([a[:, 1], a[:, 3]]) for a in Adata])
X.shape
import pandas as pd
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size = 0.2, random_state = 0)<jupyter_output><empty_output><jupyter_text>Logistic Regression<jupyter_code>from sklearn.linear_model import LogisticRegression
classifier = LogisticRegression(random_state = 0)
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
print(cm)
from sklearn.model_selection import cross_val_score
accuracies = cross_val_score(estimator = classifier, X = X_train, y = y_train, cv = 10)
print("Accuracy: {:.2f} %".format(accuracies.mean()*100))
print("Standard Deviation: {:.2f} %".format(accuracies.std()*100))<jupyter_output>Accuracy: 89.90 %
Standard Deviation: 7.87 %<jupyter_text>Kernal SVM<jupyter_code>from sklearn.svm import SVC
classifier = SVC(kernel = 'rbf', random_state = 0)
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
from sklearn.metrics import confusion_matrix, accuracy_score
cm = confusion_matrix(y_test, y_pred)
print(cm)
accuracy_score(y_test, y_pred)<jupyter_output>[[19  3]
 [ 2 21]]<jupyter_text>Random Forest<jupyter_code>from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier(n_estimators = 10, criterion = 'entropy', random_state = 0)
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
from sklearn.metrics import confusion_matrix, accuracy_score
cm = confusion_matrix(y_test, y_pred)
print(cm)
accuracy_score(y_test, y_pred)<jupyter_output>[[19  3]
 [ 2 21]]
{'fraction_non_alphanumeric': 0.13280562884784522, 'fraction_numerical': 0.025065963060686015, 'mean_word_length': 7.783783783783784, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 18, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '88393', 'license': 'MIT', 'n_tokens_mistral': 925, 'n_tokens_neox': 876, 'n_words': 171, 'path': '.ipynb_checkpoints/Democode1-checkpoint.ipynb', 'repo_name': 'sahilm75/EEG-based-classification', 'size': '2274'}