Created
February 12, 2018 10:32
-
-
Save Radi4/1059185352b8e8022317c88c3172d18f to your computer and use it in GitHub Desktop.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 102, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from keras.models import Model\n", | |
"from keras.layers import Dense, Input, Flatten, Reshape\n", | |
"from keras.layers import Conv1D, MaxPooling1D, UpSampling1D\n", | |
"import numpy as np\n", | |
"import mne\n", | |
"import os\n", | |
"from sklearn.preprocessing import StandardScaler\n", | |
"from sklearn.model_selection import train_test_split\n", | |
"import h5py\n", | |
"from sklearn.metrics import mean_squared_error" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 103, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"eeg_dir = \"./data/new_data/\"\n", | |
"eeg_names = [x for x in os.listdir(eeg_dir) \n", | |
" if x[-5:] == \".vhdr\"]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Extracting parameters from ./data/new_data/0311_pre_eeg_popova.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Extracting parameters from ./data/new_data/2509_post_eeg_rinata.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 601549 = 0.000 ... 601.549 secs...\n", | |
"Extracting parameters from ./data/new_data/2510_post_eeg_osipova.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 602949 = 0.000 ... 602.949 secs...\n", | |
"Extracting parameters from ./data/new_data/0311_post_eeg_mazurova.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 603349 = 0.000 ... 603.349 secs...\n", | |
"Extracting parameters from ./data/new_data/3111_post_eeg_popova.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 612499 = 0.000 ... 612.499 secs...\n", | |
"Extracting parameters from ./data/new_data/1909_pre_eeg_eliseev.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 608399 = 0.000 ... 608.399 secs...\n", | |
"Extracting parameters from ./data/new_data/14071200_limanskaya_pre_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 604549 = 0.000 ... 604.549 secs...\n", | |
"Extracting parameters from ./data/new_data/3010_pre_eeg_suhareva.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 609899 = 0.000 ... 609.899 secs...\n", | |
"Extracting parameters from ./data/new_data/2809_pre_eeg_lukyanov.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 615899 = 0.000 ... 615.899 secs...\n", | |
"Extracting parameters from ./data/new_data/1207_shevchenko_post_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 602849 = 0.000 ... 602.849 secs...\n", | |
"Extracting parameters from ./data/new_data/0708_pre_eeg_krasovskaya.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 604049 = 0.000 ... 604.049 secs...\n", | |
"Extracting parameters from ./data/new_data/1207_shevchenko.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 2132749 = 0.000 ... 2132.749 secs...\n", | |
"Extracting parameters from ./data/new_data/0311_eeg_mazurova.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 2048799 = 0.000 ... 2048.799 secs...\n", | |
"Extracting parameters from ./data/new_data/3010_post_eeg_suhareva.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 605799 = 0.000 ... 605.799 secs...\n", | |
"Extracting parameters from ./data/new_data/2809_lukyanov.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 2085449 = 0.000 ... 2085.449 secs...\n", | |
"Extracting parameters from ./data/new_data/1608_post_eeg_polshina.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 632899 = 0.000 ... 632.899 secs...\n", | |
"Extracting parameters from ./data/new_data/17_11_pre_eeg_bachurina.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 602149 = 0.000 ... 602.149 secs...\n", | |
"Extracting parameters from ./data/new_data/3110_maistrenko.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 1914399 = 0.000 ... 1914.399 secs...\n", | |
"Extracting parameters from ./data/new_data/1509_pre_eeg_zvyagincev.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 606799 = 0.000 ... 606.799 secs...\n", | |
"Extracting parameters from ./data/new_data/2306_patrakeeva_post_eeg_rest.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 605199 = 0.000 ... 605.199 secs...\n", | |
"Extracting parameters from ./data/new_data/3010_eeg_suhareva.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 1572349 = 0.000 ... 1572.349 secs...\n", | |
"Extracting parameters from ./data/new_data/1909_eliseev.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 2093299 = 0.000 ... 2093.299 secs...\n", | |
"Extracting parameters from ./data/new_data/1909_post_eeg_eliseev.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 842249 = 0.000 ... 842.249 secs...\n", | |
"Extracting parameters from ./data/new_data/0307_STRELKOVA.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 2103349 = 0.000 ... 2103.349 secs...\n", | |
"Extracting parameters from ./data/new_data/3110_post_eeg_maistrenko.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 620899 = 0.000 ... 620.899 secs...\n", | |
"Extracting parameters from ./data/new_data/2606_patrakeeva_main_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 2106049 = 0.000 ... 2106.049 secs...\n", | |
"Extracting parameters from ./data/new_data/1608_rpre_eeg_polshina.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 629449 = 0.000 ... 629.449 secs...\n", | |
"Extracting parameters from ./data/new_data/2510_pre_eeg_osipova.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 604099 = 0.000 ... 604.099 secs...\n", | |
"Extracting parameters from ./data/new_data/0311_eeg_popova.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 1977699 = 0.000 ... 1977.699 secs...\n", | |
"Extracting parameters from ./data/new_data/0708_post_eeg_krasovskaya.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 614349 = 0.000 ... 614.349 secs...\n", | |
"Extracting parameters from ./data/new_data/14071200_limaskaya_post_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 604849 = 0.000 ... 604.849 secs...\n", | |
"Extracting parameters from ./data/new_data/2510_osipova.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 1958699 = 0.000 ... 1958.699 secs...\n", | |
"Extracting parameters from ./data/new_data/2809_post_eeg_lukyanov.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 602149 = 0.000 ... 602.149 secs...\n", | |
"Extracting parameters from ./data/new_data/1207_shevchenko_pre_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 614199 = 0.000 ... 614.199 secs...\n", | |
"Extracting parameters from ./data/new_data/0708_eeg_krasovskaya.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 2023149 = 0.000 ... 2023.149 secs...\n", | |
"Extracting parameters from ./data/new_data/2306_patrakeeva_pre_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Extracting parameters from ./data/new_data/0307_POST_EEG_sTRELKOVA.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 602149 = 0.000 ... 602.149 secs...\n", | |
"Extracting parameters from ./data/new_data/2509_eeg_rinata.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 2129299 = 0.000 ... 2129.299 secs...\n", | |
"Extracting parameters from ./data/new_data/2509-pre_eeg_rinata.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 724899 = 0.000 ... 724.899 secs...\n", | |
"Extracting parameters from ./data/new_data/17_11_post_eeg_bachurina.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 610499 = 0.000 ... 610.499 secs...\n", | |
"Extracting parameters from ./data/new_data/1608_eeg_polshina.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 1961799 = 0.000 ... 1961.799 secs...\n", | |
"Extracting parameters from ./data/new_data/311_pre_eeg_mazurova.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 604349 = 0.000 ... 604.349 secs...\n", | |
"Extracting parameters from ./data/new_data/1509_zvyagincev.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 1910849 = 0.000 ... 1910.849 secs...\n", | |
"Extracting parameters from ./data/new_data/1407_limanskaya_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 2406349 = 0.000 ... 2406.349 secs...\n", | |
"Extracting parameters from ./data/new_data/3110_pre_eeg_maistrenko.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 663199 = 0.000 ... 663.199 secs...\n", | |
"Extracting parameters from ./data/new_data/17_11_bachurina.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 1979549 = 0.000 ... 1979.549 secs...\n", | |
"Extracting parameters from ./data/new_data/0307_STRELKOVA_PRE_EEG.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 601999 = 0.000 ... 601.999 secs...\n", | |
"2\n" | |
] | |
} | |
], | |
"source": [ | |
"test_data = np.zeros((0,61))\n", | |
"\n", | |
"fail_count = 0\n", | |
"\n", | |
"for eeg_name in eeg_names:\n", | |
" try:\n", | |
" eeg_data = mne.io.read_raw_brainvision(eeg_dir + eeg_name, preload=True).get_data().T\n", | |
" test_data = np.append(test_data, eeg_data, axis = 0)\n", | |
" except OSError as e:\n", | |
" fail_count += 1\n", | |
" continue\n", | |
"\n", | |
"print(fail_count)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 23, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"eeg_dir = \"./data/resting_state/\"\n", | |
"eeg_names = [x for x in os.listdir(eeg_dir) \n", | |
" if x[-5:] == \".vhdr\"]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 28, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Extracting parameters from ./data/resting_state/pre_egg_petuhova3103.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 602749 = 0.000 ... 602.749 secs...\n", | |
"Extracting parameters from ./data/resting_state/2205_miloslavov_post_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 623249 = 0.000 ... 623.249 secs...\n", | |
"Extracting parameters from ./data/resting_state/kozunova_pre_eeg_2103.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 602849 = 0.000 ... 602.849 secs...\n", | |
"Extracting parameters from ./data/resting_state/2505_shirokova_post_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 606599 = 0.000 ... 606.599 secs...\n", | |
"Extracting parameters from ./data/resting_state/gorbacheva_03021300_rest_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 625249 = 0.000 ... 625.249 secs...\n", | |
"Extracting parameters from ./data/resting_state/200317_ivanova_pre_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 602099 = 0.000 ... 602.099 secs...\n", | |
"Extracting parameters from ./data/resting_state/2403_kutuzova_posteeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 604199 = 0.000 ... 604.199 secs...\n", | |
"Extracting parameters from ./data/resting_state/3103_petuhova_posteeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 630049 = 0.000 ... 630.049 secs...\n", | |
"Extracting parameters from ./data/resting_state/2103_glebko_posteeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 633899 = 0.000 ... 633.899 secs...\n", | |
"Extracting parameters from ./data/resting_state/glebko_2103_pre_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 643749 = 0.000 ... 643.749 secs...\n", | |
"Extracting parameters from ./data/resting_state/gorin_310117_rest_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 609999 = 0.000 ... 609.999 secs...\n", | |
"Extracting parameters from ./data/resting_state/zavrib_post_eeg_eyesopen15021500.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 321599 = 0.000 ... 321.599 secs...\n", | |
"Extracting parameters from ./data/resting_state/gorbacheva_03_02_2017_post_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 603949 = 0.000 ... 603.949 secs...\n", | |
"Extracting parameters from ./data/resting_state/post_eeg_tsoy_2504.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 604949 = 0.000 ... 604.949 secs...\n", | |
"Extracting parameters from ./data/resting_state/2403_kutuzova_pre_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 602849 = 0.000 ... 602.849 secs...\n", | |
"Extracting parameters from ./data/resting_state/2505_shirokova.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 604799 = 0.000 ... 604.799 secs...\n", | |
"Extracting parameters from ./data/resting_state/dagaev_post_rest_eeg_30011600.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 603799 = 0.000 ... 603.799 secs...\n", | |
"Extracting parameters from ./data/resting_state/zagirova_pre_eeg_2704.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 607549 = 0.000 ... 607.549 secs...\n", | |
"Extracting parameters from ./data/resting_state/08021400_post_eeg_shuhova.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 607199 = 0.000 ... 607.199 secs...\n", | |
"Extracting parameters from ./data/resting_state/2704_zagirova_post_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 604549 = 0.000 ... 604.549 secs...\n", | |
"Extracting parameters from ./data/resting_state/shuhova_08022017_rest_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 637949 = 0.000 ... 637.949 secs...\n", | |
"Extracting parameters from ./data/resting_state/zavrin_open_eyes_eeg_15021500.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 301999 = 0.000 ... 301.999 secs...\n", | |
"Extracting parameters from ./data/resting_state/zavrin_eyes_closed_eeg_15021500.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 302749 = 0.000 ... 302.749 secs...\n", | |
"Extracting parameters from ./data/resting_state/tsoy_pre_eeg_2504.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 652699 = 0.000 ... 652.699 secs...\n", | |
"Extracting parameters from ./data/resting_state/2003_ivanova_post_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 616599 = 0.000 ... 616.599 secs...\n", | |
"Extracting parameters from ./data/resting_state/bagaeva_post_eeg_13031500.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 603899 = 0.000 ... 603.899 secs...\n", | |
"Extracting parameters from ./data/resting_state/gorin_rest_eeg_post_31011200.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 603699 = 0.000 ... 603.699 secs...\n", | |
"Extracting parameters from ./data/resting_state/bagaeva_13021500_rest_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 603949 = 0.000 ... 603.949 secs...\n", | |
"Extracting parameters from ./data/resting_state/miloslavov_22_05_pre_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 603399 = 0.000 ... 603.399 secs...\n", | |
"Extracting parameters from ./data/resting_state/300120171600_dagaev_rest_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 615599 = 0.000 ... 615.599 secs...\n", | |
"Extracting parameters from ./data/resting_state/zavrin_15021500_eyesclosed_post_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 319299 = 0.000 ... 319.299 secs...\n", | |
"Extracting parameters from ./data/resting_state/2103_kozunova_post_eeg.vhdr...\n", | |
"Setting channel info structure...\n", | |
"Reading 0 ... 603199 = 0.000 ... 603.199 secs...\n" | |
] | |
} | |
], | |
"source": [ | |
"train_data = np.zeros((0,61))\n", | |
"data_splitters = []\n", | |
"last = 0\n", | |
"\n", | |
"for eeg_name in eeg_names:\n", | |
" eeg_data = mne.io.read_raw_brainvision(eeg_dir + eeg_name, preload=True).get_data().T\n", | |
" train_data = np.append(train_data, eeg_data, axis = 0)\n", | |
" last += eeg_data.shape[0] // 50\n", | |
" data_splitters.append(last)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 30, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(368220, 50, 61)" | |
] | |
}, | |
"execution_count": 30, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"scaler = StandardScaler()\n", | |
"train_data_scaled = scaler.fit_transform(train_data)\n", | |
"train_data_reshaped = train_data_scaled.reshape((train_data.shape[0] // 50, 50,61))\n", | |
"train_data_reshaped.shape" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 35, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(32,)" | |
] | |
}, | |
"execution_count": 35, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"data_splitters = np.array(data_splitters)\n", | |
"data_splitters.shape" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 37, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"X_train = train_data_reshaped[:data_splitters[11]]\n", | |
"X_val = train_data_reshaped[data_splitters[11]:]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 181, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def create_cnn_ae(encoding_dim = 30, batch_size = 50, channels_num = 61):\n", | |
" input_data = Input(shape=(batch_size, channels_num,))\n", | |
" \n", | |
" x = Conv1D(5, 3, padding='same')(input_data)\n", | |
" x = MaxPooling1D(padding='same')(x)\n", | |
" x = Flatten()(x)\n", | |
" encoded = Dense(encoding_dim * batch_size, activation='relu')(x)\n", | |
"\n", | |
" input_encoded = Input(shape=(encoding_dim * batch_size,))\n", | |
" x = Dense(batch_size // 2, activation='tanh')(input_encoded)\n", | |
" x = Reshape((batch_size // 2, 1))(x)\n", | |
" x = UpSampling1D()(x)\n", | |
" decoded = Conv1D(61, 3, padding='same')(x)\n", | |
"\n", | |
" encoder = Model(input_data, encoded, name=\"encoder\")\n", | |
" decoder = Model(input_encoded, decoded, name=\"decoder\")\n", | |
" autoencoder = Model(input_data, decoder(encoder(input_data)), name=\"autoencoder\")\n", | |
" autoencoder.compile(optimizer='adam', loss='mean_squared_error')\n", | |
" return encoder, decoder, autoencoder" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 182, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"encoder, decoder, autoencoder = create_cnn_ae()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 183, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Train on 142126 samples, validate on 226094 samples\n", | |
"Epoch 1/5\n", | |
"142126/142126 [==============================] - 25s - loss: 0.6456 - val_loss: 0.9812\n", | |
"Epoch 2/5\n", | |
"142126/142126 [==============================] - 24s - loss: 0.5934 - val_loss: 1.0319\n", | |
"Epoch 3/5\n", | |
"142126/142126 [==============================] - 24s - loss: 0.5910 - val_loss: 1.0532\n", | |
"Epoch 4/5\n", | |
"142126/142126 [==============================] - 24s - loss: 0.5908 - val_loss: 1.0585\n", | |
"Epoch 5/5\n", | |
"142126/142126 [==============================] - 24s - loss: 0.5906 - val_loss: 1.0527\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<keras.callbacks.History at 0x7efd82ed42b0>" | |
] | |
}, | |
"execution_count": 183, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"autoencoder.fit(X_train, X_train,\n", | |
" epochs=5,\n", | |
" batch_size=256,\n", | |
" shuffle=True,\n", | |
" validation_data=(X_val, X_val))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 166, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"test_data_scaled = scaler.fit_transform(test_data)\n", | |
"test_data_reshaped = test_data_scaled.reshape((test_data.shape[0] // 50, 50, 61))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 184, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"predict_data = autoencoder.predict(test_data_reshaped)\n", | |
"predict_data = predict_data.reshape(predict_data.shape[0] * 50, 61)\n", | |
"preict_data = scaler.inverse_transform(predict_data)\n", | |
"mse = mean_squared_error(test_data, predict_data)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 186, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.37431217851726606" | |
] | |
}, | |
"execution_count": 186, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"mse" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment