-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch .ipynb files to .py & add new function res_df into package
- Loading branch information
cma013
committed
Jan 29, 2021
1 parent
91ae76f
commit 795de01
Showing
17 changed files
with
372 additions
and
4 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
multi_participants 2/.idea/inspectionProfiles/profiles_settings.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import os | ||
from mind_reading_package import mind_reading as mr | ||
import pandas as pd | ||
|
||
# list all folders' name | ||
participants = os.listdir('path') | ||
|
||
# remove the 'cha' folder we don't need | ||
participants = participants.remove('cha') | ||
|
||
# create the initial dataframe | ||
df = pd.DataFrame(index = ['SVC', 'DTC', 'NB', 'NN']) | ||
|
||
for participant in participants: | ||
# iterate all the folders | ||
|
||
for file in os.listdir(participant): | ||
# iterate all files in every folder, find out the one end with 'Cong.csv' and 'Incong.csv' as input data | ||
|
||
if file.endswith('Cong.csv'): file1 = f"{participant}/{file}" | ||
if file.endswith('Incong.csv'): file2 = f"{participant}/{file}" | ||
|
||
# load in cong and incong data for them | ||
df1 = mr.load_data(file1) | ||
df2 = mr.load_data(file2) | ||
|
||
# concatenate such data | ||
data = mr.concatenate_data(df1, df2) | ||
|
||
# find trials to later separate | ||
trials_index = mr.find_trials(data) | ||
|
||
# separate trials | ||
trials = mr.separate_trials(data, trials_index) | ||
|
||
# create the label column | ||
labels = mr.create_binary_labels(data) | ||
|
||
# Go through each trial, reset the columns, we split from 100-300ms ((308th sample to 513th sample)) | ||
pro_trials = mr.process_trials(trials) | ||
|
||
# Find the mean across channels | ||
avg_trials = mr.average_trials(pro_trials) | ||
|
||
# concatenates the average trials dataframe with labels | ||
ml_df = mr.create_ml_df(avg_trials, labels) | ||
|
||
# train models | ||
X_train, X_test, y_train, y_test = mr.prepare_ml_df(ml_df) | ||
|
||
acc_svc, precision_svc = mr.train_svc(X_train, X_test, y_train, y_test) | ||
|
||
acc_dtc, precision_dtc = mr.train_dtc(X_train, X_test, y_train, y_test) | ||
|
||
acc_nb, precision_nb = mr.train_nb(X_train, X_test, y_train, y_test) | ||
|
||
acc_nn, precision_nn = mr.train_nn(64, X_train, X_test, y_train, y_test) | ||
|
||
# add every participant's accuracy together | ||
acc_list = [f"{acc_svc:.2f}", f"{acc_dtc:.2f}", f"{acc_nb:.2f}", f"{acc_nn:.2f}"] | ||
|
||
df = mr.res_df(df, acc_list, participant) | ||
|
||
# generate result .csv file | ||
df.to_csv('case_3_accuracy.csv') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import os | ||
from mind_reading_package import mind_reading as mr | ||
import pandas as pd | ||
|
||
# list all folders' name | ||
participants = os.listdir('path') | ||
|
||
# remove the 'cha' folder we don't need | ||
participants = participants.remove('cha') | ||
|
||
# create the initial dataframe | ||
df = pd.DataFrame(index = ['SVC', 'DTC', 'NB', 'NN']) | ||
|
||
for participant in participants: | ||
# iterate all the folders | ||
|
||
for file in os.listdir(participant): | ||
# iterate all files in every folder, find out the one end with 'Cong.csv' and 'Incong.csv' as input data | ||
|
||
if file.endswith('Cong.csv'): file1 = f"{participant}/{file}" | ||
if file.endswith('Incong.csv'): file2 = f"{participant}/{file}" | ||
|
||
# load in cong and incong data for them | ||
df1 = mr.load_data(file1) | ||
df2 = mr.load_data(file2) | ||
|
||
# concatenate such data | ||
data = mr.concatenate_data(df1, df2) | ||
|
||
# find trials to later separate | ||
trials_index = mr.find_trials(data) | ||
|
||
# separate trials | ||
trials = mr.separate_trials(data, trials_index) | ||
|
||
# create the label column | ||
labels = mr.create_binary_labels(data) | ||
|
||
# Go through each trial, reset the columns, we split from 100-300ms ((308th sample to 513th sample)) | ||
pro_trials = mr.process_trials(trials) | ||
|
||
# Find the mean across channels | ||
avg_trials = mr.average_trials(pro_trials) | ||
|
||
# concatenates the average trials dataframe with labels | ||
ml_df = mr.create_ml_df(avg_trials, labels) | ||
|
||
# train models | ||
X_train, X_test, y_train, y_test = mr.prepare_ml_df(ml_df) | ||
|
||
acc_svc, precision_svc = mr.train_svc(X_train, X_test, y_train, y_test) | ||
|
||
acc_dtc, precision_dtc = mr.train_dtc(X_train, X_test, y_train, y_test) | ||
|
||
acc_nb, precision_nb = mr.train_nb(X_train, X_test, y_train, y_test) | ||
|
||
acc_nn, precision_nn = mr.train_nn(64, X_train, X_test, y_train, y_test) | ||
|
||
# add every participant's precision together | ||
precision_list = [f"{precision_svc:.2f}", f"{precision_dtc:.2f}", f"{precision_nb:.2f}", f"{precision_nn:.2f}"] | ||
|
||
df = mr.res_df(df, precision_list, participant) | ||
|
||
# generate result .csv file | ||
df.to_csv('case_3_accuracy.csv') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import os | ||
from mind_reading_package import mind_reading as mr | ||
import pandas as pd | ||
|
||
# list all folders' name | ||
participants = os.listdir('path') | ||
|
||
# remove the 'cha' folder we don't need | ||
participants = participants.remove('cha') | ||
|
||
# create the initial dataframe | ||
df = pd.DataFrame(index = ['SVC', 'DTC', 'NB', 'NN']) | ||
|
||
for participant in participants: | ||
# iterate all the folders | ||
|
||
for file in os.listdir(participant): | ||
# iterate all files in every folder, find out the one end with 'Cong.csv' and 'Incong.csv' as input data | ||
|
||
if file.endswith('Cong.csv'): file1 = f"{participant}/{file}" | ||
if file.endswith('Incong.csv'): file2 = f"{participant}/{file}" | ||
|
||
# load in cong and incong data for them | ||
df1 = mr.load_data(file1) | ||
df2 = mr.load_data(file2) | ||
|
||
# concatenate such data | ||
data = mr.concatenate_data(df1, df2) | ||
|
||
# find trials to later separate | ||
trials_index = mr.find_trials(data) | ||
|
||
# separate trials | ||
trials = mr.separate_trials(data, trials_index) | ||
|
||
# create the label column | ||
labels = mr.create_multi_labels(data) | ||
|
||
# Go through each trial, reset the columns, we split from 100-300ms ((308th sample to 513th sample)) | ||
pro_trials = mr.process_trials(trials) | ||
|
||
# Find the mean across channels | ||
avg_trials = mr.average_trials(pro_trials) | ||
|
||
# concatenates the average trials dataframe with labels | ||
ml_df = mr.create_ml_df(avg_trials, labels) | ||
|
||
# train models | ||
X_train, X_test, y_train, y_test = mr.prepare_ml_df(ml_df) | ||
|
||
acc_svc, precision_svc = mr.train_svc_multi(X_train, X_test, y_train, y_test) | ||
|
||
acc_dtc, precision_dtc = mr.train_dtc_multi(X_train, X_test, y_train, y_test) | ||
|
||
acc_nb, precision_nb = mr.train_nb_multi(X_train, X_test, y_train, y_test) | ||
|
||
acc_nn, precision_nn = mr.train_nn_multi(64, X_train, X_test, y_train, y_test) | ||
|
||
# add every participant's accuracy together | ||
acc_list = [f"{acc_svc:.2f}", f"{acc_dtc:.2f}", f"{acc_nb:.2f}", f"{acc_nn:.2f}"] | ||
|
||
df = mr.res_df(df, acc_list, participant) | ||
|
||
# generate result .csv file | ||
df.to_csv('case_4_accuracy.csv') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import os | ||
from mind_reading_package import mind_reading as mr | ||
import pandas as pd | ||
|
||
# list all folders' name | ||
participants = os.listdir('path') | ||
|
||
# remove the 'cha' folder we don't need | ||
participants = participants.remove('cha') | ||
|
||
# create the initial dataframe | ||
df = pd.DataFrame(index = ['SVC', 'DTC', 'NB', 'NN']) | ||
|
||
for participant in participants: | ||
# iterate all the folders | ||
|
||
for file in os.listdir(participant): | ||
# iterate all files in every folder, find out the one end with 'Cong.csv' and 'Incong.csv' as input data | ||
|
||
if file.endswith('Cong.csv'): file1 = f"{participant}/{file}" | ||
if file.endswith('Incong.csv'): file2 = f"{participant}/{file}" | ||
|
||
# load in cong and incong data for them | ||
df1 = mr.load_data(file1) | ||
df2 = mr.load_data(file2) | ||
|
||
# concatenate such data | ||
data = mr.concatenate_data(df1, df2) | ||
|
||
# find trials to later separate | ||
trials_index = mr.find_trials(data) | ||
|
||
# separate trials | ||
trials = mr.separate_trials(data, trials_index) | ||
|
||
# create the label column | ||
labels = mr.create_multi_labels(data) | ||
|
||
# Go through each trial, reset the columns, we split from 100-300ms ((308th sample to 513th sample)) | ||
pro_trials = mr.process_trials(trials) | ||
|
||
# Find the mean across channels | ||
avg_trials = mr.average_trials(pro_trials) | ||
|
||
# concatenates the average trials dataframe with labels | ||
ml_df = mr.create_ml_df(avg_trials, labels) | ||
|
||
# train models | ||
X_train, X_test, y_train, y_test = mr.prepare_ml_df(ml_df) | ||
|
||
acc_svc, precision_svc = mr.train_svc_multi(X_train, X_test, y_train, y_test) | ||
|
||
acc_dtc, precision_dtc = mr.train_dtc_multi(X_train, X_test, y_train, y_test) | ||
|
||
acc_nb, precision_nb = mr.train_nb_multi(X_train, X_test, y_train, y_test) | ||
|
||
acc_nn, precision_nn = mr.train_nn_multi(64, X_train, X_test, y_train, y_test) | ||
|
||
# add every participant's precision together | ||
precision_list = [f"{precision_svc:.2f}", f"{precision_dtc:.2f}", f"{precision_nb:.2f}", f"{precision_nn:.2f}"] | ||
|
||
df = mr.res_df(df, precision_list, participant) | ||
|
||
# generate result .csv file | ||
df.to_csv('case_4_precision.csv') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion
1
multi_participants/case_3/multi_participants_case_3 (accuracy).ipynb
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.