Skip to content
Snippets Groups Projects
Commit bc1e4158 authored by Nehemia Berhane Ghebremussie's avatar Nehemia Berhane Ghebremussie
Browse files

Delete SleepStageModels.ipynb

parent 0164d37e
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Installation
%% Cell type:code id: tags:
```
!pip install pyedflib
!pip install numpy
!pip install xmltodict
!pip install mne
!pip install tensorflow
!pip install pandas
!pip install scikit-learn
!pip install hampel
!pip install keras-tuner
```
%% Cell type:markdown id: tags:
# Prepare data
%% Cell type:code id: tags:
```
# Mount to google drive
from google.colab import drive
drive.mount('/content/drive')
```
%% Output
Mounted at /content/drive
%% Cell type:code id: tags:
```
# create Folders to store the data from google drive
import os
path_to_edf_files = 'edf_files'
if not os.path.exists(path_to_edf_files):
os.mkdir(path_to_edf_files)
path_to_annotations = 'annotations' #/content/drive/My Drive/annotations'
if not os.path.exists(path_to_annotations):
os.mkdir(path_to_annotations)
```
%% Cell type:code id: tags:
```
import shutil
# Be carefull not to delete folder by accident (always comment out after running it)
#shutil.rmtree(path_to_annotations)
```
%% Cell type:code id: tags:
```
import zipfile
# Info: All edf and annotation Files are stored in multiple zip_files in google drive.
# Root folder for edf files is path_to_all_edf_zip_folder
# Root folder for annotation files is path_to_all_annotation_zip_folder
path_to_all_edf_zip_folder = '/content/drive/My Drive/shhs2_edf_zip'
path_to_all_annotation_zip_folder = '/content/drive/My Drive/shhs2_annotation_zip'
# Unzip all files from path_to_all_edf_zip_folder into folder 'edf_files'
for filename in os.listdir(path_to_all_edf_zip_folder):
if filename.endswith('.zip'):
zip_path = os.path.join(path_to_all_edf_zip_folder, filename)
# Open ZIP-File
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
# extract files into path_to_edf_files
print(zip_path)
!unzip "$zip_path" -d "$path_to_edf_files"
print(f'Extrahiert: {filename}')
# Unzip all files from path_to_all_annotation_zip_folder into folder 'annotations'
for filename in os.listdir(path_to_all_annotation_zip_folder):
if filename.endswith('.zip'):
zip_path = os.path.join(path_to_all_annotation_zip_folder, filename)
# Open ZIP-File
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
# # extract files into path_to_annotations
print(zip_path)
!unzip "$zip_path" -d "$path_to_annotations"
print(f'Extrahiert: {filename}')
```
%% Cell type:markdown id: tags:
# Imports
%% Cell type:code id: tags:
```
import pyedflib
import numpy as np
import os
import xmltodict
import mne
import csv
import matplotlib.pyplot as plt
import pandas as pd
from scipy.signal import butter, lfilter, resample
from hampel import hampel
import numpy
import statistics
import pywt
from scipy.fft import fft, ifft, fftfreq
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import classification_report, cohen_kappa_score
from sklearn.preprocessing import LabelEncoder
import imblearn
from collections import Counter
from sklearn.datasets import make_classification
from matplotlib import pyplot
from numpy import where
from imblearn.over_sampling import SMOTE
from imblearn.under_sampling import RandomUnderSampler
from imblearn.pipeline import Pipeline
from sklearn.model_selection import train_test_split, RandomizedSearchCV, cross_val_predict, cross_val_score
from scipy.stats import skew, kurtosis
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv1D, MaxPooling1D, Flatten, Dense
from tensorflow.keras.preprocessing.sequence import pad_sequences
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report, cohen_kappa_score
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import precision_score
from sklearn.metrics import recall_score
from sklearn.metrics import f1_score
from sklearn.metrics import cohen_kappa_score, recall_score, f1_score, classification_report
from tensorflow.keras.optimizers import Adam
import kerastuner as kt
from kerastuner.tuners import RandomSearch
import traceback
import warnings
```
%% Cell type:markdown id: tags:
# Read available channels
%% Cell type:code id: tags:
```
for filename in os.listdir(path_to_edf_files):
data = mne.io.read_raw_edf(path_to_edf_files + "/" + filename)
raw_data = data.get_data()
channel_names = data.ch_names
print(channel_names)
break
# I only use PR, SaO2, Position and ABDO RES
```
%% Output
Extracting EDF parameters from /content/edf_files/shhs2-200646.edf...
EDF file detected
Setting channel info structure...
Creating raw.info structure...
['SaO2', 'H.R.', 'EEG(sec)', 'ECG', 'EMG', 'EOG(L)', 'EOG(R)', 'EEG', 'AIRFLOW', 'THOR RES', 'ABDO RES', 'POSITION', 'LIGHT', 'OX stat']
%% Cell type:markdown id: tags:
# Functions
%% Cell type:code id: tags:
```
def calculate_epochs_and_remainings(total_seconds, epoch_duration):
# Calculate the number of complete epochs
epochs_completed = total_seconds // epoch_duration
# Calculate the remaining seconds
remaining_seconds = total_seconds % epoch_duration
return epochs_completed, remaining_seconds
# Visualize signal
def visualize_signal(data, title):
"""
Visualize EEG signal data.
:param data: EEG signal data as a list or numpy array.
"""
plt.figure(figsize=(12, 6))
plt.plot(data)
plt.title(title)
plt.xlabel("Time (in seconds)")
plt.ylabel("Amplitude")
plt.show()
# Get the Min and Max Value of the singals
def getMinMaxValue(signalName):
if signalName == "SaO2":
return 90, 100
if signalName == "PR":
return 60, 100
if signalName == "POSITION":
return 0, 3
if signalName == "ABDO RES":
return -1, 1
# Use min max normalization
def normalize(value, min_val, max_val):
return (value - min_val) / (max_val - min_val)
# Get time domain features.
def time_domain_features(signal):
mean_val = np.mean(signal)
# Suppress warnings for this specific computation
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=RuntimeWarning)
kurtosis_val = kurtosis(signal)
skewness_val = skew(signal)
# Replace Nan Values with mean
if np.isnan(kurtosis_val):
kurtosis_val = mean_val
if np.isnan(skewness_val):
skewness_val = mean_val
std_dev = np.std(signal)
variance = np.var(signal)
return mean_val, std_dev, variance, kurtosis_val, skewness_val
```
%% Cell type:markdown id: tags:
# Read and Save Signals
%% Cell type:code id: tags:
```
# Signals
important_signals = {
'SaO2' : 0,
'PR': 1,
'ABDO RES': 10, # Abdomen has Sampling Rate 10
'POSITION': 11
}
# Variables
epoch_duration = 30
# Create and open the CSV file for writing the header
with open('signal_data.csv', mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['stage', 'signalName', 'std', 'mean', 'variance', 'kurtosis', 'skewness'])
# Iterate over EDF files in the directory
print(f"path_to_edf_files {path_to_edf_files}")
for filename in os.listdir(path_to_edf_files):
print(f"\n\nEDF-File {filename}")
path_to_edf = f"{path_to_edf_files}/{filename}"
# Create xml filename
filename_without_extension = filename.split(".")[0]
xml_filename = filename_without_extension + "-nsrr.xml"
with open(f"{path_to_annotations}/{xml_filename}") as fd:
doc = xmltodict.parse(fd.read())
# Create scored_events
annotations = doc['PSGAnnotation']
events = annotations['ScoredEvents']
scored_events = events['ScoredEvent']
# Get the start time and duration of each sleep stage
awake_times = []
lite_sleep_times = []
deep_sleep_times = []
rem_sleep_times = []
for element in scored_events:
if element['EventConcept'] == 'Wake|0':
awake_times.append({"start": element["Start"], "duration": element["Duration"]})
if element['EventConcept'] == 'Stage 1 sleep|1' or element['EventConcept'] == 'Stage 2 sleep|2':
lite_sleep_times.append({"start": element["Start"], "duration": element["Duration"]})
if element['EventConcept'] == 'Stage 3 sleep|3':
deep_sleep_times.append({"start": element["Start"], "duration": element["Duration"]})
if element['EventConcept'] == 'REM sleep|5':
rem_sleep_times.append({"start": element["Start"], "duration": element["Duration"]})
sleep_stages = {
"awake": awake_times,
"lite_sleep": lite_sleep_times,
"deep_sleep": deep_sleep_times,
"rem_sleep": rem_sleep_times
}
# Iterate over each EDF File
# Iterate over each Sleep Stage
# Iterate over each important Signal
# For each Sleep Stage get start and duration
try:
with pyedflib.EdfReader(path_to_edf) as f:
# Read the whole Signal and store in seperate csv File. This is explained in the bachelor Thesis.
whole_signal = f.readSignal(chn=signal_index)
for stage, array_data in sleep_stages.items():
for signal_name, signal_index in important_signals.items():
# get sample frequency
sample_frequency = f.getSampleFrequency(signal_index)
for element in array_data:
start_value = int(float(element['start']))
duration_value = int(float(element['duration']))
# Read the Signal
partial_signal_data = f.readSignal(chn=signal_index, start=start_value, n=duration_value)
# Preprocess
# Downsample if necessary
if sample_frequency != 1:
duration = duration_value
new_sample_frequency = 1
new_length = duration * new_sample_frequency
partial_signal_data = resample(partial_signal_data, new_length)
min_val, max_val = getMinMaxValue(signal_name)
filtered_signal_data = normalize(filtered_signal_data, min_val, max_val)
# remove outliner with Hampel-Filter
result = hampel(partial_signal_data, window_size=5, n_sigma=5.0)
filtered_signal_data = result.filtered_data
# Split Signal in 30 sec epochs
epochs, remainings = calculate_epochs_and_remainings(duration_value, epoch_duration)
# Read signal in 30 sec epochs
for i in range(epochs):
start_index = i * epoch_duration
end_index = start_index + epoch_duration
signal_data = filtered_signal_data[start_index:end_index]
# Feature extraction
mean_val, std_dev_val, variance_val, kurtosis_val, skewness_val = time_domain_features(signal_data)
# Write the data to the CSV file
with open('signal_data.csv', mode='a', newline='') as file:
writer = csv.writer(file)
writer.writerow([stage, signal_name, mean_val, std_dev_val, variance_val, kurtosis_val, skewness_val])
except Exception as e:
print(f"Error {filename} {e}")
traceback.print_exc()
continue
print("Finished")
```
%% Cell type:markdown id: tags:
# Preprocess
%% Cell type:code id: tags:
```
data = pd.read_csv('signal_data.csv')
data = data.dropna()
data = data[data['signalName'] != 'POSITION'] # Remove rows with signalName Position
data = data[data['signalName'] != 'ABDO RES'] # Remove rows with signalName ABDO RES
# Write the preprocessed data to a new CSV file
data.to_csv('preprocessed_signal_data.csv', index=False)
data_without_stage = data.drop('stage', axis=1)
amount_trained_features = len(list(data_without_stage.columns))
print(f"Amt Stages \n{data['stage'].unique()}")
# Visualize the quantity of each stage
class_counts = data['stage'].value_counts()
class_counts.plot(kind='bar')
plt.xlabel('Class')
plt.ylabel('Amount of entries')
plt.title('Original Class Distribution')
plt.show()
# Calculate CIF to check for imbalance dataset
total_entries = len(data)
min_stage_entries = data['stage'].value_counts().min()
cif = (total_entries / (2 * 4 * min_stage_entries))
print(f"CIF {cif}")
```
%% Cell type:code id: tags:
```
X = data[['signalName', 'std', 'mean', 'variance', 'kurtosis', 'skewness']]
signal_name_encoder = LabelEncoder()
stage_encoder = LabelEncoder()
X['signalName'] = signal_name_encoder.fit_transform(X['signalName'])
data['stage'] = stage_encoder.fit_transform(data['stage'])
y = data['stage']
print("Unique values in y after encoding:", np.unique(y))
over = SMOTE(sampling_strategy="not majority") # Oversample only the minority class / The number of samples in the different classes will be equalized
under = RandomUnderSampler(sampling_strategy='not minority') # Undersample only the majority class
steps = [('o', over), ('u', under)]
pipeline = Pipeline(steps=steps)
X, y = over.fit_resample(X, y) # ONLY USE OVERSMPLE
counter = Counter(y)
print(counter)
# Plotting the class distribution
plt.bar(counter.keys(), counter.values())
plt.xlabel('Class')
plt.ylabel('Amount of entries')
plt.title('Resampled Class Distribution')
plt.show()
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
```
%% Cell type:markdown id: tags:
# Machine Learning
%% Cell type:code id: tags:
```
# Random Forest
# Hyperparameter
'''param_distributions = {
'n_estimators': [50, 100],
'max_depth': [10, 20],
'min_samples_split': [10],
'min_samples_leaf': [6],
'bootstrap': [True]
}
# RandomizedSearchCV for RF
#Best parameters: {'n_estimators': 100, 'min_samples_split': 5, 'min_samples_leaf': 6, 'max_depth': 20, 'bootstrap': True}
#Best parameters: {'n_estimators': 100, 'min_samples_split': 10, 'min_samples_leaf': 6, 'max_depth': 20, 'bootstrap': True}
best_params = {'n_estimators': 100, 'min_samples_split': 10, 'min_samples_leaf': 6, 'max_depth': 20, 'bootstrap': True}
random_search = RandomizedSearchCV(
estimator=RandomForestClassifier(random_state=42, class_weight='balanced'),
param_distributions=param_distributions,
n_iter=5,
cv=5,
verbose=2,
random_state=42,
n_jobs=-1
)
random_search.fit(X_train, y_train)
best_params = random_search.best_params_
best_score = random_search.best_score_
print(f"Best parameters: {best_params}")
print(f"Best cross-validated score: {best_score}")
# Train
#rf_classifier = RandomForestClassifier(**best_params, random_state=42, class_weight='balanced') # With Hypertuning'''
# Without Hypertuning
rf_classifier = RandomForestClassifier(random_state=42)
rf_classifier.fit(X_train, y_train)
# Extract Feature Importance
feature_importances = rf_classifier.feature_importances_
features_df = pd.DataFrame({
'Feature': X.columns,
'Importance': feature_importances
}).sort_values(by='Importance', ascending=False)
print(features_df)
# Make predictions on the test set
y_pred = rf_classifier.predict(X_test)
# Evaluation
print("Classification report for RandomForestClassifier")
print(classification_report(y_test, y_pred))
macro_f1 = f1_score(y_test, y_pred, average='macro')
print(f"Macro-average F1 Score: {macro_f1}")
kappa = cohen_kappa_score(y_test, y_pred)
print(f"Cohen's Kappa: {kappa}")
```
%% Cell type:code id: tags:
```
# KNN
# Hyperparameter for KNN
param_knn = {
'n_neighbors': [3, 5, 7, 10, 15],
'weights': ['uniform', 'distance'],
'metric' : ['minkowski','euclidean','manhattan']
}
# RandomizedSearchCV for KNN
knn_search = RandomizedSearchCV(
estimator=KNeighborsClassifier(),
param_distributions=param_knn,
n_iter=5,
cv=5,
verbose=2,
random_state=42,
n_jobs=-1
)
# Fit to the training data
knn_search.fit(X_train, y_train)
# Retrieve the best parameters and score for KNN
best_params_knn = knn_search.best_params_
best_score_knn = knn_search.best_score_
# Output the results for KNN
print(f"Best parameters for KNN: {best_params_knn}")
print(f"Best cross-validated score for KNN: {best_score_knn}")
# Train KNN with the best parameters
knn_classifier = KNeighborsClassifier(**best_params_knn)
# Without Hyperparameter Tuning
#knn_classifier = KNeighborsClassifier()
knn_classifier.fit(X_train, y_train)
# Extrahieren der Feature Importance
feature_importances = rf_classifier.feature_importances_
features_df = pd.DataFrame({
'Feature': X.columns,
'Importance': feature_importances
}).sort_values(by='Importance', ascending=False)
print(features_df)
# Predict and evaluate KNN
y_pred_knn = knn_classifier.predict(X_test)
print("Classification report for KNeighborsClassifier:")
print(classification_report(y_test, y_pred_knn))
macro_f1 = f1_score(y_test, y_pred, average='macro')
print(f"Macro-average F1 Score: {macro_f1}")
kappa_knn = cohen_kappa_score(y_test, y_pred_knn)
print(f"Cohen's Kappa for KNN: {kappa_knn}")
```
%% Cell type:markdown id: tags:
# Deep Learning
%% Cell type:code id: tags:
```
# CNN
print("Unique labels in training set:", np.unique(y_train))
print("Unique labels in test set:", np.unique(y_test))
def build_model(hp):
model = Sequential()
hp_filters = hp.Int('filters', min_value=32, max_value=128, step=32)
hp_choice = hp.Choice('kernel_size', values=[3, 5])
model.add(Conv1D(filters=hp_filters,
kernel_size=hp_choice,
activation='relu',
input_shape=(amount_trained_features, 1)))
model.add(MaxPooling1D(2))
model.add(Flatten())
hp_unit_filter = hp.Int('units', min_value=64, max_value=128, step=32)
model.add(Dense(units=hp_unit_filter, activation='relu'))
model.add(Dense(len(np.unique(y)), activation='softmax'))
hp_learning_rate = hp.Choice('learning_rate', values = [1e-2, 1e-3])
opt = Adam(learning_rate=hp_learning_rate)
model.compile(optimizer=opt,loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
return model
tuner = RandomSearch(
hypermodel=build_model,
objective='val_accuracy',
max_trials=4,
executions_per_trial=1
)
tuner.search_space_summary()
# Start the search and get the best model
tuner.search(X_train, y_train, epochs=10, validation_split=0.2, batch_size=62)
best_hps = tuner.get_best_hyperparameters(num_trials=1)[0]
# Build the model with the best hyperparameters
model_cnn = build_model(best_hps)
model_cnn.fit(X_train, y_train, epochs=10, batch_size=62)
# Make predictions
y_pred_probs = model_cnn.predict(X_test)
y_pred_classes = np.argmax(y_pred_probs, axis=1)
test_loss, test_acc = model_cnn.evaluate(X_test, y_test, verbose=2)
# Evaluation
kappa = cohen_kappa_score(y_test, y_pred_classes)
print(f"Cohen's Kappa: {kappa}")
y_pred_labels = np.argmax(y_pred_probs, axis=1)
recall = recall_score(y_test, y_pred_labels, average='weighted')
print('Recall: %f' % recall)
f1 = f1_score(y_test, y_pred_labels, average='weighted')
print('F1 score: %f' % f1)
target_names = [str(name) for name in stage_encoder.inverse_transform([i for i in range(len(stage_encoder.classes_))])]
print(classification_report(y_test, y_pred_classes, target_names=target_names))
macro_f1 = f1_score(y_test, y_pred_classes, average='macro')
print(f"Macro-average F1 Score: {macro_f1}")
```
%% Cell type:code id: tags:
```
# LSTM
def build_model(hp):
model = Sequential([
LSTM(hp.Int('units', min_value=32, max_value=128, step=32),
activation='relu',
input_shape=(amount_trained_features, 1)),
Dense(len(np.unique(y)), activation='softmax')
])
model.compile(optimizer=Adam(hp.Float('learning_rate', min_value=1e-4, max_value=1e-2, sampling='LOG')),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
return model
tuner = RandomSearch(
hypermodel=build_model,
objective='val_accuracy',
max_trials=4,
executions_per_trial=1
)
tuner.search(X_train, y_train, epochs=10, validation_split=0.2, batch_size=62)
# Get the best hyperparameters
best_hps = tuner.get_best_hyperparameters(num_trials=1)[0]
print(f"Best Hyperparameters {best_hps}")
# Build the model with the best hyperparameters and train it on the data
model = tuner.hypermodel.build(best_hps)
history = model.fit(X_train, y_train, epochs=20, batch_size=64, validation_split=0.2)
# Extrahieren der Feature Importance
feature_importances = rf_classifier.feature_importances_
features_df = pd.DataFrame({
'Feature': X.columns,
'Importance': feature_importances
}).sort_values(by='Importance', ascending=False)
print(features_df)
y_pred_probs = model.predict(X_test)
y_pred_classes = np.argmax(y_pred_probs, axis=1)
test_loss, test_acc = model.evaluate(X_test, y_test, verbose=2)
# Evaluation
kappa = cohen_kappa_score(y_test, y_pred_classes)
print(f"Cohen's Kappa: {kappa}")
y_pred_labels = np.argmax(y_pred_probs, axis=1)
recall = recall_score(y_test, y_pred_labels, average='weighted')
print('Recall: %f' % recall)
f1 = f1_score(y_test, y_pred_labels, average='weighted')
print('F1 score: %f' % f1)
target_names = [str(name) for name in stage_encoder.inverse_transform([i for i in range(len(stage_encoder.classes_))])]
print(classification_report(y_test, y_pred_classes, target_names=target_names))
macro_f1 = f1_score(y_test, y_pred_classes, average='macro')
print(f"Macro-average F1 Score: {macro_f1}")
```
%% Output
Reloading Tuner from ./untitled_project/tuner0.json
Best Hyperparameters <keras_tuner.src.engine.hyperparameters.hyperparameters.HyperParameters object at 0x7bcfdcb078b0>
Epoch 1/20
24943/24943 [==============================] - 178s 7ms/step - loss: 1.1905 - accuracy: 0.4265 - val_loss: 1.1850 - val_accuracy: 0.4321
Epoch 2/20
24943/24943 [==============================] - 167s 7ms/step - loss: 1.1816 - accuracy: 0.4326 - val_loss: 1.1785 - val_accuracy: 0.4352
Epoch 3/20
24943/24943 [==============================] - 179s 7ms/step - loss: 1.1789 - accuracy: 0.4341 - val_loss: 1.1769 - val_accuracy: 0.4356
Epoch 4/20
24943/24943 [==============================] - 173s 7ms/step - loss: 1.1771 - accuracy: 0.4354 - val_loss: 1.1745 - val_accuracy: 0.4384
Epoch 5/20
24943/24943 [==============================] - 178s 7ms/step - loss: 1.1761 - accuracy: 0.4360 - val_loss: 1.1758 - val_accuracy: 0.4359
Epoch 6/20
24943/24943 [==============================] - 174s 7ms/step - loss: 1.1752 - accuracy: 0.4364 - val_loss: 1.1764 - val_accuracy: 0.4375
Epoch 7/20
24943/24943 [==============================] - 168s 7ms/step - loss: 1.1746 - accuracy: 0.4370 - val_loss: 1.1735 - val_accuracy: 0.4356
Epoch 8/20
24943/24943 [==============================] - 166s 7ms/step - loss: 1.1742 - accuracy: 0.4374 - val_loss: 1.1729 - val_accuracy: 0.4382
Epoch 9/20
24943/24943 [==============================] - 173s 7ms/step - loss: 1.1736 - accuracy: 0.4377 - val_loss: 1.1766 - val_accuracy: 0.4369
Epoch 10/20
24943/24943 [==============================] - 180s 7ms/step - loss: 1.1732 - accuracy: 0.4381 - val_loss: 1.1713 - val_accuracy: 0.4394
Epoch 11/20
24943/24943 [==============================] - 202s 8ms/step - loss: 1.1732 - accuracy: 0.4383 - val_loss: 1.1710 - val_accuracy: 0.4398
Epoch 12/20
24943/24943 [==============================] - 167s 7ms/step - loss: 1.1729 - accuracy: 0.4384 - val_loss: 1.1740 - val_accuracy: 0.4380
Epoch 13/20
24943/24943 [==============================] - 168s 7ms/step - loss: 1.1729 - accuracy: 0.4386 - val_loss: 1.1716 - val_accuracy: 0.4379
Epoch 14/20
24943/24943 [==============================] - 170s 7ms/step - loss: 1.1726 - accuracy: 0.4384 - val_loss: 1.1749 - val_accuracy: 0.4378
Epoch 15/20
24943/24943 [==============================] - 167s 7ms/step - loss: 1.1727 - accuracy: 0.4390 - val_loss: 1.1792 - val_accuracy: 0.4383
Epoch 16/20
24943/24943 [==============================] - 167s 7ms/step - loss: 1.1736 - accuracy: 0.4387 - val_loss: 1.1728 - val_accuracy: 0.4387
Epoch 17/20
24943/24943 [==============================] - 171s 7ms/step - loss: 1.1723 - accuracy: 0.4391 - val_loss: 1.1709 - val_accuracy: 0.4399
Epoch 18/20
24943/24943 [==============================] - 172s 7ms/step - loss: 1.1723 - accuracy: 0.4393 - val_loss: 1.1723 - val_accuracy: 0.4401
Epoch 19/20
24943/24943 [==============================] - 172s 7ms/step - loss: 1.1985 - accuracy: 0.4373 - val_loss: 1.1708 - val_accuracy: 0.4393
Epoch 20/20
24943/24943 [==============================] - 168s 7ms/step - loss: 1.1884 - accuracy: 0.4374 - val_loss: 1.1779 - val_accuracy: 0.4366
Feature Importance
1 std 0.249967
4 kurtosis 0.208756
2 mean 0.189652
5 skewness 0.175992
3 variance 0.169360
0 signalName 0.006272
15589/15589 [==============================] - 37s 2ms/step
15589/15589 - 32s - loss: 1.1777 - accuracy: 0.4358 - 32s/epoch - 2ms/step
Cohen's Kappa: 0.2478535374116223
Recall: 0.435759
F1 score: 0.412573
precision recall f1-score support
awake 0.78 0.50 0.61 124789
deep_sleep 0.39 0.64 0.49 124715
lite_sleep 0.34 0.09 0.14 124949
rem_sleep 0.35 0.51 0.42 124391
accuracy 0.44 498844
macro avg 0.46 0.44 0.41 498844
weighted avg 0.46 0.44 0.41 498844
Macro-average F1 Score: 0.4126748745582194
"\nCohen's Kappa: 0.2796082316913435\nRecall: 0.459339\nF1 score: 0.447196\n precision recall f1-score support\n\n awake 0.86 0.54 0.66 52649\n deep_sleep 0.38 0.75 0.50 52242\n lite_sleep 0.36 0.17 0.23 52690\n rem_sleep 0.41 0.38 0.40 52791\n\n accuracy 0.46 210372\n macro avg 0.50 0.46 0.45 210372\nweighted avg 0.50 0.46 0.45 210372\n\nUndersample\nCohen's Kappa: 0.25736372829306753\nRecall: 0.443274\nF1 score: 0.441652\n precision recall f1-score support\n\n awake 0.85 0.49 0.62 27280\n deep_sleep 0.38 0.66 0.49 27386\n lite_sleep 0.33 0.22 0.26 27088\n rem_sleep 0.39 0.41 0.40 27384\n\n accuracy 0.44 109138\n macro avg 0.49 0.44 0.44 109138\nweighted avg 0.49 0.44 0.44 109138\n\n\nFeature Importance\n1 std 0.387214\n2 mean 0.369977\n3 maxA 0.228155\n0 signalName 0.014655\n3411/3411 [==============================] - 8s 2ms/step\n3411/3411 - 8s - loss: 1.1881 - accuracy: 0.4272 - 8s/epoch - 2ms/step\nCohen's Kappa: 0.2356531000090908\nRecall: 0.427230\nF1 score: 0.400917\n precision recall f1-score support\n\n awake 0.87 0.46 0.60 27280\n deep_sleep 0.37 0.70 0.49 27386\n lite_sleep 0.28 0.06 0.10 27088\n rem_sleep 0.36 0.48 0.41 27384\n\n accuracy 0.43 109138\n macro avg 0.47 0.43 0.40 109138\nweighted avg 0.47 0.43 0.40 109138\n\nMacro-average F1 Score: 0.40030597312739447\n\n\n\n\n Feature Importance\n1 std 0.229538\n0 signalName 0.179083\n4 kurtosis 0.165762\n3 variance 0.152368\n2 mean 0.140518\n5 skewness 0.132731\n6822/6822 [==============================] - 23s 3ms/step\n6822/6822 - 18s - loss: 1.2765 - accuracy: 0.3565 - 18s/epoch - 3ms/step\nCohen's Kappa: 0.14185713040600867\nRecall: 0.356494\nF1 score: 0.350898\n precision recall f1-score support\n\n awake 0.43 0.52 0.47 54553\n deep_sleep 0.36 0.34 0.35 54210\n lite_sleep 0.28 0.35 0.31 54922\n rem_sleep 0.36 0.22 0.27 54591\n\n accuracy 0.36 218276\n macro avg 0.36 0.36 0.35 218276\nweighted avg 0.36 0.36 0.35 218276\n\nMacro-average F1 Score: 0.3509835323216871\n\n\nOHNE POS & ABDO\nFeature Importance\n1 std 0.317718\n2 mean 0.260348\n3 variance 0.166735\n4 kurtosis 0.133296\n5 skewness 0.105235\n0 signalName 0.016668\n3411/3411 [==============================] - 12s 3ms/step\n3411/3411 - 10s - loss: 1.1958 - accuracy: 0.4254 - 10s/epoch - 3ms/step\nCohen's Kappa: 0.23302260719925538\nRecall: 0.425370\nF1 score: 0.377417\n precision recall f1-score support\n\n awake 0.84 0.47 0.60 27280\n deep_sleep 0.38 0.67 0.48 27386\n lite_sleep 0.31 0.00 0.00 27088\n rem_sleep 0.34 0.56 0.42 27384\n\n accuracy 0.43 109138\n macro avg 0.47 0.42 0.38 109138\nweighted avg 0.47 0.43 0.38 109138\n\nMacro-average F1 Score: 0.3766119137787486\n"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment