├── ECG_Analysis.pdf ├── README.md └── Signal Processing and Pattern Classification ├── PCG-2016-DNN ├── Hyper-parameter tuning │ ├── Classical machine learning algorithms.ipynb │ ├── Data.csv │ ├── Hyper-paramter-tuning-DNN.ipynb │ └── test.py ├── README.md ├── dnn │ ├── dnn1.py │ ├── dnn1test.py │ ├── dnn2.py │ ├── dnn2test.py │ ├── dnn3.py │ ├── dnn3test.py │ ├── dnn4.py │ ├── dnn4test.py │ ├── dnn5.py │ ├── dnn5test.py │ ├── dnn7.py │ ├── dnn7test.py │ └── kdd │ │ └── binary │ │ └── Training.csv ├── preprocess │ ├── __init__.py │ ├── model.pyc │ ├── parser.py │ ├── parser.pyc │ └── train_model.py └── requirements.txt ├── README.md ├── atrial-fibrillation ├── convert.py ├── gru │ ├── gru.py │ └── grutest.py ├── lstm │ ├── crossvalidation.py │ ├── lstm.py │ └── lstmtest.py └── rnn │ ├── rnn.py │ └── rnntest.py └── basics ├── Numpy.ipynb ├── Pandas.ipynb ├── data ├── places.h5 └── save.p ├── index.jpeg ├── pandastutorial.ipynb ├── pickleandh5py.ipynb ├── seabornTutorial.ipynb └── support └── titanic.csv /ECG_Analysis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinayakumarr/Signal-Processing-and-Pattern-Classification/38d4fa08d4d9d4cd01b15ad4ba0bce55100711cc/ECG_Analysis.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Signal-Processing-and-Pattern-Classification 2 | 3 | DOI 4 | 5 | Please cite the following papers, if you use the code as part of your research 6 | 7 | Real-Time Detection of Atrial Fibrillation from Short Time Single Lead ECG Traces Using Recurrent Neural Networks 8 | 9 | Instantaneous Heart Rate as a Robust Feature for Sleep Apnea Severity Detection using Deep Learning 10 | 11 | Single Sensor Techniques for Sleep Apnea Diagnosis using Deep Learning 12 | 13 | Anomaly detection in Phonocardiogram employing Deep learning 14 | 15 | Deep models for Phonocardiography (PCG) classification 16 | 17 | Atrial Fibrillation: Data set is from https://physionet.org/physiobank/database/afdb/ 18 | 19 | PCG-physionet: Data set is from https://physionet.org/challenge/2016/ 20 | 21 | Sleep Apnea: Data set is from https://www.physionet.org/physiobank/database/apnea-ecg/ 22 | 23 | heartsound - PCG: Data set is from http://www.peterjbentley.com/heartchallenge/ 24 | 25 | Other supported deep learning papers 26 | 27 | Evaluating Shallow and Deep Networks for Secure Shell (SSH)Traffic Analysis 28 | 29 | Evaluating Effectiveness of Shallow and Deep Networks to Intrusion Detection System 30 | 31 | Deep Android Malware Detection and Classification 32 | 33 | Long Short-Term Memory based Operation Log Anomaly Detection 34 | 35 | Deep Encrypted Text Categorization 36 | 37 | Applying Convolutional Neural Network for Network Intrusion Detection 38 | 39 | Secure Shell (SSH) Traffic Analysis with Flow based Features Using Shallow and Deep networks 40 | 41 | Applying Deep Learning Approaches for Network Traffic Prediction 42 | 43 | Evaluating Shallow and Deep Networks for Ransomware Detection and Classification 44 | 45 | Stock Price Prediction Using LSTM, RNN And CNN-Sliding Window Model 46 | 47 | Deep Power: Deep Learning Architectures for Power Quality Disturbances Classification 48 | 49 | DEFT 2017 - Texts Search @ TALN / RECITAL 2017: Deep Analysis of Opinion and Figurative language on Tweets in French 50 | 51 | Deep Stance and Gender Detection in Tweets on Catalan Independence@Ibereval 2017 52 | 53 | deepCybErNet at EmoInt-2017: Deep Emotion Intensities in Tweets 54 | 55 | Software Installation 56 | 57 | sudo apt-get install libatlas-base-dev gfortran python-dev 58 | 59 | sudo apt-get install python-pip 60 | 61 | sudo pip install --upgrade pip 62 | 63 | sudo pip install numpy 64 | 65 | sudo pip install scipy 66 | 67 | sudo pip install matplotlib 68 | 69 | Sudo pip install seaborn 70 | 71 | sudo pip install scikit-learn 72 | 73 | sudo pip install tensorflow 74 | 75 | sudo pip install theano 76 | 77 | sudo pip install keras 78 | 79 | sudo pip install pandas 80 | 81 | sudo pip install h5py 82 | 83 | sudo pip install jupyter 84 | 85 | sudo pip install ipython 86 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/Hyper-parameter tuning/Classical machine learning algorithms.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 27, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import numpy as np\n", 10 | "from sklearn.preprocessing import Normalizer\n", 11 | "from sklearn.model_selection import train_test_split\n", 12 | "from sklearn.linear_model import LogisticRegression\n", 13 | "from sklearn.naive_bayes import GaussianNB\n", 14 | "from sklearn.neighbors import KNeighborsClassifier\n", 15 | "from sklearn.tree import DecisionTreeClassifier\n", 16 | "from sklearn.metrics import (precision_score, recall_score,f1_score, accuracy_score,mean_squared_error,mean_absolute_error)\n", 17 | "from sklearn.ensemble import AdaBoostClassifier\n", 18 | "from sklearn.ensemble import RandomForestClassifier\n", 19 | "from sklearn.svm import SVC\n", 20 | "from sklearn import svm" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 14, 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [ 29 | "dataset = np.loadtxt(\"pima-indians-diabetes.csv\", delimiter=\",\")\n", 30 | "# split into input (X) and output (Y) variables\n", 31 | "X = dataset[:,0:8]\n", 32 | "Y = dataset[:,8]\n", 33 | "\n", 34 | "#normalize the data\n", 35 | "scaler = Normalizer().fit(X)\n", 36 | "X = scaler.transform(X)" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 17, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "traindata, testdata, trainlabel, testlabel = train_test_split(X, Y, test_size=0.33, random_state=42)\n", 46 | "expected = testlabel" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 19, 52 | "metadata": {}, 53 | "outputs": [ 54 | { 55 | "name": "stdout", 56 | "output_type": "stream", 57 | "text": [ 58 | "-----------------------------------------LR---------------------------------\n", 59 | "accuracy\n", 60 | "0.673\n", 61 | "precision\n", 62 | "0.588\n", 63 | "racall\n", 64 | "0.116\n", 65 | "f1score\n", 66 | "0.194\n" 67 | ] 68 | } 69 | ], 70 | "source": [ 71 | "print(\"-----------------------------------------LR---------------------------------\")\n", 72 | "model = LogisticRegression()\n", 73 | "model.fit(traindata, trainlabel)\n", 74 | "\n", 75 | "# make predictions\n", 76 | "expected = testlabel\n", 77 | "predicted = model.predict(testdata)\n", 78 | "\n", 79 | "y_train1 = expected\n", 80 | "y_pred = predicted\n", 81 | "accuracy = accuracy_score(y_train1, y_pred)\n", 82 | "recall = recall_score(y_train1, y_pred , average=\"binary\")\n", 83 | "precision = precision_score(y_train1, y_pred , average=\"binary\")\n", 84 | "f1 = f1_score(y_train1, y_pred, average=\"binary\")\n", 85 | "\n", 86 | "print(\"accuracy\")\n", 87 | "print(\"%.3f\" %accuracy)\n", 88 | "print(\"precision\")\n", 89 | "print(\"%.3f\" %precision)\n", 90 | "print(\"racall\")\n", 91 | "print(\"%.3f\" %recall)\n", 92 | "print(\"f1score\")\n", 93 | "print(\"%.3f\" %f1)\n" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": 20, 99 | "metadata": {}, 100 | "outputs": [ 101 | { 102 | "name": "stdout", 103 | "output_type": "stream", 104 | "text": [ 105 | "-----------------------------------------NB---------------------------------\n", 106 | "GaussianNB(priors=None)\n", 107 | "accuracy\n", 108 | "0.661\n", 109 | "precision\n", 110 | "0.500\n", 111 | "racall\n", 112 | "0.407\n", 113 | "f1score\n", 114 | "0.449\n" 115 | ] 116 | } 117 | ], 118 | "source": [ 119 | "# fit a Naive Bayes model to the data\n", 120 | "print(\"-----------------------------------------NB---------------------------------\")\n", 121 | "model = GaussianNB()\n", 122 | "model.fit(traindata, trainlabel)\n", 123 | "print(model)\n", 124 | "# make predictions\n", 125 | "expected = testlabel\n", 126 | "predicted = model.predict(testdata)\n", 127 | "\n", 128 | "y_train1 = expected\n", 129 | "y_pred = predicted\n", 130 | "accuracy = accuracy_score(y_train1, y_pred)\n", 131 | "recall = recall_score(y_train1, y_pred , average=\"binary\")\n", 132 | "precision = precision_score(y_train1, y_pred , average=\"binary\")\n", 133 | "f1 = f1_score(y_train1, y_pred, average=\"binary\")\n", 134 | "\n", 135 | "print(\"accuracy\")\n", 136 | "print(\"%.3f\" %accuracy)\n", 137 | "print(\"precision\")\n", 138 | "print(\"%.3f\" %precision)\n", 139 | "print(\"racall\")\n", 140 | "print(\"%.3f\" %recall)\n", 141 | "print(\"f1score\")\n", 142 | "print(\"%.3f\" %f1)" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 21, 148 | "metadata": {}, 149 | "outputs": [ 150 | { 151 | "name": "stdout", 152 | "output_type": "stream", 153 | "text": [ 154 | "-----------------------------------------KNN---------------------------------\n", 155 | "KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',\n", 156 | " metric_params=None, n_jobs=1, n_neighbors=5, p=2,\n", 157 | " weights='uniform')\n", 158 | "----------------------------------------------\n", 159 | "accuracy\n", 160 | "0.693\n", 161 | "precision\n", 162 | "0.559\n", 163 | "racall\n", 164 | "0.442\n", 165 | "f1score\n", 166 | "0.494\n" 167 | ] 168 | } 169 | ], 170 | "source": [ 171 | "# fit a k-nearest neighbor model to the data\n", 172 | "print(\"-----------------------------------------KNN---------------------------------\")\n", 173 | "model = KNeighborsClassifier()\n", 174 | "model.fit(traindata, trainlabel)\n", 175 | "print(model)\n", 176 | "# make predictions\n", 177 | "expected = testlabel\n", 178 | "predicted = model.predict(testdata)\n", 179 | "# summarize the fit of the model\n", 180 | "\n", 181 | "y_train1 = expected\n", 182 | "y_pred = predicted\n", 183 | "accuracy = accuracy_score(y_train1, y_pred)\n", 184 | "recall = recall_score(y_train1, y_pred , average=\"binary\")\n", 185 | "precision = precision_score(y_train1, y_pred , average=\"binary\")\n", 186 | "f1 = f1_score(y_train1, y_pred, average=\"binary\")\n", 187 | "\n", 188 | "\n", 189 | "print(\"----------------------------------------------\")\n", 190 | "print(\"accuracy\")\n", 191 | "print(\"%.3f\" %accuracy)\n", 192 | "print(\"precision\")\n", 193 | "print(\"%.3f\" %precision)\n", 194 | "print(\"racall\")\n", 195 | "print(\"%.3f\" %recall)\n", 196 | "print(\"f1score\")\n", 197 | "print(\"%.3f\" %f1)" 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": 22, 203 | "metadata": {}, 204 | "outputs": [ 205 | { 206 | "name": "stdout", 207 | "output_type": "stream", 208 | "text": [ 209 | "-----------------------------------------DT---------------------------------\n", 210 | "DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=None,\n", 211 | " max_features=None, max_leaf_nodes=None,\n", 212 | " min_impurity_decrease=0.0, min_impurity_split=None,\n", 213 | " min_samples_leaf=1, min_samples_split=2,\n", 214 | " min_weight_fraction_leaf=0.0, presort=False, random_state=None,\n", 215 | " splitter='best')\n", 216 | "----------------------------------------------\n", 217 | "accuracy\n", 218 | "0.634\n", 219 | "precision\n", 220 | "0.457\n", 221 | "racall\n", 222 | "0.430\n", 223 | "f1score\n", 224 | "0.443\n" 225 | ] 226 | } 227 | ], 228 | "source": [ 229 | "print(\"-----------------------------------------DT---------------------------------\")\n", 230 | "\n", 231 | "model = DecisionTreeClassifier()\n", 232 | "model.fit(traindata, trainlabel)\n", 233 | "print(model)\n", 234 | "# make predictions\n", 235 | "expected = testlabel\n", 236 | "predicted = model.predict(testdata)\n", 237 | "# summarize the fit of the model\n", 238 | "\n", 239 | "y_train1 = expected\n", 240 | "y_pred = predicted\n", 241 | "accuracy = accuracy_score(y_train1, y_pred)\n", 242 | "recall = recall_score(y_train1, y_pred , average=\"binary\")\n", 243 | "precision = precision_score(y_train1, y_pred , average=\"binary\")\n", 244 | "f1 = f1_score(y_train1, y_pred, average=\"binary\")\n", 245 | "\n", 246 | "\n", 247 | "print(\"----------------------------------------------\")\n", 248 | "print(\"accuracy\")\n", 249 | "print(\"%.3f\" %accuracy)\n", 250 | "print(\"precision\")\n", 251 | "print(\"%.3f\" %precision)\n", 252 | "print(\"racall\")\n", 253 | "print(\"%.3f\" %recall)\n", 254 | "print(\"f1score\")\n", 255 | "print(\"%.3f\" %f1)\n" 256 | ] 257 | }, 258 | { 259 | "cell_type": "code", 260 | "execution_count": 23, 261 | "metadata": {}, 262 | "outputs": [ 263 | { 264 | "name": "stdout", 265 | "output_type": "stream", 266 | "text": [ 267 | "-----------------------------------------Adaboost---------------------------------\n", 268 | "----------------------------------------------\n", 269 | "accuracy\n", 270 | "0.650\n", 271 | "precision\n", 272 | "0.475\n", 273 | "racall\n", 274 | "0.337\n", 275 | "f1score\n", 276 | "0.395\n" 277 | ] 278 | } 279 | ], 280 | "source": [ 281 | "print(\"-----------------------------------------Adaboost---------------------------------\")\n", 282 | "\n", 283 | "model = AdaBoostClassifier(n_estimators=100)\n", 284 | "model.fit(traindata, trainlabel)\n", 285 | "\n", 286 | "# make predictions\n", 287 | "expected = testlabel\n", 288 | "predicted = model.predict(testdata)\n", 289 | "# summarize the fit of the model\n", 290 | "\n", 291 | "y_train1 = expected\n", 292 | "y_pred = predicted\n", 293 | "accuracy = accuracy_score(y_train1, y_pred)\n", 294 | "recall = recall_score(y_train1, y_pred , average=\"binary\")\n", 295 | "precision = precision_score(y_train1, y_pred , average=\"binary\")\n", 296 | "f1 = f1_score(y_train1, y_pred, average=\"binary\")\n", 297 | "\n", 298 | "\n", 299 | "print(\"----------------------------------------------\")\n", 300 | "print(\"accuracy\")\n", 301 | "print(\"%.3f\" %accuracy)\n", 302 | "print(\"precision\")\n", 303 | "print(\"%.3f\" %precision)\n", 304 | "print(\"racall\")\n", 305 | "print(\"%.3f\" %recall)\n", 306 | "print(\"f1score\")\n", 307 | "print(\"%.3f\" %f1)\n" 308 | ] 309 | }, 310 | { 311 | "cell_type": "code", 312 | "execution_count": 24, 313 | "metadata": {}, 314 | "outputs": [ 315 | { 316 | "name": "stdout", 317 | "output_type": "stream", 318 | "text": [ 319 | "--------------------------------------RF--------------------------------------\n", 320 | "----------------------------------------------\n", 321 | "accuracy\n", 322 | "0.677\n", 323 | "precision\n", 324 | "0.532\n", 325 | "racall\n", 326 | "0.384\n", 327 | "f1score\n", 328 | "0.446\n" 329 | ] 330 | } 331 | ], 332 | "source": [ 333 | "model = RandomForestClassifier(n_estimators=100)\n", 334 | "model = model.fit(traindata, trainlabel)\n", 335 | "\n", 336 | "# make predictions\n", 337 | "expected = testlabel\n", 338 | "predicted = model.predict(testdata)\n", 339 | "# summarize the fit of the model\n", 340 | "\n", 341 | "print(\"--------------------------------------RF--------------------------------------\")\n", 342 | "\n", 343 | "y_train1 = expected\n", 344 | "y_pred = predicted\n", 345 | "accuracy = accuracy_score(y_train1, y_pred)\n", 346 | "recall = recall_score(y_train1, y_pred , average=\"binary\")\n", 347 | "precision = precision_score(y_train1, y_pred , average=\"binary\")\n", 348 | "f1 = f1_score(y_train1, y_pred, average=\"binary\")\n", 349 | "\n", 350 | "\n", 351 | "print(\"----------------------------------------------\")\n", 352 | "print(\"accuracy\")\n", 353 | "print(\"%.3f\" %accuracy)\n", 354 | "print(\"precision\")\n", 355 | "print(\"%.3f\" %precision)\n", 356 | "print(\"racall\")\n", 357 | "print(\"%.3f\" %recall)\n", 358 | "print(\"f1score\")\n", 359 | "print(\"%.3f\" %f1)" 360 | ] 361 | }, 362 | { 363 | "cell_type": "code", 364 | "execution_count": 28, 365 | "metadata": {}, 366 | "outputs": [ 367 | { 368 | "name": "stdout", 369 | "output_type": "stream", 370 | "text": [ 371 | "--------------------------------------SVMrbf--------------------------------------\n", 372 | "accuracy\n", 373 | "0.661\n", 374 | "precision\n", 375 | "0.000\n", 376 | "racall\n", 377 | "0.000\n", 378 | "f1score\n", 379 | "0.000\n" 380 | ] 381 | }, 382 | { 383 | "name": "stderr", 384 | "output_type": "stream", 385 | "text": [ 386 | "/usr/local/lib/python2.7/dist-packages/sklearn/metrics/classification.py:1135: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 due to no predicted samples.\n", 387 | " 'precision', 'predicted', average, warn_for)\n", 388 | "/usr/local/lib/python2.7/dist-packages/sklearn/metrics/classification.py:1135: UndefinedMetricWarning: F-score is ill-defined and being set to 0.0 due to no predicted samples.\n", 389 | " 'precision', 'predicted', average, warn_for)\n" 390 | ] 391 | } 392 | ], 393 | "source": [ 394 | "model = svm.SVC(kernel='rbf')\n", 395 | "model = model.fit(traindata, trainlabel)\n", 396 | "\n", 397 | "# make predictions\n", 398 | "expected = testlabel\n", 399 | "predicted = model.predict(testdata)\n", 400 | "print(\"--------------------------------------SVMrbf--------------------------------------\")\n", 401 | "y_train1 = expected\n", 402 | "y_pred = predicted\n", 403 | "accuracy = accuracy_score(y_train1, y_pred)\n", 404 | "recall = recall_score(y_train1, y_pred , average=\"binary\")\n", 405 | "precision = precision_score(y_train1, y_pred , average=\"binary\")\n", 406 | "f1 = f1_score(y_train1, y_pred, average=\"binary\")\n", 407 | "\n", 408 | "print(\"accuracy\")\n", 409 | "print(\"%.3f\" %accuracy)\n", 410 | "print(\"precision\")\n", 411 | "print(\"%.3f\" %precision)\n", 412 | "print(\"racall\")\n", 413 | "print(\"%.3f\" %recall)\n", 414 | "print(\"f1score\")\n", 415 | "print(\"%.3f\" %f1)\n" 416 | ] 417 | }, 418 | { 419 | "cell_type": "code", 420 | "execution_count": 29, 421 | "metadata": {}, 422 | "outputs": [ 423 | { 424 | "name": "stdout", 425 | "output_type": "stream", 426 | "text": [ 427 | "SVC(C=1000, cache_size=200, class_weight=None, coef0=0.0,\n", 428 | " decision_function_shape='ovr', degree=3, gamma='auto', kernel='linear',\n", 429 | " max_iter=-1, probability=False, random_state=None, shrinking=True,\n", 430 | " tol=0.001, verbose=False)\n", 431 | "--------------------------------------SVM linear--------------------------------------\n", 432 | "accuracy\n", 433 | "0.661\n", 434 | "precision\n", 435 | "0.000\n", 436 | "racall\n", 437 | "0.000\n", 438 | "f1score\n", 439 | "0.000\n" 440 | ] 441 | } 442 | ], 443 | "source": [ 444 | "model = svm.SVC(kernel='linear', C=1000)\n", 445 | "model.fit(traindata, trainlabel)\n", 446 | "print(model)\n", 447 | "# make predictions\n", 448 | "expected = testlabel\n", 449 | "predicted = model.predict(testdata)\n", 450 | "# summarize the fit of the model\n", 451 | "print(\"--------------------------------------SVM linear--------------------------------------\")\n", 452 | "y_train1 = expected\n", 453 | "y_pred = predicted\n", 454 | "accuracy = accuracy_score(y_train1, y_pred)\n", 455 | "recall = recall_score(y_train1, y_pred , average=\"binary\")\n", 456 | "precision = precision_score(y_train1, y_pred , average=\"binary\")\n", 457 | "f1 = f1_score(y_train1, y_pred, average=\"binary\")\n", 458 | "\n", 459 | "print(\"accuracy\")\n", 460 | "print(\"%.3f\" %accuracy)\n", 461 | "print(\"precision\")\n", 462 | "print(\"%.3f\" %precision)\n", 463 | "print(\"racall\")\n", 464 | "print(\"%.3f\" %recall)\n", 465 | "print(\"f1score\")\n", 466 | "print(\"%.3f\" %f1)" 467 | ] 468 | }, 469 | { 470 | "cell_type": "code", 471 | "execution_count": null, 472 | "metadata": {}, 473 | "outputs": [], 474 | "source": [] 475 | } 476 | ], 477 | "metadata": { 478 | "kernelspec": { 479 | "display_name": "securetensor", 480 | "language": "python", 481 | "name": "securetensor" 482 | }, 483 | "language_info": { 484 | "codemirror_mode": { 485 | "name": "ipython", 486 | "version": 2 487 | }, 488 | "file_extension": ".py", 489 | "mimetype": "text/x-python", 490 | "name": "python", 491 | "nbconvert_exporter": "python", 492 | "pygments_lexer": "ipython2", 493 | "version": "2.7.12" 494 | } 495 | }, 496 | "nbformat": 4, 497 | "nbformat_minor": 2 498 | } 499 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/Hyper-parameter tuning/Hyper-paramter-tuning-DNN.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#Grid Search Hyperparameters\n", 10 | "\n", 11 | "#Hyperparameter Optimization\n", 12 | "\n", 13 | "#k-fold Cross Validation: k=5 or k=10 \n", 14 | "#Please use seed during cross validation to produce reproduicable results." 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "# Case 1: Use scikit-learn to grid search the batch size and epochs\n", 24 | "import numpy\n", 25 | "from sklearn.model_selection import GridSearchCV\n", 26 | "from keras.models import Sequential\n", 27 | "from keras.layers import Dense\n", 28 | "from keras.wrappers.scikit_learn import KerasClassifier\n", 29 | "from sklearn.preprocessing import Normalizer\n", 30 | "# Function to create model, required for KerasClassifier\n", 31 | "def create_model():\n", 32 | "\t# create model\n", 33 | "\tmodel = Sequential()\n", 34 | "\tmodel.add(Dense(12, input_dim=8, activation='relu'))\n", 35 | "\tmodel.add(Dense(1, activation='sigmoid'))\n", 36 | "\t# Compile model\n", 37 | "\tmodel.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])\n", 38 | "\treturn model\n", 39 | "# fix random seed for reproducibility\n", 40 | "seed = 7\n", 41 | "numpy.random.seed(seed)\n", 42 | "# load dataset\n", 43 | "dataset = numpy.loadtxt(\"pima-indians-diabetes.csv\", delimiter=\",\")\n", 44 | "# split into input (X) and output (Y) variables\n", 45 | "X = dataset[:,0:8]\n", 46 | "Y = dataset[:,8]\n", 47 | "\n", 48 | "#normalize the data\n", 49 | "scaler = Normalizer().fit(X)\n", 50 | "X = scaler.transform(X)\n", 51 | "\n", 52 | "# create model\n", 53 | "model = KerasClassifier(build_fn=create_model, verbose=0)\n", 54 | "# define the grid search parameters\n", 55 | "batch_size = [10, 20, 40, 60, 80, 100]\n", 56 | "epochs = [10, 50, 100]\n", 57 | "param_grid = dict(batch_size=batch_size, epochs=epochs)\n", 58 | "grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1)\n", 59 | "grid_result = grid.fit(X, Y)\n", 60 | "# summarize results\n", 61 | "print(\"Best: %f using %s\" % (grid_result.best_score_, grid_result.best_params_))\n", 62 | "means = grid_result.cv_results_['mean_test_score']\n", 63 | "stds = grid_result.cv_results_['std_test_score']\n", 64 | "params = grid_result.cv_results_['params']\n", 65 | "for mean, stdev, param in zip(means, stds, params):\n", 66 | " print(\"%f (%f) with: %r\" % (mean, stdev, param))" 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": null, 72 | "metadata": {}, 73 | "outputs": [], 74 | "source": [ 75 | "# Case 2: How to Tune the Training Optimization Algorithm\n", 76 | "import numpy\n", 77 | "from sklearn.model_selection import GridSearchCV\n", 78 | "from keras.models import Sequential\n", 79 | "from keras.layers import Dense\n", 80 | "from keras.wrappers.scikit_learn import KerasClassifier\n", 81 | "from sklearn.preprocessing import Normalizer\n", 82 | "# Function to create model, required for KerasClassifier\n", 83 | "def create_model(optimizer='adam'):\n", 84 | "\t# create model\n", 85 | "\tmodel = Sequential()\n", 86 | "\tmodel.add(Dense(12, input_dim=8, activation='relu'))\n", 87 | "\tmodel.add(Dense(1, activation='sigmoid'))\n", 88 | "\t# Compile model\n", 89 | "\tmodel.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy'])\n", 90 | "\treturn model\n", 91 | "# fix random seed for reproducibility\n", 92 | "seed = 7\n", 93 | "numpy.random.seed(seed)\n", 94 | "# load dataset\n", 95 | "dataset = numpy.loadtxt(\"pima-indians-diabetes.csv\", delimiter=\",\")\n", 96 | "# split into input (X) and output (Y) variables\n", 97 | "X = dataset[:,0:8]\n", 98 | "Y = dataset[:,8]\n", 99 | "\n", 100 | "#normalize the data\n", 101 | "scaler = Normalizer().fit(X)\n", 102 | "X = scaler.transform(X)\n", 103 | "\n", 104 | "# create model\n", 105 | "model = KerasClassifier(build_fn=create_model, epochs=100, batch_size=10, verbose=0)\n", 106 | "# define the grid search parameters\n", 107 | "optimizer = ['SGD', 'RMSprop', 'Adagrad', 'Adadelta', 'Adam', 'Adamax', 'Nadam']\n", 108 | "param_grid = dict(optimizer=optimizer)\n", 109 | "grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1)\n", 110 | "grid_result = grid.fit(X, Y)\n", 111 | "# summarize results\n", 112 | "print(\"Best: %f using %s\" % (grid_result.best_score_, grid_result.best_params_))\n", 113 | "means = grid_result.cv_results_['mean_test_score']\n", 114 | "stds = grid_result.cv_results_['std_test_score']\n", 115 | "params = grid_result.cv_results_['params']\n", 116 | "for mean, stdev, param in zip(means, stds, params):\n", 117 | " print(\"%f (%f) with: %r\" % (mean, stdev, param))" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "# Case 3: Use scikit-learn to grid search the learning rate and momentum\n", 127 | "import numpy\n", 128 | "from sklearn.model_selection import GridSearchCV\n", 129 | "from keras.models import Sequential\n", 130 | "from keras.layers import Dense\n", 131 | "from keras.wrappers.scikit_learn import KerasClassifier\n", 132 | "from keras.optimizers import SGD\n", 133 | "from sklearn.preprocessing import Normalizer\n", 134 | "# Function to create model, required for KerasClassifier\n", 135 | "def create_model(learn_rate=0.01, momentum=0):\n", 136 | "\t# create model\n", 137 | "\tmodel = Sequential()\n", 138 | "\tmodel.add(Dense(12, input_dim=8, activation='relu'))\n", 139 | "\tmodel.add(Dense(1, activation='sigmoid'))\n", 140 | "\t# Compile model\n", 141 | "\toptimizer = SGD(lr=learn_rate, momentum=momentum)\n", 142 | "\tmodel.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy'])\n", 143 | "\treturn model\n", 144 | "# fix random seed for reproducibility\n", 145 | "seed = 7\n", 146 | "numpy.random.seed(seed)\n", 147 | "# load dataset\n", 148 | "dataset = numpy.loadtxt(\"pima-indians-diabetes.csv\", delimiter=\",\")\n", 149 | "# split into input (X) and output (Y) variables\n", 150 | "X = dataset[:,0:8]\n", 151 | "Y = dataset[:,8]\n", 152 | "\n", 153 | "#normalize the data\n", 154 | "scaler = Normalizer().fit(X)\n", 155 | "X = scaler.transform(X)\n", 156 | "\n", 157 | "# create model\n", 158 | "model = KerasClassifier(build_fn=create_model, epochs=100, batch_size=10, verbose=0)\n", 159 | "# define the grid search parameters\n", 160 | "learn_rate = [0.001, 0.01, 0.1, 0.2, 0.3]\n", 161 | "momentum = [0.0, 0.2, 0.4, 0.6, 0.8, 0.9]\n", 162 | "param_grid = dict(learn_rate=learn_rate, momentum=momentum)\n", 163 | "grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1)\n", 164 | "grid_result = grid.fit(X, Y)\n", 165 | "# summarize results\n", 166 | "print(\"Best: %f using %s\" % (grid_result.best_score_, grid_result.best_params_))\n", 167 | "means = grid_result.cv_results_['mean_test_score']\n", 168 | "stds = grid_result.cv_results_['std_test_score']\n", 169 | "params = grid_result.cv_results_['params']\n", 170 | "for mean, stdev, param in zip(means, stds, params):\n", 171 | " print(\"%f (%f) with: %r\" % (mean, stdev, param))" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": null, 177 | "metadata": {}, 178 | "outputs": [], 179 | "source": [ 180 | "# Case 4: Use scikit-learn to grid search the weight initialization\n", 181 | "import numpy\n", 182 | "from sklearn.model_selection import GridSearchCV\n", 183 | "from keras.models import Sequential\n", 184 | "from keras.layers import Dense\n", 185 | "from keras.wrappers.scikit_learn import KerasClassifier\n", 186 | "from sklearn.preprocessing import Normalizer\n", 187 | "# Function to create model, required for KerasClassifier\n", 188 | "def create_model(init_mode='uniform'):\n", 189 | "\t# create model\n", 190 | "\tmodel = Sequential()\n", 191 | "\tmodel.add(Dense(12, input_dim=8, kernel_initializer=init_mode, activation='relu'))\n", 192 | "\tmodel.add(Dense(1, kernel_initializer=init_mode, activation='sigmoid'))\n", 193 | "\t# Compile model\n", 194 | "\tmodel.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])\n", 195 | "\treturn model\n", 196 | "# fix random seed for reproducibility\n", 197 | "seed = 7\n", 198 | "numpy.random.seed(seed)\n", 199 | "# load dataset\n", 200 | "dataset = numpy.loadtxt(\"pima-indians-diabetes.csv\", delimiter=\",\")\n", 201 | "# split into input (X) and output (Y) variables\n", 202 | "X = dataset[:,0:8]\n", 203 | "Y = dataset[:,8]\n", 204 | "\n", 205 | "#normalize the data\n", 206 | "scaler = Normalizer().fit(X)\n", 207 | "X = scaler.transform(X)\n", 208 | "\n", 209 | "# create model\n", 210 | "model = KerasClassifier(build_fn=create_model, epochs=100, batch_size=10, verbose=0)\n", 211 | "# define the grid search parameters\n", 212 | "init_mode = ['uniform', 'lecun_uniform', 'normal', 'zero', 'glorot_normal', 'glorot_uniform', 'he_normal', 'he_uniform']\n", 213 | "param_grid = dict(init_mode=init_mode)\n", 214 | "grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1)\n", 215 | "grid_result = grid.fit(X, Y)\n", 216 | "# summarize results\n", 217 | "print(\"Best: %f using %s\" % (grid_result.best_score_, grid_result.best_params_))\n", 218 | "means = grid_result.cv_results_['mean_test_score']\n", 219 | "stds = grid_result.cv_results_['std_test_score']\n", 220 | "params = grid_result.cv_results_['params']\n", 221 | "for mean, stdev, param in zip(means, stds, params):\n", 222 | " print(\"%f (%f) with: %r\" % (mean, stdev, param))" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": null, 228 | "metadata": {}, 229 | "outputs": [], 230 | "source": [ 231 | "# Case 5: Use scikit-learn to grid search the activation function\n", 232 | "import numpy\n", 233 | "from sklearn.model_selection import GridSearchCV\n", 234 | "from keras.models import Sequential\n", 235 | "from keras.layers import Dense\n", 236 | "from keras.wrappers.scikit_learn import KerasClassifier\n", 237 | "from sklearn.preprocessing import Normalizer\n", 238 | "# Function to create model, required for KerasClassifier\n", 239 | "def create_model(activation='relu'):\n", 240 | "\t# create model\n", 241 | "\tmodel = Sequential()\n", 242 | "\tmodel.add(Dense(12, input_dim=8, kernel_initializer='uniform', activation=activation))\n", 243 | "\tmodel.add(Dense(1, kernel_initializer='uniform', activation='sigmoid'))\n", 244 | "\t# Compile model\n", 245 | "\tmodel.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])\n", 246 | "\treturn model\n", 247 | "# fix random seed for reproducibility\n", 248 | "seed = 7\n", 249 | "numpy.random.seed(seed)\n", 250 | "# load dataset\n", 251 | "dataset = numpy.loadtxt(\"pima-indians-diabetes.csv\", delimiter=\",\")\n", 252 | "# split into input (X) and output (Y) variables\n", 253 | "X = dataset[:,0:8]\n", 254 | "Y = dataset[:,8]\n", 255 | "\n", 256 | "#normalize the data\n", 257 | "scaler = Normalizer().fit(X)\n", 258 | "X = scaler.transform(X)\n", 259 | "\n", 260 | "# create model\n", 261 | "model = KerasClassifier(build_fn=create_model, epochs=100, batch_size=10, verbose=0)\n", 262 | "# define the grid search parameters\n", 263 | "activation = ['softmax', 'softplus', 'softsign', 'relu', 'tanh', 'sigmoid', 'hard_sigmoid', 'linear']\n", 264 | "param_grid = dict(activation=activation)\n", 265 | "grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1)\n", 266 | "grid_result = grid.fit(X, Y)\n", 267 | "# summarize results\n", 268 | "print(\"Best: %f using %s\" % (grid_result.best_score_, grid_result.best_params_))\n", 269 | "means = grid_result.cv_results_['mean_test_score']\n", 270 | "stds = grid_result.cv_results_['std_test_score']\n", 271 | "params = grid_result.cv_results_['params']\n", 272 | "for mean, stdev, param in zip(means, stds, params):\n", 273 | " print(\"%f (%f) with: %r\" % (mean, stdev, param))" 274 | ] 275 | }, 276 | { 277 | "cell_type": "code", 278 | "execution_count": null, 279 | "metadata": {}, 280 | "outputs": [], 281 | "source": [ 282 | "# Case 6: Use scikit-learn to grid search the dropout rate\n", 283 | "import numpy\n", 284 | "from sklearn.model_selection import GridSearchCV\n", 285 | "from keras.models import Sequential\n", 286 | "from keras.layers import Dense\n", 287 | "from keras.layers import Dropout\n", 288 | "from keras.wrappers.scikit_learn import KerasClassifier\n", 289 | "from keras.constraints import maxnorm\n", 290 | "from sklearn.preprocessing import Normalizer\n", 291 | "# Function to create model, required for KerasClassifier\n", 292 | "def create_model(dropout_rate=0.0, weight_constraint=0):\n", 293 | "\t# create model\n", 294 | "\tmodel = Sequential()\n", 295 | "\tmodel.add(Dense(12, input_dim=8, kernel_initializer='uniform', activation='linear', kernel_constraint=maxnorm(weight_constraint)))\n", 296 | "\tmodel.add(Dropout(dropout_rate))\n", 297 | "\tmodel.add(Dense(1, kernel_initializer='uniform', activation='sigmoid'))\n", 298 | "\t# Compile model\n", 299 | "\tmodel.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])\n", 300 | "\treturn model\n", 301 | "# fix random seed for reproducibility\n", 302 | "seed = 7\n", 303 | "numpy.random.seed(seed)\n", 304 | "# load dataset\n", 305 | "dataset = numpy.loadtxt(\"pima-indians-diabetes.csv\", delimiter=\",\")\n", 306 | "# split into input (X) and output (Y) variables\n", 307 | "X = dataset[:,0:8]\n", 308 | "Y = dataset[:,8]\n", 309 | "\n", 310 | "#normalize the data\n", 311 | "scaler = Normalizer().fit(X)\n", 312 | "X = scaler.transform(X)\n", 313 | "\n", 314 | "# create model\n", 315 | "model = KerasClassifier(build_fn=create_model, epochs=100, batch_size=10, verbose=0)\n", 316 | "# define the grid search parameters\n", 317 | "weight_constraint = [1, 2, 3, 4, 5]\n", 318 | "dropout_rate = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]\n", 319 | "param_grid = dict(dropout_rate=dropout_rate, weight_constraint=weight_constraint)\n", 320 | "grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1)\n", 321 | "grid_result = grid.fit(X, Y)\n", 322 | "# summarize results\n", 323 | "print(\"Best: %f using %s\" % (grid_result.best_score_, grid_result.best_params_))\n", 324 | "means = grid_result.cv_results_['mean_test_score']\n", 325 | "stds = grid_result.cv_results_['std_test_score']\n", 326 | "params = grid_result.cv_results_['params']\n", 327 | "for mean, stdev, param in zip(means, stds, params):\n", 328 | " print(\"%f (%f) with: %r\" % (mean, stdev, param))" 329 | ] 330 | }, 331 | { 332 | "cell_type": "code", 333 | "execution_count": null, 334 | "metadata": {}, 335 | "outputs": [], 336 | "source": [ 337 | "# Case 7: Use scikit-learn to grid search the number of neurons\n", 338 | "import numpy\n", 339 | "from sklearn.model_selection import GridSearchCV\n", 340 | "from keras.models import Sequential\n", 341 | "from keras.layers import Dense\n", 342 | "from keras.layers import Dropout\n", 343 | "from keras.wrappers.scikit_learn import KerasClassifier\n", 344 | "from keras.constraints import maxnorm\n", 345 | "from sklearn.preprocessing import Normalizer\n", 346 | "# Function to create model, required for KerasClassifier\n", 347 | "def create_model(neurons=1):\n", 348 | "\t# create model\n", 349 | "\tmodel = Sequential()\n", 350 | "\tmodel.add(Dense(neurons, input_dim=8, kernel_initializer='uniform', activation='linear', kernel_constraint=maxnorm(4)))\n", 351 | "\tmodel.add(Dropout(0.2))\n", 352 | "\tmodel.add(Dense(1, kernel_initializer='uniform', activation='sigmoid'))\n", 353 | "\t# Compile model\n", 354 | "\tmodel.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])\n", 355 | "\treturn model\n", 356 | "# fix random seed for reproducibility\n", 357 | "seed = 7\n", 358 | "numpy.random.seed(seed)\n", 359 | "# load dataset\n", 360 | "dataset = numpy.loadtxt(\"pima-indians-diabetes.csv\", delimiter=\",\")\n", 361 | "# split into input (X) and output (Y) variables\n", 362 | "X = dataset[:,0:8]\n", 363 | "Y = dataset[:,8]\n", 364 | "\n", 365 | "#normalize the data\n", 366 | "scaler = Normalizer().fit(X)\n", 367 | "X = scaler.transform(X)\n", 368 | "\n", 369 | "# create model\n", 370 | "model = KerasClassifier(build_fn=create_model, epochs=100, batch_size=10, verbose=0)\n", 371 | "# define the grid search parameters\n", 372 | "neurons = [1, 5, 10, 15, 20, 25, 30]\n", 373 | "param_grid = dict(neurons=neurons)\n", 374 | "grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1)\n", 375 | "grid_result = grid.fit(X, Y)\n", 376 | "# summarize results\n", 377 | "print(\"Best: %f using %s\" % (grid_result.best_score_, grid_result.best_params_))\n", 378 | "means = grid_result.cv_results_['mean_test_score']\n", 379 | "stds = grid_result.cv_results_['std_test_score']\n", 380 | "params = grid_result.cv_results_['params']\n", 381 | "for mean, stdev, param in zip(means, stds, params):\n", 382 | " print(\"%f (%f) with: %r\" % (mean, stdev, param))" 383 | ] 384 | } 385 | ], 386 | "metadata": { 387 | "kernelspec": { 388 | "display_name": "Python 2", 389 | "language": "python", 390 | "name": "python2" 391 | }, 392 | "language_info": { 393 | "codemirror_mode": { 394 | "name": "ipython", 395 | "version": 2 396 | }, 397 | "file_extension": ".py", 398 | "mimetype": "text/x-python", 399 | "name": "python", 400 | "nbconvert_exporter": "python", 401 | "pygments_lexer": "ipython2", 402 | "version": "2.7.12" 403 | } 404 | }, 405 | "nbformat": 4, 406 | "nbformat_minor": 2 407 | } 408 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/Hyper-parameter tuning/test.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Grid Search Hyperparameters 3 | 4 | 5 | Hyperparameter Optimization 6 | 7 | k-fold Cross Validation: k=5 or k=10 8 | 9 | Please use seed during cross validation to produce reproduicable results. 10 | 11 | Tuning Batch Size and Number of Epochs 12 | ''' 13 | # Use scikit-learn to grid search the batch size and epochs 14 | import numpy 15 | from sklearn.model_selection import GridSearchCV 16 | from keras.models import Sequential 17 | from keras.layers import Dense 18 | from keras.wrappers.scikit_learn import KerasClassifier 19 | # Function to create model, required for KerasClassifier 20 | def create_model(): 21 | # create model 22 | model = Sequential() 23 | model.add(Dense(12, input_dim=8, activation='relu')) 24 | model.add(Dense(24, activation='relu')) 25 | model.add(Dense(1, activation='sigmoid')) 26 | # Compile model 27 | model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) 28 | return model 29 | # fix random seed for reproducibility 30 | seed = 7 31 | numpy.random.seed(seed) 32 | # load dataset 33 | dataset = numpy.loadtxt("Data.csv", delimiter=",") 34 | # split into input (X) and output (Y) variables 35 | X = dataset[:,0:8] 36 | Y = dataset[:,8] 37 | # create model 38 | model = KerasClassifier(build_fn=create_model, verbose=0) 39 | # define the grid search parameters 40 | number_of_units = [12, 24, 36] 41 | batch_size = [10, 20, 40, 60, 80, 100] 42 | epochs = [1, 2, 3] 43 | param_grid = dict(batch_size=batch_size, epochs=epochs) 44 | grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1) 45 | grid_result = grid.fit(X, Y) 46 | # summarize results 47 | print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_)) 48 | means = grid_result.cv_results_['mean_test_score'] 49 | stds = grid_result.cv_results_['std_test_score'] 50 | params = grid_result.cv_results_['params'] 51 | for mean, stdev, param in zip(means, stds, params): 52 | print("%f (%f) with: %r" % (mean, stdev, param)) 53 | 54 | ''' 55 | Tuning the Training Optimization Algorithm 56 | ''' 57 | 58 | # Use scikit-learn to grid search the batch size and epochs 59 | import numpy 60 | from sklearn.model_selection import GridSearchCV 61 | from keras.models import Sequential 62 | from keras.layers import Dense 63 | from keras.wrappers.scikit_learn import KerasClassifier 64 | # Function to create model, required for KerasClassifier 65 | def create_model(optimizer='adam'): 66 | # create model 67 | model = Sequential() 68 | model.add(Dense(12, input_dim=8, activation='relu')) 69 | model.add(Dense(1, activation='sigmoid')) 70 | # Compile model 71 | model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy']) 72 | return model 73 | # fix random seed for reproducibility 74 | seed = 7 75 | numpy.random.seed(seed) 76 | # load dataset 77 | dataset = numpy.loadtxt("Data.csv", delimiter=",") 78 | # split into input (X) and output (Y) variables 79 | X = dataset[:,0:8] 80 | Y = dataset[:,8] 81 | # create model 82 | model = KerasClassifier(build_fn=create_model, epochs=100, batch_size=10, verbose=0) 83 | # define the grid search parameters 84 | optimizer = ['SGD', 'RMSprop', 'Adagrad', 'Adadelta', 'Adam', 'Adamax', 'Nadam'] 85 | param_grid = dict(optimizer=optimizer) 86 | grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1) 87 | grid_result = grid.fit(X, Y) 88 | # summarize results 89 | print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_)) 90 | means = grid_result.cv_results_['mean_test_score'] 91 | stds = grid_result.cv_results_['std_test_score'] 92 | params = grid_result.cv_results_['params'] 93 | for mean, stdev, param in zip(means, stds, params): 94 | print("%f (%f) with: %r" % (mean, stdev, param)) 95 | 96 | ''' 97 | Tuning Learning Rate and Momentum 98 | ''' 99 | 100 | # Use scikit-learn to grid search the learning rate and momentum 101 | import numpy 102 | from sklearn.model_selection import GridSearchCV 103 | from keras.models import Sequential 104 | from keras.layers import Dense 105 | from keras.wrappers.scikit_learn import KerasClassifier 106 | from keras.optimizers import SGD 107 | # Function to create model, required for KerasClassifier 108 | def create_model(learn_rate=0.01, momentum=0): 109 | # create model 110 | model = Sequential() 111 | model.add(Dense(12, input_dim=8, activation='relu')) 112 | model.add(Dense(1, activation='sigmoid')) 113 | # Compile model 114 | optimizer = SGD(lr=learn_rate, momentum=momentum) 115 | model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy']) 116 | return model 117 | # fix random seed for reproducibility 118 | seed = 7 119 | numpy.random.seed(seed) 120 | # load dataset 121 | dataset = numpy.loadtxt("Data.csv", delimiter=",") 122 | # split into input (X) and output (Y) variables 123 | X = dataset[:,0:8] 124 | Y = dataset[:,8] 125 | # create model 126 | model = KerasClassifier(build_fn=create_model, epochs=100, batch_size=10, verbose=0) 127 | # define the grid search parameters 128 | learn_rate = [0.001, 0.01, 0.1, 0.2, 0.3] 129 | momentum = [0.0, 0.2, 0.4, 0.6, 0.8, 0.9] 130 | param_grid = dict(learn_rate=learn_rate, momentum=momentum) 131 | grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1) 132 | grid_result = grid.fit(X, Y) 133 | # summarize results 134 | print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_)) 135 | means = grid_result.cv_results_['mean_test_score'] 136 | stds = grid_result.cv_results_['std_test_score'] 137 | params = grid_result.cv_results_['params'] 138 | for mean, stdev, param in zip(means, stds, params): 139 | print("%f (%f) with: %r" % (mean, stdev, param)) 140 | 141 | 142 | ''' 143 | Tuning Network Weight Initialization 144 | ''' 145 | 146 | 147 | # Use scikit-learn to grid search the weight initialization 148 | import numpy 149 | from sklearn.model_selection import GridSearchCV 150 | from keras.models import Sequential 151 | from keras.layers import Dense 152 | from keras.wrappers.scikit_learn import KerasClassifier 153 | # Function to create model, required for KerasClassifier 154 | def create_model(init_mode='uniform'): 155 | # create model 156 | model = Sequential() 157 | model.add(Dense(12, input_dim=8, kernel_initializer=init_mode, activation='relu')) 158 | model.add(Dense(1, kernel_initializer=init_mode, activation='sigmoid')) 159 | # Compile model 160 | model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) 161 | return model 162 | # fix random seed for reproducibility 163 | seed = 7 164 | numpy.random.seed(seed) 165 | # load dataset 166 | dataset = numpy.loadtxt("Data.csv", delimiter=",") 167 | # split into input (X) and output (Y) variables 168 | X = dataset[:,0:8] 169 | Y = dataset[:,8] 170 | # create model 171 | model = KerasClassifier(build_fn=create_model, epochs=100, batch_size=10, verbose=0) 172 | # define the grid search parameters 173 | init_mode = ['uniform', 'lecun_uniform', 'normal', 'zero', 'glorot_normal', 'glorot_uniform', 'he_normal', 'he_uniform'] 174 | param_grid = dict(init_mode=init_mode) 175 | grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1) 176 | grid_result = grid.fit(X, Y) 177 | # summarize results 178 | print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_)) 179 | means = grid_result.cv_results_['mean_test_score'] 180 | stds = grid_result.cv_results_['std_test_score'] 181 | params = grid_result.cv_results_['params'] 182 | for mean, stdev, param in zip(means, stds, params): 183 | print("%f (%f) with: %r" % (mean, stdev, param)) 184 | 185 | 186 | 187 | ''' 188 | Tuning the Neuron Activation Function 189 | ''' 190 | 191 | # Use scikit-learn to grid search the activation function 192 | import numpy 193 | from sklearn.model_selection import GridSearchCV 194 | from keras.models import Sequential 195 | from keras.layers import Dense 196 | from keras.wrappers.scikit_learn import KerasClassifier 197 | # Function to create model, required for KerasClassifier 198 | def create_model(activation='relu'): 199 | # create model 200 | model = Sequential() 201 | model.add(Dense(12, input_dim=8, kernel_initializer='uniform', activation=activation)) 202 | model.add(Dense(1, kernel_initializer='uniform', activation='sigmoid')) 203 | # Compile model 204 | model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) 205 | return model 206 | # fix random seed for reproducibility 207 | seed = 7 208 | numpy.random.seed(seed) 209 | # load dataset 210 | dataset = numpy.loadtxt("Data.csv", delimiter=",") 211 | # split into input (X) and output (Y) variables 212 | X = dataset[:,0:8] 213 | Y = dataset[:,8] 214 | # create model 215 | model = KerasClassifier(build_fn=create_model, epochs=100, batch_size=10, verbose=0) 216 | # define the grid search parameters 217 | activation = ['softmax', 'softplus', 'softsign', 'relu', 'tanh', 'sigmoid', 'hard_sigmoid', 'linear'] 218 | param_grid = dict(activation=activation) 219 | grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1) 220 | grid_result = grid.fit(X, Y) 221 | # summarize results 222 | print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_)) 223 | means = grid_result.cv_results_['mean_test_score'] 224 | stds = grid_result.cv_results_['std_test_score'] 225 | params = grid_result.cv_results_['params'] 226 | for mean, stdev, param in zip(means, stds, params): 227 | print("%f (%f) with: %r" % (mean, stdev, param)) 228 | 229 | 230 | ''' 231 | Tuning Dropout Regularization 232 | ''' 233 | 234 | # Use scikit-learn to grid search the dropout rate 235 | import numpy 236 | from sklearn.model_selection import GridSearchCV 237 | from keras.models import Sequential 238 | from keras.layers import Dense 239 | from keras.layers import Dropout 240 | from keras.wrappers.scikit_learn import KerasClassifier 241 | from keras.constraints import maxnorm 242 | # Function to create model, required for KerasClassifier 243 | def create_model(dropout_rate=0.0, weight_constraint=0): 244 | # create model 245 | model = Sequential() 246 | model.add(Dense(12, input_dim=8, kernel_initializer='uniform', activation='linear', kernel_constraint=maxnorm(weight_constraint))) 247 | model.add(Dropout(dropout_rate)) 248 | model.add(Dense(1, kernel_initializer='uniform', activation='sigmoid')) 249 | # Compile model 250 | model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) 251 | return model 252 | # fix random seed for reproducibility 253 | seed = 7 254 | numpy.random.seed(seed) 255 | # load dataset 256 | dataset = numpy.loadtxt("Data.csv", delimiter=",") 257 | # split into input (X) and output (Y) variables 258 | X = dataset[:,0:8] 259 | Y = dataset[:,8] 260 | # create model 261 | model = KerasClassifier(build_fn=create_model, epochs=100, batch_size=10, verbose=0) 262 | # define the grid search parameters 263 | weight_constraint = [1, 2, 3, 4, 5] 264 | dropout_rate = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] 265 | param_grid = dict(dropout_rate=dropout_rate, weight_constraint=weight_constraint) 266 | grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1) 267 | grid_result = grid.fit(X, Y) 268 | # summarize results 269 | print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_)) 270 | means = grid_result.cv_results_['mean_test_score'] 271 | stds = grid_result.cv_results_['std_test_score'] 272 | params = grid_result.cv_results_['params'] 273 | for mean, stdev, param in zip(means, stds, params): 274 | print("%f (%f) with: %r" % (mean, stdev, param)) 275 | 276 | 277 | ''' 278 | Tuning Number of Neurons in the Hidden Layer 279 | ''' 280 | 281 | 282 | # Use scikit-learn to grid search the number of neurons 283 | import numpy 284 | from sklearn.model_selection import GridSearchCV 285 | from keras.models import Sequential 286 | from keras.layers import Dense 287 | from keras.layers import Dropout 288 | from keras.wrappers.scikit_learn import KerasClassifier 289 | from keras.constraints import maxnorm 290 | # Function to create model, required for KerasClassifier 291 | def create_model(neurons=1): 292 | # create model 293 | model = Sequential() 294 | model.add(Dense(neurons, input_dim=8, kernel_initializer='uniform', activation='linear', kernel_constraint=maxnorm(4))) 295 | model.add(Dropout(0.2)) 296 | model.add(Dense(1, kernel_initializer='uniform', activation='sigmoid')) 297 | # Compile model 298 | model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) 299 | return model 300 | # fix random seed for reproducibility 301 | seed = 7 302 | numpy.random.seed(seed) 303 | # load dataset 304 | dataset = numpy.loadtxt("Data.csv", delimiter=",") 305 | # split into input (X) and output (Y) variables 306 | X = dataset[:,0:8] 307 | Y = dataset[:,8] 308 | # create model 309 | model = KerasClassifier(build_fn=create_model, epochs=100, batch_size=10, verbose=0) 310 | # define the grid search parameters 311 | neurons = [1, 5, 10, 15, 20, 25, 30] 312 | param_grid = dict(neurons=neurons) 313 | grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1) 314 | grid_result = grid.fit(X, Y) 315 | # summarize results 316 | print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_)) 317 | means = grid_result.cv_results_['mean_test_score'] 318 | stds = grid_result.cv_results_['std_test_score'] 319 | params = grid_result.cv_results_['params'] 320 | for mean, stdev, param in zip(means, stds, params): 321 | print("%f (%f) with: %r" % (mean, stdev, param)) 322 | 323 | 324 | 325 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/README.md: -------------------------------------------------------------------------------- 1 | Download the physionet dataset 2 | 3 | ``` 4 | >> wget http://physionet.org/physiobank/database/challenge/2016/training.zip 5 | >> unzip training.zip 6 | ``` 7 | 8 | Build a feature vector from the raw data and train the CNN 9 | 10 | python preprocess/train_model.py 11 | e.g., 12 | python preprocess/train_model.py training/ f 13 | 14 | 15 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/dnn/dnn1.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score,f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 14 | from sklearn import metrics 15 | from sklearn.preprocessing import Normalizer 16 | import h5py 17 | from keras import callbacks 18 | from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, CSVLogger 19 | from sklearn.utils import shuffle 20 | 21 | 22 | traindata = pd.read_csv('kdd/binary/Training.csv', header=None) 23 | testdata = pd.read_csv('kdd/binary/Testing.csv', header=None) 24 | 25 | traindata = shuffle(traindata) 26 | testdata = shuffle(testdata) 27 | 28 | 29 | X = traindata.iloc[:,0:600] 30 | Y = traindata.iloc[:,600] 31 | C = testdata.iloc[:,600] 32 | T = testdata.iloc[:,0:600] 33 | 34 | y_train = np.array(Y) 35 | y_test = np.array(C) 36 | 37 | 38 | X_train = np.array(X) 39 | X_test = np.array(T) 40 | 41 | 42 | batch_size = 64 43 | 44 | # 1. define the network 45 | model = Sequential() 46 | model.add(Dense(1024,input_dim=600,activation='relu')) 47 | model.add(Dropout(0.01)) 48 | model.add(Dense(1)) 49 | model.add(Activation('sigmoid')) 50 | 51 | # try using different optimizers and different optimizer configs 52 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 53 | checkpointer = callbacks.ModelCheckpoint(filepath="kddresults/dnn1layer/checkpoint-{epoch:02d}.hdf5", verbose=1, save_best_only=True, monitor='loss') 54 | csv_logger = CSVLogger('kddresults/dnn1layer/training_set_dnnanalysis.csv',separator=',', append=False) 55 | model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=1000, callbacks=[checkpointer,csv_logger]) 56 | model.save("kddresults/dnn1layer/dnn1layer_model.hdf5") 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/dnn/dnn1test.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score,f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 14 | from sklearn import metrics 15 | from sklearn.preprocessing import Normalizer 16 | import h5py 17 | from keras import callbacks 18 | from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, CSVLogger 19 | from sklearn.utils import shuffle 20 | 21 | 22 | traindata = pd.read_csv('kdd/binary/Training.csv', header=None) 23 | testdata = pd.read_csv('kdd/binary/Testing.csv', header=None) 24 | 25 | traindata = shuffle(traindata) 26 | testdata = shuffle(testdata) 27 | 28 | 29 | X = traindata.iloc[:,0:600] 30 | Y = traindata.iloc[:,600] 31 | C = testdata.iloc[:,600] 32 | T = testdata.iloc[:,0:600] 33 | 34 | y_train = np.array(Y) 35 | y_test = np.array(C) 36 | 37 | 38 | X_train = np.array(X) 39 | X_test = np.array(T) 40 | 41 | 42 | batch_size = 64 43 | 44 | # 1. define the network 45 | model = Sequential() 46 | model.add(Dense(1024,input_dim=600,activation='relu')) 47 | model.add(Dropout(0.01)) 48 | model.add(Dense(1)) 49 | model.add(Activation('sigmoid')) 50 | 51 | ''' 52 | # try using different optimizers and different optimizer configs 53 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 54 | checkpointer = callbacks.ModelCheckpoint(filepath="kddresults/dnn1layer/checkpoint-{epoch:02d}.hdf5", verbose=1, save_best_only=True, monitor='loss') 55 | csv_logger = CSVLogger('kddresults/dnn1layer/training_set_dnnanalysis.csv',separator=',', append=False) 56 | model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=1000, callbacks=[checkpointer,csv_logger]) 57 | model.save("kddresults/dnn1layer/dnn1layer_model.hdf5") 58 | ''' 59 | 60 | 61 | 62 | 63 | 64 | 65 | score = [] 66 | name = [] 67 | import os 68 | for file in os.listdir("kddresults/dnn1layer/"): 69 | print("within a loop") 70 | model.load_weights("kddresults/dnn1layer/"+file) 71 | # make predictions 72 | testPredict = model.predict_classes(X_test) 73 | accuracy = accuracy_score(y_test, testPredict) 74 | print(accuracy) 75 | print(file) 76 | score.append(accuracy) 77 | name.append(file) 78 | 79 | print(max(score)) 80 | 81 | 82 | model.load_weights("kddresults/dnn1layer/"+name[score.index(max(score))]) 83 | pred = model.predict_classes(X_test) 84 | proba = model.predict_proba(X_test) 85 | np.savetxt("res/dnn1predicted.txt", pred) 86 | np.savetxt("res/dnn1probability.txt", proba) 87 | 88 | accuracy = accuracy_score(y_test, pred) 89 | recall = recall_score(y_test, pred , average="binary") 90 | precision = precision_score(y_test, pred , average="binary") 91 | f1 = f1_score(y_test, pred, average="binary") 92 | 93 | 94 | print("----------------------------------------------") 95 | print("accuracy") 96 | print("%.3f" %accuracy) 97 | print("precision") 98 | print("%.3f" %precision) 99 | print("racall") 100 | print("%.3f" %recall) 101 | print("f1score") 102 | print("%.3f" %f1) 103 | 104 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/dnn/dnn2.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score,f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 14 | from sklearn import metrics 15 | from sklearn.preprocessing import Normalizer 16 | import h5py 17 | from keras import callbacks 18 | from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, CSVLogger 19 | from sklearn.utils import shuffle 20 | 21 | 22 | traindata = pd.read_csv('kdd/binary/Training.csv', header=None) 23 | testdata = pd.read_csv('kdd/binary/Testing.csv', header=None) 24 | 25 | traindata = shuffle(traindata) 26 | testdata = shuffle(testdata) 27 | 28 | 29 | X = traindata.iloc[:,0:600] 30 | Y = traindata.iloc[:,600] 31 | C = testdata.iloc[:,600] 32 | T = testdata.iloc[:,0:600] 33 | 34 | y_train = np.array(Y) 35 | y_test = np.array(C) 36 | 37 | 38 | X_train = np.array(X) 39 | X_test = np.array(T) 40 | 41 | 42 | batch_size = 64 43 | 44 | # 1. define the network 45 | model = Sequential() 46 | model.add(Dense(1024,input_dim=600,activation='relu')) 47 | model.add(Dropout(0.01)) 48 | model.add(Dense(768,activation='relu')) 49 | model.add(Dropout(0.01)) 50 | model.add(Dense(1)) 51 | model.add(Activation('sigmoid')) 52 | 53 | # try using different optimizers and different optimizer configs 54 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 55 | checkpointer = callbacks.ModelCheckpoint(filepath="kddresults/dnn2layer/checkpoint-{epoch:02d}.hdf5", verbose=1, save_best_only=True, monitor='loss') 56 | csv_logger = CSVLogger('kddresults/dnn2layer/training_set_dnnanalysis.csv',separator=',', append=False) 57 | model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=1000, callbacks=[checkpointer,csv_logger]) 58 | model.save("kddresults/dnn2layer/dnn2layer_model.hdf5") 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/dnn/dnn2test.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score,f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 14 | from sklearn import metrics 15 | from sklearn.preprocessing import Normalizer 16 | import h5py 17 | from keras import callbacks 18 | from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, CSVLogger 19 | from sklearn.utils import shuffle 20 | 21 | 22 | traindata = pd.read_csv('kdd/binary/Training.csv', header=None) 23 | testdata = pd.read_csv('kdd/binary/Testing.csv', header=None) 24 | 25 | traindata = shuffle(traindata) 26 | testdata = shuffle(testdata) 27 | 28 | 29 | X = traindata.iloc[:,0:600] 30 | Y = traindata.iloc[:,600] 31 | C = testdata.iloc[:,600] 32 | T = testdata.iloc[:,0:600] 33 | 34 | y_train = np.array(Y) 35 | y_test = np.array(C) 36 | 37 | 38 | X_train = np.array(X) 39 | X_test = np.array(T) 40 | 41 | 42 | batch_size = 64 43 | 44 | # 1. define the network 45 | model = Sequential() 46 | model.add(Dense(1024,input_dim=600,activation='relu')) 47 | model.add(Dropout(0.01)) 48 | model.add(Dense(768,activation='relu')) 49 | model.add(Dropout(0.01)) 50 | model.add(Dense(1)) 51 | model.add(Activation('sigmoid')) 52 | 53 | ''' 54 | # try using different optimizers and different optimizer configs 55 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 56 | checkpointer = callbacks.ModelCheckpoint(filepath="kddresults/dnn2layer/checkpoint-{epoch:02d}.hdf5", verbose=1, save_best_only=True, monitor='loss') 57 | csv_logger = CSVLogger('kddresults/dnn2layer/training_set_dnnanalysis.csv',separator=',', append=False) 58 | model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=1000, callbacks=[checkpointer,csv_logger]) 59 | model.save("kddresults/dnn2layer/dnn2layer_model.hdf5") 60 | ''' 61 | 62 | score = [] 63 | name = [] 64 | import os 65 | for file in os.listdir("kddresults/dnn2layer/"): 66 | print("within a loop") 67 | model.load_weights("kddresults/dnn2layer/"+file) 68 | # make predictions 69 | testPredict = model.predict_classes(X_test) 70 | accuracy = accuracy_score(y_test, testPredict) 71 | print(accuracy) 72 | print(file) 73 | score.append(accuracy) 74 | name.append(file) 75 | 76 | print(max(score)) 77 | 78 | 79 | 80 | 81 | 82 | 83 | model.load_weights("kddresults/dnn2layer/"+name[score.index(max(score))]) 84 | pred = model.predict_classes(X_test) 85 | proba = model.predict_proba(X_test) 86 | np.savetxt("res/dnn2predicted.txt", pred) 87 | np.savetxt("res/dnn2probability.txt", proba) 88 | 89 | accuracy = accuracy_score(y_test, pred) 90 | recall = recall_score(y_test, pred , average="binary") 91 | precision = precision_score(y_test, pred , average="binary") 92 | f1 = f1_score(y_test, pred, average="binary") 93 | 94 | 95 | print("----------------------------------------------") 96 | print("accuracy") 97 | print("%.3f" %accuracy) 98 | print("precision") 99 | print("%.3f" %precision) 100 | print("racall") 101 | print("%.3f" %recall) 102 | print("f1score") 103 | print("%.3f" %f1) 104 | 105 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/dnn/dnn3.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score,f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 14 | from sklearn import metrics 15 | from sklearn.preprocessing import Normalizer 16 | import h5py 17 | from keras import callbacks 18 | from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, CSVLogger 19 | from sklearn.utils import shuffle 20 | 21 | 22 | traindata = pd.read_csv('kdd/binary/Training.csv', header=None) 23 | testdata = pd.read_csv('kdd/binary/Testing.csv', header=None) 24 | 25 | traindata = shuffle(traindata) 26 | testdata = shuffle(testdata) 27 | 28 | 29 | X = traindata.iloc[:,0:600] 30 | Y = traindata.iloc[:,600] 31 | C = testdata.iloc[:,600] 32 | T = testdata.iloc[:,0:600] 33 | 34 | y_train = np.array(Y) 35 | y_test = np.array(C) 36 | 37 | 38 | X_train = np.array(X) 39 | X_test = np.array(T) 40 | 41 | 42 | batch_size = 64 43 | 44 | # 1. define the network 45 | model = Sequential() 46 | model.add(Dense(1024,input_dim=600,activation='relu')) 47 | model.add(Dropout(0.01)) 48 | model.add(Dense(768,activation='relu')) 49 | model.add(Dropout(0.01)) 50 | model.add(Dense(512,activation='relu')) 51 | model.add(Dropout(0.01)) 52 | model.add(Dense(1)) 53 | model.add(Activation('sigmoid')) 54 | 55 | # try using different optimizers and different optimizer configs 56 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 57 | checkpointer = callbacks.ModelCheckpoint(filepath="kddresults/dnn3layer/checkpoint-{epoch:02d}.hdf5", verbose=1, save_best_only=True, monitor='loss') 58 | csv_logger = CSVLogger('kddresults/dnn3layer/training_set_dnnanalysis.csv',separator=',', append=False) 59 | model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=1000, callbacks=[checkpointer,csv_logger]) 60 | model.save("kddresults/dnn3layer/dnn3layer_model.hdf5") 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/dnn/dnn3test.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score,f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 14 | from sklearn import metrics 15 | from sklearn.preprocessing import Normalizer 16 | import h5py 17 | from keras import callbacks 18 | from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, CSVLogger 19 | from sklearn.utils import shuffle 20 | 21 | 22 | traindata = pd.read_csv('kdd/binary/Training.csv', header=None) 23 | testdata = pd.read_csv('kdd/binary/Testing.csv', header=None) 24 | 25 | traindata = shuffle(traindata) 26 | testdata = shuffle(testdata) 27 | 28 | 29 | X = traindata.iloc[:,0:600] 30 | Y = traindata.iloc[:,600] 31 | C = testdata.iloc[:,600] 32 | T = testdata.iloc[:,0:600] 33 | 34 | y_train = np.array(Y) 35 | y_test = np.array(C) 36 | 37 | 38 | X_train = np.array(X) 39 | X_test = np.array(T) 40 | 41 | 42 | batch_size = 64 43 | 44 | # 1. define the network 45 | model = Sequential() 46 | model.add(Dense(1024,input_dim=600,activation='relu')) 47 | model.add(Dropout(0.01)) 48 | model.add(Dense(768,activation='relu')) 49 | model.add(Dropout(0.01)) 50 | model.add(Dense(512,activation='relu')) 51 | model.add(Dropout(0.01)) 52 | model.add(Dense(1)) 53 | model.add(Activation('sigmoid')) 54 | 55 | ''' 56 | # try using different optimizers and different optimizer configs 57 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 58 | checkpointer = callbacks.ModelCheckpoint(filepath="kddresults/dnn3layer/checkpoint-{epoch:02d}.hdf5", verbose=1, save_best_only=True, monitor='loss') 59 | csv_logger = CSVLogger('kddresults/dnn3layer/training_set_dnnanalysis.csv',separator=',', append=False) 60 | model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=1000, callbacks=[checkpointer,csv_logger]) 61 | model.save("kddresults/dnn3layer/dnn3layer_model.hdf5") 62 | ''' 63 | 64 | 65 | score = [] 66 | name = [] 67 | import os 68 | for file in os.listdir("kddresults/dnn3layer/"): 69 | print("within a loop") 70 | model.load_weights("kddresults/dnn3layer/"+file) 71 | # make predictions 72 | testPredict = model.predict_classes(X_test) 73 | accuracy = accuracy_score(y_test, testPredict) 74 | print(accuracy) 75 | print(file) 76 | score.append(accuracy) 77 | name.append(file) 78 | 79 | print(max(score)) 80 | 81 | 82 | model.load_weights("kddresults/dnn3layer/"+name[score.index(max(score))]) 83 | pred = model.predict_classes(X_test) 84 | proba = model.predict_proba(X_test) 85 | np.savetxt("res/dnn3predicted.txt", pred) 86 | np.savetxt("res/dnn3probability.txt", proba) 87 | 88 | 89 | 90 | accuracy = accuracy_score(y_test, pred) 91 | recall = recall_score(y_test, pred , average="binary") 92 | precision = precision_score(y_test, pred , average="binary") 93 | f1 = f1_score(y_test, pred, average="binary") 94 | 95 | 96 | print("----------------------------------------------") 97 | print("accuracy") 98 | print("%.3f" %accuracy) 99 | print("precision") 100 | print("%.3f" %precision) 101 | print("racall") 102 | print("%.3f" %recall) 103 | print("f1score") 104 | print("%.3f" %f1) 105 | 106 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/dnn/dnn4.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score,f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 14 | from sklearn import metrics 15 | from sklearn.preprocessing import Normalizer 16 | import h5py 17 | from keras import callbacks 18 | from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, CSVLogger 19 | from sklearn.utils import shuffle 20 | 21 | 22 | traindata = pd.read_csv('kdd/binary/Training.csv', header=None) 23 | testdata = pd.read_csv('kdd/binary/Testing.csv', header=None) 24 | 25 | traindata = shuffle(traindata) 26 | testdata = shuffle(testdata) 27 | 28 | 29 | X = traindata.iloc[:,0:600] 30 | Y = traindata.iloc[:,600] 31 | C = testdata.iloc[:,600] 32 | T = testdata.iloc[:,0:600] 33 | 34 | y_train = np.array(Y) 35 | y_test = np.array(C) 36 | 37 | 38 | X_train = np.array(X) 39 | X_test = np.array(T) 40 | 41 | 42 | batch_size = 64 43 | 44 | # 1. define the network 45 | model = Sequential() 46 | model.add(Dense(1024,input_dim=600,activation='relu')) 47 | model.add(Dropout(0.01)) 48 | model.add(Dense(768,activation='relu')) 49 | model.add(Dropout(0.01)) 50 | model.add(Dense(512,activation='relu')) 51 | model.add(Dropout(0.01)) 52 | model.add(Dense(256,activation='relu')) 53 | model.add(Dropout(0.01)) 54 | model.add(Dense(1)) 55 | model.add(Activation('sigmoid')) 56 | 57 | # try using different optimizers and different optimizer configs 58 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 59 | checkpointer = callbacks.ModelCheckpoint(filepath="kddresults/dnn4layer/checkpoint-{epoch:02d}.hdf5", verbose=1, save_best_only=True, monitor='loss') 60 | csv_logger = CSVLogger('kddresults/dnn4layer/training_set_dnnanalysis.csv',separator=',', append=False) 61 | model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=1000, callbacks=[checkpointer,csv_logger]) 62 | model.save("kddresults/dnn4layer/dnn4layer_model.hdf5") 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/dnn/dnn4test.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score,f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 14 | from sklearn import metrics 15 | from sklearn.preprocessing import Normalizer 16 | import h5py 17 | from keras import callbacks 18 | from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, CSVLogger 19 | from sklearn.utils import shuffle 20 | 21 | 22 | traindata = pd.read_csv('kdd/binary/Training.csv', header=None) 23 | testdata = pd.read_csv('kdd/binary/Testing.csv', header=None) 24 | 25 | traindata = shuffle(traindata) 26 | testdata = shuffle(testdata) 27 | 28 | 29 | X = traindata.iloc[:,0:600] 30 | Y = traindata.iloc[:,600] 31 | C = testdata.iloc[:,600] 32 | T = testdata.iloc[:,0:600] 33 | 34 | y_train = np.array(Y) 35 | y_test = np.array(C) 36 | 37 | 38 | X_train = np.array(X) 39 | X_test = np.array(T) 40 | 41 | 42 | batch_size = 64 43 | 44 | # 1. define the network 45 | model = Sequential() 46 | model.add(Dense(1024,input_dim=600,activation='relu')) 47 | model.add(Dropout(0.01)) 48 | model.add(Dense(768,activation='relu')) 49 | model.add(Dropout(0.01)) 50 | model.add(Dense(512,activation='relu')) 51 | model.add(Dropout(0.01)) 52 | model.add(Dense(256,activation='relu')) 53 | model.add(Dropout(0.01)) 54 | model.add(Dense(1)) 55 | model.add(Activation('sigmoid')) 56 | 57 | ''' 58 | # try using different optimizers and different optimizer configs 59 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 60 | checkpointer = callbacks.ModelCheckpoint(filepath="kddresults/dnn4layer/checkpoint-{epoch:02d}.hdf5", verbose=1, save_best_only=True, monitor='loss') 61 | csv_logger = CSVLogger('kddresults/dnn4layer/training_set_dnnanalysis.csv',separator=',', append=False) 62 | model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=1000, callbacks=[checkpointer,csv_logger]) 63 | model.save("kddresults/dnn4layer/dnn4layer_model.hdf5") 64 | 65 | 66 | ''' 67 | 68 | 69 | score = [] 70 | name = [] 71 | import os 72 | for file in os.listdir("kddresults/dnn4layer/"): 73 | print("within a loop") 74 | model.load_weights("kddresults/dnn4layer/"+file) 75 | # make predictions 76 | testPredict = model.predict_classes(X_test) 77 | accuracy = accuracy_score(y_test, testPredict) 78 | print(accuracy) 79 | print(file) 80 | score.append(accuracy) 81 | name.append(file) 82 | 83 | print(max(score)) 84 | 85 | 86 | model.load_weights("kddresults/dnn4layer/"+name[score.index(max(score))]) 87 | pred = model.predict_classes(X_test) 88 | proba = model.predict_proba(X_test) 89 | np.savetxt("res/dnn4predicted.txt", pred) 90 | np.savetxt("res/dnn4probability.txt", proba) 91 | 92 | accuracy = accuracy_score(y_test, pred) 93 | recall = recall_score(y_test, pred , average="binary") 94 | precision = precision_score(y_test, pred , average="binary") 95 | f1 = f1_score(y_test, pred, average="binary") 96 | 97 | 98 | print("----------------------------------------------") 99 | print("accuracy") 100 | print("%.3f" %accuracy) 101 | print("precision") 102 | print("%.3f" %precision) 103 | print("racall") 104 | print("%.3f" %recall) 105 | print("f1score") 106 | print("%.3f" %f1) 107 | 108 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/dnn/dnn5.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score,f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 14 | from sklearn import metrics 15 | from sklearn.preprocessing import Normalizer 16 | import h5py 17 | from keras import callbacks 18 | from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, CSVLogger 19 | from sklearn.utils import shuffle 20 | 21 | traindata = pd.read_csv('kdd/binary/Training.csv', header=None) 22 | testdata = pd.read_csv('kdd/binary/Testing.csv', header=None) 23 | 24 | traindata = shuffle(traindata) 25 | testdata = shuffle(testdata) 26 | 27 | 28 | X = traindata.iloc[:,0:600] 29 | Y = traindata.iloc[:,600] 30 | C = testdata.iloc[:,600] 31 | T = testdata.iloc[:,0:600] 32 | 33 | y_train = np.array(Y) 34 | y_test = np.array(C) 35 | 36 | 37 | X_train = np.array(X) 38 | X_test = np.array(T) 39 | 40 | 41 | batch_size = 64 42 | 43 | # 1. define the network 44 | model = Sequential() 45 | model.add(Dense(1024,input_dim=600,activation='relu')) 46 | model.add(Dropout(0.01)) 47 | model.add(Dense(768,activation='relu')) 48 | model.add(Dropout(0.01)) 49 | model.add(Dense(512,activation='relu')) 50 | model.add(Dropout(0.01)) 51 | model.add(Dense(256,activation='relu')) 52 | model.add(Dropout(0.01)) 53 | model.add(Dense(128,activation='relu')) 54 | model.add(Dropout(0.01)) 55 | model.add(Dense(1)) 56 | model.add(Activation('sigmoid')) 57 | 58 | # try using different optimizers and different optimizer configs 59 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 60 | checkpointer = callbacks.ModelCheckpoint(filepath="kddresults/dnn5layer/checkpoint-{epoch:02d}.hdf5", verbose=1, save_best_only=True, monitor='loss') 61 | csv_logger = CSVLogger('kddresults/dnn5layer/training_set_dnnanalysis.csv',separator=',', append=False) 62 | model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=1000, callbacks=[checkpointer,csv_logger]) 63 | model.save("kddresults/dnn5layer/dnn5layer_model.hdf5") 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/dnn/dnn5test.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score,f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 14 | from sklearn import metrics 15 | from sklearn.preprocessing import Normalizer 16 | import h5py 17 | from keras import callbacks 18 | from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, CSVLogger 19 | from sklearn.utils import shuffle 20 | 21 | traindata = pd.read_csv('kdd/binary/Training.csv', header=None) 22 | testdata = pd.read_csv('kdd/binary/Testing.csv', header=None) 23 | 24 | traindata = shuffle(traindata) 25 | testdata = shuffle(testdata) 26 | 27 | 28 | X = traindata.iloc[:,0:600] 29 | Y = traindata.iloc[:,600] 30 | C = testdata.iloc[:,600] 31 | T = testdata.iloc[:,0:600] 32 | 33 | y_train = np.array(Y) 34 | y_test = np.array(C) 35 | 36 | 37 | X_train = np.array(X) 38 | X_test = np.array(T) 39 | 40 | 41 | batch_size = 64 42 | 43 | # 1. define the network 44 | model = Sequential() 45 | model.add(Dense(1024,input_dim=600,activation='relu')) 46 | model.add(Dropout(0.01)) 47 | model.add(Dense(768,activation='relu')) 48 | model.add(Dropout(0.01)) 49 | model.add(Dense(512,activation='relu')) 50 | model.add(Dropout(0.01)) 51 | model.add(Dense(256,activation='relu')) 52 | model.add(Dropout(0.01)) 53 | model.add(Dense(128,activation='relu')) 54 | model.add(Dropout(0.01)) 55 | model.add(Dense(1)) 56 | model.add(Activation('sigmoid')) 57 | 58 | ''' 59 | # try using different optimizers and different optimizer configs 60 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 61 | checkpointer = callbacks.ModelCheckpoint(filepath="kddresults/dnn5layer/checkpoint-{epoch:02d}.hdf5", verbose=1, save_best_only=True, monitor='loss') 62 | csv_logger = CSVLogger('kddresults/dnn5layer/training_set_dnnanalysis.csv',separator=',', append=False) 63 | model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=1000, callbacks=[checkpointer,csv_logger]) 64 | model.save("kddresults/dnn5layer/dnn5layer_model.hdf5") 65 | 66 | ''' 67 | 68 | 69 | score = [] 70 | name = [] 71 | import os 72 | for file in os.listdir("kddresults/dnn5layer/"): 73 | print("within a loop") 74 | model.load_weights("kddresults/dnn5layer/"+file) 75 | # make predictions 76 | testPredict = model.predict_classes(X_test) 77 | accuracy = accuracy_score(y_test, testPredict) 78 | print(accuracy) 79 | print(file) 80 | score.append(accuracy) 81 | name.append(file) 82 | 83 | print(max(score)) 84 | 85 | 86 | 87 | 88 | model.load_weights("kddresults/dnn5layer/"+name[score.index(max(score))]) 89 | pred = model.predict_classes(X_test) 90 | proba = model.predict_proba(X_test) 91 | np.savetxt("res/dnn5predicted.txt", pred) 92 | np.savetxt("res/dnn5probability.txt", proba) 93 | 94 | 95 | accuracy = accuracy_score(y_test, pred) 96 | recall = recall_score(y_test, pred , average="binary") 97 | precision = precision_score(y_test, pred , average="binary") 98 | f1 = f1_score(y_test, pred, average="binary") 99 | 100 | 101 | print("----------------------------------------------") 102 | print("accuracy") 103 | print("%.3f" %accuracy) 104 | print("precision") 105 | print("%.3f" %precision) 106 | print("racall") 107 | print("%.3f" %recall) 108 | print("f1score") 109 | print("%.3f" %f1) 110 | 111 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/dnn/dnn7.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score,f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 14 | from sklearn import metrics 15 | from sklearn.preprocessing import Normalizer 16 | import h5py 17 | from keras import callbacks 18 | from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, CSVLogger 19 | from sklearn.utils import shuffle 20 | 21 | traindata = pd.read_csv('kdd/binary/Training.csv', header=None) 22 | testdata = pd.read_csv('kdd/binary/Testing.csv', header=None) 23 | 24 | traindata = shuffle(traindata) 25 | testdata = shuffle(testdata) 26 | 27 | 28 | X = traindata.iloc[:,0:600] 29 | Y = traindata.iloc[:,600] 30 | C = testdata.iloc[:,600] 31 | T = testdata.iloc[:,0:600] 32 | 33 | y_train = np.array(Y) 34 | y_test = np.array(C) 35 | 36 | 37 | X_train = np.array(X) 38 | X_test = np.array(T) 39 | 40 | 41 | batch_size = 64 42 | 43 | # 1. define the network 44 | model = Sequential() 45 | model.add(Dense(3072,input_dim=600,activation='relu')) 46 | model.add(Dropout(0.01)) 47 | model.add(Dense(2048,activation='relu')) 48 | model.add(Dropout(0.01)) 49 | model.add(Dense(1024,activation='relu')) 50 | model.add(Dropout(0.01)) 51 | model.add(Dense(768,activation='relu')) 52 | model.add(Dropout(0.01)) 53 | model.add(Dense(512,activation='relu')) 54 | model.add(Dropout(0.01)) 55 | model.add(Dense(256,activation='relu')) 56 | model.add(Dropout(0.01)) 57 | model.add(Dense(128,activation='relu')) 58 | model.add(Dropout(0.01)) 59 | model.add(Dense(1)) 60 | model.add(Activation('sigmoid')) 61 | print(model.summary()) 62 | # try using different optimizers and different optimizer configs 63 | ''' 64 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 65 | checkpointer = callbacks.ModelCheckpoint(filepath="kddresults/dnn7layer/checkpoint-{epoch:02d}.hdf5", verbose=1, save_best_only=True, monitor='loss') 66 | csv_logger = CSVLogger('kddresults/dnn7layer/training_set_dnnanalysis.csv',separator=',', append=False) 67 | model.fit(X_train, y_train,batch_size=batch_size, nb_epoch=1000, callbacks=[checkpointer,csv_logger]) 68 | model.save("kddresults/dnn7layer/dnn7layer_model.hdf5") 69 | ''' 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/dnn/dnn7test.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score,f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 14 | from sklearn import metrics 15 | from sklearn.preprocessing import Normalizer 16 | import h5py 17 | from keras import callbacks 18 | from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, CSVLogger 19 | from sklearn.utils import shuffle 20 | 21 | traindata = pd.read_csv('kdd/binary/Training.csv', header=None) 22 | testdata = pd.read_csv('kdd/binary/Testing.csv', header=None) 23 | 24 | traindata = shuffle(traindata) 25 | testdata = shuffle(testdata) 26 | 27 | 28 | X = traindata.iloc[:,0:600] 29 | Y = traindata.iloc[:,600] 30 | C = testdata.iloc[:,600] 31 | T = testdata.iloc[:,0:600] 32 | 33 | y_train = np.array(Y) 34 | y_test = np.array(C) 35 | 36 | 37 | X_train = np.array(X) 38 | X_test = np.array(T) 39 | 40 | 41 | batch_size = 64 42 | 43 | # 1. define the network 44 | model = Sequential() 45 | model.add(Dense(3072,input_dim=600,activation='relu')) 46 | model.add(Dropout(0.01)) 47 | model.add(Dense(2048,activation='relu')) 48 | model.add(Dropout(0.01)) 49 | model.add(Dense(1024,activation='relu')) 50 | model.add(Dropout(0.01)) 51 | model.add(Dense(768,activation='relu')) 52 | model.add(Dropout(0.01)) 53 | model.add(Dense(512,activation='relu')) 54 | model.add(Dropout(0.01)) 55 | model.add(Dense(256,activation='relu')) 56 | model.add(Dropout(0.01)) 57 | model.add(Dense(128,activation='relu')) 58 | model.add(Dropout(0.01)) 59 | model.add(Dense(1)) 60 | model.add(Activation('sigmoid')) 61 | 62 | ''' 63 | # try using different optimizers and different optimizer configs 64 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 65 | checkpointer = callbacks.ModelCheckpoint(filepath="kddresults/dnn7layer/checkpoint-{epoch:02d}.hdf5", verbose=1, save_best_only=True, monitor='loss') 66 | csv_logger = CSVLogger('kddresults/dnn7layer/training_set_dnnanalysis.csv',separator=',', append=False) 67 | model.fit(X_train, y_train,batch_size=batch_size, nb_epoch=1000, callbacks=[checkpointer,csv_logger]) 68 | model.save("kddresults/dnn7layer/dnn7layer_model.hdf5") 69 | ''' 70 | 71 | score = [] 72 | name = [] 73 | import os 74 | for file in os.listdir("kddresults/dnn7layer/"): 75 | print("within a loop") 76 | model.load_weights("kddresults/dnn7layer/"+file) 77 | # make predictions 78 | testPredict = model.predict_classes(X_test) 79 | accuracy = accuracy_score(y_test, testPredict) 80 | print(accuracy) 81 | print(file) 82 | score.append(accuracy) 83 | name.append(file) 84 | 85 | print(max(score)) 86 | 87 | 88 | 89 | 90 | 91 | 92 | model.load_weights("kddresults/dnn7layer/"+name[score.index(max(score))]) 93 | pred = model.predict_classes(X_test) 94 | proba = model.predict_proba(X_test) 95 | np.savetxt("res/dnn7predicted.txt", pred) 96 | np.savetxt("res/dnn7probability.txt", proba) 97 | 98 | accuracy = accuracy_score(y_test, pred) 99 | recall = recall_score(y_test, pred , average="binary") 100 | precision = precision_score(y_test, pred , average="binary") 101 | f1 = f1_score(y_test, pred, average="binary") 102 | 103 | 104 | print("----------------------------------------------") 105 | print("accuracy") 106 | print("%.3f" %accuracy) 107 | print("precision") 108 | print("%.3f" %precision) 109 | print("racall") 110 | print("%.3f" %recall) 111 | print("f1score") 112 | print("%.3f" %f1) 113 | 114 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/preprocess/__init__.py: -------------------------------------------------------------------------------- 1 | from . import model 2 | from . import parser -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/preprocess/model.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinayakumarr/Signal-Processing-and-Pattern-Classification/38d4fa08d4d9d4cd01b15ad4ba0bce55100711cc/Signal Processing and Pattern Classification/PCG-2016-DNN/preprocess/model.pyc -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/preprocess/parser.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pickle 3 | import numpy as np 4 | from scipy.io import wavfile 5 | from scipy.fftpack import fft 6 | from scipy.signal import butter, lfilter 7 | from sklearn.preprocessing import normalize 8 | from sklearn.cross_validation import train_test_split 9 | from collections import namedtuple 10 | from sklearn.cross_validation import check_random_state 11 | 12 | 13 | class PCG: 14 | """ 15 | PCG is a container for loading phonocardiogram (PCG) data for the [2016 physionet 16 | challenge](http://physionet.org/challenge/2016). Raw wav files are parsed into 17 | features, class labels are extracted from header files and data is split into 18 | training and testing groups. 19 | """ 20 | def __init__(self, basepath, random_state=42): 21 | self.basepath = basepath 22 | self.class_name_to_id = {"normal": 0, "abnormal": 1} 23 | self.nclasses = len(self.class_name_to_id.keys()) 24 | 25 | self.train = None 26 | self.test = None 27 | 28 | self.n_samples = 0 29 | 30 | self.X = None 31 | self.y = None 32 | 33 | self.random_state = random_state 34 | 35 | 36 | def initialize_wav_data(self): 37 | """ 38 | Load the original wav files and extract features. Warning, this can take a 39 | while due to slow FFTs. 40 | 41 | Parameters 42 | ---------- 43 | None 44 | 45 | Returns 46 | ------- 47 | None 48 | """ 49 | self.__load_wav_file() 50 | self.__split_train_test() 51 | # TODO: check if directory exists 52 | self.save("/tmp") 53 | 54 | def save(self, save_path): 55 | """ 56 | Persist the PCG class to disk 57 | 58 | Parameters 59 | ---------- 60 | save_path: str 61 | Location on disk to store the parsed PCG metadata 62 | 63 | Returns 64 | ------- 65 | None 66 | 67 | """ 68 | print("fjklsdfjklsdjfklsdjfkls====================") 69 | np.save(os.path.join(save_path, "fX.npy"), self.X) 70 | np.save(os.path.join(save_path, "fy.npy"), self.y) 71 | with open( os.path.join(save_path, "meta"), "w") as fout: 72 | pickle.dump((self.basepath, self.class_name_to_id, self.nclasses, 73 | self.n_samples, self.random_state), fout) 74 | 75 | def load(self, load_path): 76 | """ 77 | Load a previously stored PCG class. 78 | 79 | Parameters 80 | ---------- 81 | load_path: str 82 | Location on disk to load parsed PCG data 83 | 84 | Returns 85 | ------- 86 | None 87 | 88 | """ 89 | self.X = np.load(os.path.join(load_path, "X.npy")) 90 | self.y = np.load(os.path.join(load_path, "y.npy")) 91 | with open(os.path.join(load_path, "meta"), "r") as fin: 92 | (self.basepath, self.class_name_to_id, self.nclasses, 93 | self.n_samples, self.random_state) = pickle.load(fin) 94 | self.__split_train_test() 95 | 96 | def __load_wav_file(self, doFFT=True): 97 | """ 98 | Loads physio 2016 challenge dataset from self.basepath by crawling the path. 99 | For each discovered wav file: 100 | 101 | * Attempt to parse the header file for class label 102 | * Attempt to load the wav file 103 | * Calculate features from the wav file. if doFFT, features are 104 | the Fourier transform of the original signal. Else, features are 105 | the raw signal itself truncated to a fixed length 106 | 107 | Parameters 108 | ---------- 109 | doFFT: bool 110 | True if features to be calculated are the FFT of the original signal 111 | 112 | Returns 113 | ------- 114 | None 115 | """ 116 | 117 | # First pass to calculate number of samples 118 | # ensure each wav file has an associated and parsable 119 | # Header file 120 | wav_file_names = [] 121 | class_labels = [] 122 | for root, dirs, files in os.walk(self.basepath): 123 | # Ignore validation for now! 124 | if "validation" in root: 125 | continue 126 | for file in files: 127 | if file.endswith('.wav'): 128 | try: 129 | base_file_name = file.rstrip(".wav") 130 | label_file_name = os.path.join(root, base_file_name + ".hea") 131 | 132 | class_label = self.__parse_class_label(label_file_name) 133 | class_labels.append(self.class_name_to_id[class_label]) 134 | wav_file_names.append(os.path.join(root, file)) 135 | 136 | self.n_samples += 1 137 | except InvalidHeaderFileException as e: 138 | print e 139 | 140 | if doFFT: 141 | fft_embedding_size = 400 142 | highpass_embedding_size = 200 143 | X = np.zeros([self.n_samples, fft_embedding_size + highpass_embedding_size]) 144 | else: 145 | # Truncating the length of each wav file to the 146 | # min file size (10611) (Note: this is bad 147 | # And causes loss of information!) 148 | embedding_size = 10611 149 | X = np.zeros([self.n_samples, embedding_size]) 150 | 151 | for idx, wavfname in enumerate(wav_file_names): 152 | rate, wf = wavfile.read(wavfname) 153 | wf = normalize(wf.reshape(1, -1)) 154 | 155 | if doFFT: 156 | # We only care about the magnitude of each frequency 157 | wf_fft = np.abs(fft(wf)) 158 | wf_fft = wf_fft[:, :fft_embedding_size].reshape(-1) 159 | 160 | # Filter out high frequencies via Butter transform 161 | # The human heart maxes out around 150bpm = 2.5Hz 162 | # Let's filter out any frequency significantly above this 163 | nyquist = 0.5 * rate 164 | cutoff_freq = 4.0 # Hz 165 | w0, w1 = butter(5, cutoff_freq / nyquist, btype='low', analog=False) 166 | wf_low_pass = lfilter(w0, w1, wf) 167 | 168 | # FFT the filtered signal 169 | wf_low_pass_fft = np.abs(fft(wf_low_pass)) 170 | wf_low_pass_fft = wf_low_pass_fft[:, :highpass_embedding_size].reshape(-1) 171 | 172 | features = np.concatenate((wf_fft, wf_low_pass_fft)) 173 | else: 174 | features = wf[:embedding_size] 175 | 176 | X[idx, :] = features 177 | idx += 1 178 | 179 | self.X = X 180 | 181 | class_labels = np.array(class_labels) 182 | 183 | # Map from dense to one hot 184 | self.y = np.eye(self.nclasses)[class_labels] 185 | 186 | def __parse_class_label(self, label_file_name): 187 | """ 188 | Parses physio bank header files, where the class label 189 | is located in the last line of the file. An example header 190 | file could contain: 191 | 192 | f0112 1 2000 60864 193 | f0112.wav 16+44 1 16 0 0 0 0 PCG 194 | # Normal 195 | 196 | 197 | Parameters 198 | ---------- 199 | label_file_name: str 200 | Path to a specific header file 201 | 202 | Returns 203 | ------- 204 | class_label: str 205 | One of `normal` or `abnormal` 206 | """ 207 | with open(label_file_name, 'r') as fin: 208 | header = fin.readlines() 209 | 210 | comments = [line for line in header if line.startswith("#")] 211 | if not len(comments) == 1: 212 | raise InvalidHeaderFileException("Invalid label file %s" % label_file_name) 213 | 214 | class_label = str(comments[0]).lstrip("#").rstrip("\r").strip().lower() 215 | 216 | if not class_label in self.class_name_to_id.keys(): 217 | raise InvalidHeaderFileException("Invalid class label %s" % class_label) 218 | 219 | return class_label 220 | 221 | def __split_train_test(self): 222 | """ 223 | Splits internal features (self.X) and class labels (self.y) into 224 | balanced training and test sets using sklearn's helper function. 225 | 226 | Notes: 227 | * if self.random_state is None, splits will be randomly seeded 228 | otherwise, self.random_state defines the random seed to deterministicly 229 | split training and test data 230 | * For now, class balancing is done by subsampling the overrepresented class. 231 | Ideally this would be pushed down to the cost function in TensorFlow. 232 | 233 | Returns 234 | ------- 235 | None 236 | """ 237 | mlData = namedtuple('ml_data', 'X y') 238 | 239 | num_pos, num_neg = np.sum(self.y, axis=0) 240 | 241 | # Remove samples to rebalance classes 242 | # TODO: push this down into the cost function 243 | undersample_rate = num_neg / num_pos 244 | over_represented_idxs = self.y[:, 1] == 0 245 | under_represented_idxs = self.y[:, 1] == 1 246 | random_indexes_to_remove = np.random.rand(self.y.shape[0]) < undersample_rate 247 | sample_idxs = (over_represented_idxs & random_indexes_to_remove | 248 | under_represented_idxs) 249 | 250 | X_balanced = self.X[sample_idxs, :] 251 | y_balanced = self.y[sample_idxs, :] 252 | 253 | X_train, X_test, y_train, y_test = train_test_split(X_balanced, y_balanced, test_size=0.25, 254 | random_state=self.random_state) 255 | 256 | self.train = mlData(X=X_train, y=y_train) 257 | self.test = mlData(X=X_test, y=y_test) 258 | 259 | def get_mini_batch(self, batch_size): 260 | """ 261 | Helper function for sampling mini-batches from the training 262 | set. Note, random_state needs to be set to None or the same 263 | mini batch will be sampled eternally! 264 | 265 | Parameters 266 | ---------- 267 | batch_size: int 268 | Number of elements to return in the mini batch 269 | 270 | Returns 271 | ------- 272 | X: np.ndarray 273 | A feature matrix subsampled from self.train 274 | 275 | y: np.ndarray 276 | A one-hot matrix of class labels subsampled from self.train 277 | """ 278 | random_state = check_random_state(None) # self.random_state) 279 | n_training_samples = self.train.X.shape[0] 280 | minibatch_indices = random_state.randint(0, n_training_samples - 1, batch_size) 281 | 282 | return self.train.X[minibatch_indices, :], self.train.y[minibatch_indices, :] 283 | 284 | 285 | class InvalidHeaderFileException(Exception): 286 | def __init__(self, *args, **kwargs): 287 | super(args, kwargs) 288 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/preprocess/parser.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinayakumarr/Signal-Processing-and-Pattern-Classification/38d4fa08d4d9d4cd01b15ad4ba0bce55100711cc/Signal Processing and Pattern Classification/PCG-2016-DNN/preprocess/parser.pyc -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/preprocess/train_model.py: -------------------------------------------------------------------------------- 1 | from parser import PCG 2 | import sys 3 | 4 | true_strs = {"True", "true", "t"} 5 | 6 | def load_and_train_model(model_path, load_pretrained): 7 | pcg = PCG(model_path) 8 | 9 | if load_pretrained: 10 | pcg.load("/tmp") 11 | else: 12 | pcg.initialize_wav_data() 13 | print("-----------------------------------------------------------------------") 14 | 15 | #cnn = CNN(pcg, epochs=100, dropout=0.5) 16 | #cnn.train() 17 | 18 | if __name__ == '__main__': 19 | data_path = sys.argv[1] 20 | 21 | load_pretrained = False 22 | if len(sys.argv) == 3: 23 | load_pretrained = sys.argv[2] in true_strs 24 | 25 | load_and_train_model(data_path, load_pretrained) 26 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/PCG-2016-DNN/requirements.txt: -------------------------------------------------------------------------------- 1 | appnope==0.1.0 2 | backports.shutil-get-terminal-size==1.0.0 3 | cycler==0.10.0 4 | decorator==4.0.10 5 | h5py==2.6.0 6 | ipdb==0.10.1 7 | ipython==5.0.0 8 | ipython-genutils==0.1.0 9 | matplotlib==1.5.1 10 | numpy==1.11.1 11 | pandas==0.18.1 12 | pathlib2==2.1.0 13 | pexpect==4.2.0 14 | pickleshare==0.7.3 15 | prompt-toolkit==1.0.3 16 | protobuf==3.0.0b2 17 | ptyprocess==0.5.1 18 | py==1.4.31 19 | Pygments==2.1.3 20 | pyparsing==2.1.4 21 | pytest==2.9.2 22 | python-dateutil==2.5.3 23 | pytz==2016.4 24 | scikit-learn==0.17.1 25 | scipy==0.17.1 26 | simplegeneric==0.8.1 27 | six==1.10.0 28 | traitlets==4.2.2 29 | wcwidth==0.1.7 30 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/README.md: -------------------------------------------------------------------------------- 1 | # Signal Processing and Pattern Classification 2 | 3 | Please cite the following papers, if you use the code as part of your research 4 | 5 | Real-Time Detection of Atrial Fibrillation from Short Time Single Lead ECG Traces Using Recurrent Neural Networks 6 | 7 | Instantaneous Heart Rate as a Robust Feature for Sleep Apnea Severity Detection using Deep Learning 8 | 9 | Single Sensor Techniques for Sleep Apnea Diagnosis using Deep Learning 10 | 11 | Anomaly detection in Phonocardiogram employing Deep learning 12 | 13 | Deep models for Phonocardiography (PCG) classification 14 | 15 | Atrial Fibrillation: Data set is from https://physionet.org/physiobank/database/afdb/ 16 | 17 | PCG-physionet: Data set is from https://physionet.org/challenge/2016/ 18 | 19 | Sleep Apnea: Data set is from https://www.physionet.org/physiobank/database/apnea-ecg/ 20 | 21 | heartsound - PCG: Data set is from http://www.peterjbentley.com/heartchallenge/ 22 | 23 | Other supported deep learning papers 24 | 25 | Evaluating Shallow and Deep Networks for Secure Shell (SSH)Traffic Analysis 26 | 27 | Evaluating Effectiveness of Shallow and Deep Networks to Intrusion Detection System 28 | 29 | Deep Android Malware Detection and Classification 30 | 31 | Long Short-Term Memory based Operation Log Anomaly Detection 32 | 33 | Deep Encrypted Text Categorization 34 | 35 | Applying Convolutional Neural Network for Network Intrusion Detection 36 | 37 | Secure Shell (SSH) Traffic Analysis with Flow based Features Using Shallow and Deep networks 38 | 39 | Applying Deep Learning Approaches for Network Traffic Prediction 40 | 41 | Evaluating Shallow and Deep Networks for Ransomware Detection and Classification 42 | 43 | Stock Price Prediction Using LSTM, RNN And CNN-Sliding Window Model 44 | 45 | Deep Power: Deep Learning Architectures for Power Quality Disturbances Classification 46 | 47 | DEFT 2017 - Texts Search @ TALN / RECITAL 2017: Deep Analysis of Opinion and Figurative language on Tweets in French 48 | 49 | Deep Stance and Gender Detection in Tweets on Catalan Independence@Ibereval 2017 50 | 51 | deepCybErNet at EmoInt-2017: Deep Emotion Intensities in Tweets 52 | 53 | Software Installation 54 | 55 | sudo apt-get install libatlas-base-dev gfortran python-dev 56 | 57 | sudo apt-get install python-pip 58 | 59 | sudo pip install --upgrade pip 60 | 61 | sudo pip install numpy 62 | 63 | sudo pip install scipy 64 | 65 | sudo pip install matplotlib 66 | 67 | Sudo pip install seaborn 68 | 69 | sudo pip install scikit-learn 70 | 71 | sudo pip install tensorflow 72 | 73 | sudo pip install theano 74 | 75 | sudo pip install keras 76 | 77 | sudo pip install pandas 78 | 79 | sudo pip install h5py 80 | 81 | sudo pip install jupyter 82 | 83 | sudo pip install ipython 84 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/atrial-fibrillation/convert.py: -------------------------------------------------------------------------------- 1 | import scipy.io 2 | import numpy as np 3 | import os 4 | from numpy import array 5 | vdata = [] 6 | 7 | for file in os.listdir("ECG/NSR/"): 8 | 9 | data = scipy.io.loadmat("ECG/NSR/"+file) 10 | datae = data['val'] 11 | 12 | vdata.append(datae[0]) 13 | print ",".join([str(x) for x in datae[0]] ) 14 | 15 | np.savetxt("NSR.csv", vdata, fmt="%0d",delimiter=',') 16 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/atrial-fibrillation/gru/gru.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score, 14 | f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 15 | from sklearn import metrics 16 | from sklearn.preprocessing import Normalizer 17 | import h5py 18 | from keras import callbacks 19 | 20 | 21 | traindata = pd.read_csv('dataset/traindata.csv', header=None) 22 | testdata = pd.read_csv('dataset/testdata.csv', header=None) 23 | 24 | 25 | X = traindata.iloc[:,1:15002] 26 | Y = traindata.iloc[:,0] 27 | C = testdata.iloc[:,0] 28 | T = testdata.iloc[:,1:15002] 29 | 30 | scaler = Normalizer().fit(X) 31 | trainX = scaler.transform(X) 32 | 33 | scaler = Normalizer().fit(T) 34 | testT = scaler.transform(T) 35 | 36 | y_train = np.array(Y) 37 | y_test = np.array(C) 38 | 39 | X_train = np.reshape(trainX, (trainX.shape[0], 1, trainX.shape[1])) 40 | X_test = np.reshape(testT, (testT.shape[0], 1, testT.shape[1])) 41 | 42 | 43 | batch_size = 4 44 | 45 | # 1. define the network 46 | model = Sequential() 47 | model.add(GRU(32,input_dim=15000)) # try using a GRU instead, for fun 48 | model.add(Dropout(0.1)) 49 | model.add(Dense(1)) 50 | model.add(Activation('sigmoid')) 51 | 52 | # try using different optimizers and different optimizer configs 53 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 54 | checkpointer = callbacks.ModelCheckpoint(filepath="logs/gru1layer/checkpoint-{epoch:02d}.hdf5", verbose=1, save_best_only=True, monitor='loss') 55 | model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=1000, callbacks=[checkpointer]) 56 | model.save("logs/grulayer/grulayer_model.hdf5") 57 | 58 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/atrial-fibrillation/gru/grutest.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score, 14 | f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 15 | from sklearn import metrics 16 | from sklearn.preprocessing import Normalizer 17 | import h5py 18 | from keras import callbacks 19 | 20 | 21 | testdata = pd.read_csv('dataset/testdata.csv', header=None) 22 | 23 | 24 | C = testdata.iloc[:,0] 25 | T = testdata.iloc[:,1:15002] 26 | 27 | scaler = Normalizer().fit(T) 28 | testT = scaler.transform(T) 29 | 30 | y_test = np.array(C) 31 | 32 | 33 | X_test = np.reshape(testT, (testT.shape[0], 1, testT.shape[1])) 34 | 35 | 36 | batch_size = 4 37 | 38 | # 1. define the network 39 | model = Sequential() 40 | model.add(GRU(32,input_dim=15000)) # try using a GRU instead, for fun 41 | model.add(Dropout(0.1)) 42 | model.add(Dense(1)) 43 | model.add(Activation('sigmoid')) 44 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 45 | 46 | 47 | 48 | 49 | from sklearn.metrics import confusion_matrix 50 | model.load_weights("logs/gru1layer/checkpoint-07.hdf5") 51 | y_pred = model.predict_classes(X_test) 52 | print(y_pred) 53 | print(confusion_matrix(y_test, y_pred)) 54 | loss, accuracy = model.evaluate(X_test, y_test) 55 | print("\nLoss: %.2f, Accuracy: %.2f%%" % (loss, accuracy*100)) 56 | y_prob = model.predict_proba(X_test) 57 | np.savetxt("gru.txt", y_prob) 58 | 59 | 60 | import os 61 | for file in os.listdir("logs/gru1layer/"): 62 | model.load_weights("logs/gru1layer/"+file) 63 | y_pred = model.predict_classes(X_test) 64 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 65 | loss, accuracy = model.evaluate(X_test, y_test) 66 | print(file) 67 | print("\nLoss: %.2f, Accuracy: %.2f%%" % (loss, accuracy*100)) 68 | print("---------------------------------------------------------------------------------") 69 | accuracy = accuracy_score(y_test, y_pred) 70 | recall = recall_score(y_test, y_pred , average="binary") 71 | precision = precision_score(y_test, y_pred , average="binary") 72 | f1 = f1_score(y_test, y_pred, average="binary") 73 | 74 | print("accuracy") 75 | print("%.3f" %accuracy) 76 | print("precision") 77 | print("%.3f" %precision) 78 | print("recall") 79 | print("%.3f" %recall) 80 | print("f1score") 81 | print("%.3f" %f1) 82 | 83 | 84 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/atrial-fibrillation/lstm/crossvalidation.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score,f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 14 | from sklearn import metrics 15 | from sklearn.preprocessing import Normalizer 16 | import h5py 17 | from keras import callbacks 18 | from keras.callbacks import ModelCheckpoint, EarlyStopping, ReduceLROnPlateau, CSVLogger 19 | from keras.wrappers.scikit_learn import KerasClassifier 20 | from sklearn.model_selection import StratifiedKFold 21 | from sklearn.model_selection import cross_val_score 22 | 23 | traindata = pd.read_csv('dataset/traindata.csv', header=None) 24 | testdata = pd.read_csv('dataset/testdata.csv', header=None) 25 | 26 | 27 | X = traindata.iloc[:,1:15002] 28 | Y = traindata.iloc[:,0] 29 | C = testdata.iloc[:,0] 30 | T = testdata.iloc[:,1:15002] 31 | 32 | scaler = Normalizer().fit(X) 33 | trainX = scaler.transform(X) 34 | 35 | scaler = Normalizer().fit(T) 36 | testT = scaler.transform(T) 37 | 38 | y_train = np.array(Y) 39 | y_test = np.array(C) 40 | 41 | X_train = np.reshape(trainX, (trainX.shape[0], 1, trainX.shape[1])) 42 | X_test = np.reshape(testT, (testT.shape[0], 1, testT.shape[1])) 43 | 44 | 45 | batch_size = 4 46 | 47 | # 1. define the network 48 | def create_model(): 49 | model = Sequential() 50 | model.add(LSTM(32,input_dim=15000)) # try using a GRU instead, for fun 51 | model.add(Dropout(0.1)) 52 | model.add(Dense(1)) 53 | model.add(Activation('sigmoid')) 54 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 55 | return model 56 | 57 | seed = 7 58 | np.random.seed(seed) 59 | 60 | 61 | model = KerasClassifier(build_fn=create_model, nb_epoch=1000, batch_size=4, verbose=0) 62 | kfold = StratifiedKFold(n_splits=5, shuffle=True, random_state=seed) 63 | results = cross_val_score(model, X_train, y_train, cv=kfold) 64 | print(results.mean()) 65 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/atrial-fibrillation/lstm/lstm.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score, 14 | f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 15 | from sklearn import metrics 16 | from sklearn.preprocessing import Normalizer 17 | import h5py 18 | from keras import callbacks 19 | 20 | 21 | traindata = pd.read_csv('dataset/traindata.csv', header=None) 22 | testdata = pd.read_csv('dataset/testdata.csv', header=None) 23 | 24 | 25 | X = traindata.iloc[:,1:15002] 26 | Y = traindata.iloc[:,0] 27 | C = testdata.iloc[:,0] 28 | T = testdata.iloc[:,1:15002] 29 | 30 | scaler = Normalizer().fit(X) 31 | trainX = scaler.transform(X) 32 | 33 | scaler = Normalizer().fit(T) 34 | testT = scaler.transform(T) 35 | 36 | y_train = np.array(Y) 37 | y_test = np.array(C) 38 | 39 | X_train = np.reshape(trainX, (trainX.shape[0], 1, trainX.shape[1])) 40 | X_test = np.reshape(testT, (testT.shape[0], 1, testT.shape[1])) 41 | 42 | 43 | batch_size = 4 44 | 45 | # 1. define the network 46 | model = Sequential() 47 | model.add(LSTM(32,input_dim=15000)) # try using a GRU instead, for fun 48 | model.add(Dropout(0.1)) 49 | model.add(Dense(1)) 50 | model.add(Activation('sigmoid')) 51 | 52 | # try using different optimizers and different optimizer configs 53 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 54 | checkpointer = callbacks.ModelCheckpoint(filepath="logs/lstm1layer/checkpoint-{epoch:02d}.hdf5", verbose=1, save_best_only=True, monitor='loss') 55 | model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=1000, callbacks=[checkpointer]) 56 | model.save("logs/lstm1layer/lstm1layer_model.hdf5") 57 | 58 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/atrial-fibrillation/lstm/lstmtest.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score, 14 | f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 15 | from sklearn import metrics 16 | from sklearn.preprocessing import Normalizer 17 | import h5py 18 | from keras import callbacks 19 | 20 | 21 | testdata = pd.read_csv('dataset/testdata.csv', header=None) 22 | 23 | 24 | C = testdata.iloc[:,0] 25 | T = testdata.iloc[:,1:15002] 26 | 27 | scaler = Normalizer().fit(T) 28 | testT = scaler.transform(T) 29 | 30 | y_test = np.array(C) 31 | 32 | 33 | X_test = np.reshape(testT, (testT.shape[0], 1, testT.shape[1])) 34 | 35 | 36 | batch_size = 2 37 | 38 | # 1. define the network 39 | model = Sequential() 40 | model.add(LSTM(32,input_dim=15000)) # try using a GRU instead, for fun 41 | model.add(Dropout(0.1)) 42 | model.add(Dense(1)) 43 | model.add(Activation('sigmoid')) 44 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 45 | 46 | from sklearn.metrics import confusion_matrix 47 | model.load_weights("logs/lstm1layer/checkpoint-07.hdf5") 48 | y_pred = model.predict_classes(X_test) 49 | print(y_pred) 50 | print(confusion_matrix(y_test, y_pred)) 51 | loss, accuracy = model.evaluate(X_test, y_test) 52 | print("\nLoss: %.2f, Accuracy: %.2f%%" % (loss, accuracy*100)) 53 | y_prob = model.predict_proba(X_test) 54 | np.savetxt("gru.txt", y_prob) 55 | 56 | 57 | import os 58 | for file in os.listdir("logs/lstm1layer/"): 59 | model.load_weights("logs/lstm1layer/"+file) 60 | y_pred = model.predict_classes(X_test) 61 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 62 | loss, accuracy = model.evaluate(X_test, y_test) 63 | print(file) 64 | print("\nLoss: %.2f, Accuracy: %.2f%%" % (loss, accuracy*100)) 65 | print("---------------------------------------------------------------------------------") 66 | accuracy = accuracy_score(y_test, y_pred) 67 | recall = recall_score(y_test, y_pred , average="binary") 68 | precision = precision_score(y_test, y_pred , average="binary") 69 | f1 = f1_score(y_test, y_pred, average="binary") 70 | 71 | print("accuracy") 72 | print("%.3f" %accuracy) 73 | print("precision") 74 | print("%.3f" %precision) 75 | print("recall") 76 | print("%.3f" %recall) 77 | print("f1score") 78 | print("%.3f" %f1) 79 | 80 | 81 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/atrial-fibrillation/rnn/rnn.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score, 14 | f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 15 | from sklearn import metrics 16 | from sklearn.preprocessing import Normalizer 17 | import h5py 18 | from keras import callbacks 19 | 20 | 21 | traindata = pd.read_csv('dataset/traindata.csv', header=None) 22 | testdata = pd.read_csv('dataset/testdata.csv', header=None) 23 | 24 | 25 | X = traindata.iloc[:,1:15002] 26 | Y = traindata.iloc[:,0] 27 | C = testdata.iloc[:,0] 28 | T = testdata.iloc[:,1:15002] 29 | 30 | scaler = Normalizer().fit(X) 31 | trainX = scaler.transform(X) 32 | 33 | scaler = Normalizer().fit(T) 34 | testT = scaler.transform(T) 35 | 36 | y_train = np.array(Y) 37 | y_test = np.array(C) 38 | 39 | X_train = np.reshape(trainX, (trainX.shape[0], 1, trainX.shape[1])) 40 | X_test = np.reshape(testT, (testT.shape[0], 1, testT.shape[1])) 41 | 42 | 43 | batch_size = 2 44 | 45 | # 1. define the network 46 | model = Sequential() 47 | model.add(SimpleRNN(64,input_dim=15000)) # try using a GRU instead, for fun 48 | model.add(Dropout(0.1)) 49 | model.add(Dense(1)) 50 | model.add(Activation('sigmoid')) 51 | 52 | # try using different optimizers and different optimizer configs 53 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 54 | checkpointer = callbacks.ModelCheckpoint(filepath="logs/rnn1layer/checkpoint-{epoch:02d}.hdf5", verbose=1, save_best_only=True, monitor='loss') 55 | model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=1000, callbacks=[checkpointer]) 56 | model.save("logs/rnn1layer/rnnlayer_model.hdf5") 57 | 58 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/atrial-fibrillation/rnn/rnntest.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from sklearn.cross_validation import train_test_split 3 | import pandas as pd 4 | import numpy as np 5 | np.random.seed(1337) # for reproducibility 6 | from keras.preprocessing import sequence 7 | from keras.utils import np_utils 8 | from keras.models import Sequential 9 | from keras.layers import Dense, Dropout, Activation, Embedding 10 | from keras.layers import LSTM, SimpleRNN, GRU 11 | from keras.datasets import imdb 12 | from keras.utils.np_utils import to_categorical 13 | from sklearn.metrics import (precision_score, recall_score, 14 | f1_score, accuracy_score,mean_squared_error,mean_absolute_error) 15 | from sklearn import metrics 16 | from sklearn.preprocessing import Normalizer 17 | import h5py 18 | from keras import callbacks 19 | 20 | 21 | testdata = pd.read_csv('dataset/testdata.csv', header=None) 22 | 23 | 24 | C = testdata.iloc[:,0] 25 | T = testdata.iloc[:,1:15002] 26 | 27 | scaler = Normalizer().fit(T) 28 | testT = scaler.transform(T) 29 | 30 | y_test = np.array(C) 31 | 32 | 33 | X_test = np.reshape(testT, (testT.shape[0], 1, testT.shape[1])) 34 | 35 | 36 | batch_size = 2 37 | 38 | # 1. define the network 39 | model = Sequential() 40 | model.add(SimpleRNN(64,input_dim=15000)) # try using a GRU instead, for fun 41 | model.add(Dropout(0.1)) 42 | model.add(Dense(1)) 43 | model.add(Activation('sigmoid')) 44 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 45 | 46 | import os 47 | for file in os.listdir("logs/rnn1layer/"): 48 | model.load_weights("logs/rnn1layer/"+file) 49 | y_pred = model.predict_classes(X_test) 50 | model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) 51 | loss, accuracy = model.evaluate(X_test, y_test) 52 | print(file) 53 | print("\nLoss: %.2f, Accuracy: %.2f%%" % (loss, accuracy*100)) 54 | print("---------------------------------------------------------------------------------") 55 | accuracy = accuracy_score(y_test, y_pred) 56 | recall = recall_score(y_test, y_pred , average="binary") 57 | precision = precision_score(y_test, y_pred , average="binary") 58 | f1 = f1_score(y_test, y_pred, average="binary") 59 | 60 | print("accuracy") 61 | print("%.3f" %accuracy) 62 | print("precision") 63 | print("%.3f" %precision) 64 | print("recall") 65 | print("%.3f" %recall) 66 | print("f1score") 67 | print("%.3f" %f1) 68 | 69 | 70 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/basics/data/places.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinayakumarr/Signal-Processing-and-Pattern-Classification/38d4fa08d4d9d4cd01b15ad4ba0bce55100711cc/Signal Processing and Pattern Classification/basics/data/places.h5 -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/basics/data/save.p: -------------------------------------------------------------------------------- 1 | (dp0 2 | S'mtech' 3 | p1 4 | S'mCa' 5 | p2 6 | sS'McA' 7 | p3 8 | S'MCA' 9 | p4 10 | s. -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/basics/index.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vinayakumarr/Signal-Processing-and-Pattern-Classification/38d4fa08d4d9d4cd01b15ad4ba0bce55100711cc/Signal Processing and Pattern Classification/basics/index.jpeg -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/basics/pandastutorial.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "%matplotlib inline\n", 10 | "import numpy as np\n", 11 | "import pandas as pd\n", 12 | "import matplotlib.pyplot as plt\n", 13 | "\n", 14 | "pd.options.display.max_rows = 8" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 2, 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "df = pd.read_csv(\"support/titanic.csv\")" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 3, 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "data": { 33 | "text/plain": [ 34 | "pandas.core.frame.DataFrame" 35 | ] 36 | }, 37 | "execution_count": 3, 38 | "metadata": {}, 39 | "output_type": "execute_result" 40 | } 41 | ], 42 | "source": [ 43 | "df\n", 44 | "type(df)" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 4, 50 | "metadata": {}, 51 | "outputs": [ 52 | { 53 | "data": { 54 | "text/html": [ 55 | "
\n", 56 | "\n", 69 | "\n", 70 | " \n", 71 | " \n", 72 | " \n", 73 | " \n", 74 | " \n", 75 | " \n", 76 | " \n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | "
PassengerIdSurvivedPclassNameSexAgeSibSpParchTicketFareCabinEmbarked
0103Braund, Mr. Owen Harrismale22.010A/5 211717.2500NaNS
1211Cumings, Mrs. John Bradley (Florence Briggs Th...female38.010PC 1759971.2833C85C
2313Heikkinen, Miss. Lainafemale26.000STON/O2. 31012827.9250NaNS
3411Futrelle, Mrs. Jacques Heath (Lily May Peel)female35.01011380353.1000C123S
4503Allen, Mr. William Henrymale35.0003734508.0500NaNS
\n", 165 | "
" 166 | ], 167 | "text/plain": [ 168 | " PassengerId Survived Pclass \\\n", 169 | "0 1 0 3 \n", 170 | "1 2 1 1 \n", 171 | "2 3 1 3 \n", 172 | "3 4 1 1 \n", 173 | "4 5 0 3 \n", 174 | "\n", 175 | " Name Sex Age SibSp \\\n", 176 | "0 Braund, Mr. Owen Harris male 22.0 1 \n", 177 | "1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 \n", 178 | "2 Heikkinen, Miss. Laina female 26.0 0 \n", 179 | "3 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 \n", 180 | "4 Allen, Mr. William Henry male 35.0 0 \n", 181 | "\n", 182 | " Parch Ticket Fare Cabin Embarked \n", 183 | "0 0 A/5 21171 7.2500 NaN S \n", 184 | "1 0 PC 17599 71.2833 C85 C \n", 185 | "2 0 STON/O2. 3101282 7.9250 NaN S \n", 186 | "3 0 113803 53.1000 C123 S \n", 187 | "4 0 373450 8.0500 NaN S " 188 | ] 189 | }, 190 | "execution_count": 4, 191 | "metadata": {}, 192 | "output_type": "execute_result" 193 | } 194 | ], 195 | "source": [ 196 | "df.head()" 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": 5, 202 | "metadata": {}, 203 | "outputs": [ 204 | { 205 | "data": { 206 | "text/plain": [ 207 | "" 208 | ] 209 | }, 210 | "execution_count": 5, 211 | "metadata": {}, 212 | "output_type": "execute_result" 213 | }, 214 | { 215 | "data": { 216 | "image/png": "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\n", 217 | "text/plain": [ 218 | "" 219 | ] 220 | }, 221 | "metadata": {}, 222 | "output_type": "display_data" 223 | } 224 | ], 225 | "source": [ 226 | "#What is the age distribution of the passengers?\n", 227 | "\n", 228 | "df['Age'].hist()" 229 | ] 230 | }, 231 | { 232 | "cell_type": "code", 233 | "execution_count": 6, 234 | "metadata": {}, 235 | "outputs": [ 236 | { 237 | "data": { 238 | "text/plain": [ 239 | "RangeIndex(start=0, stop=891, step=1)" 240 | ] 241 | }, 242 | "execution_count": 6, 243 | "metadata": {}, 244 | "output_type": "execute_result" 245 | } 246 | ], 247 | "source": [ 248 | "#Attributes of the DataFrame\n", 249 | "df.index" 250 | ] 251 | }, 252 | { 253 | "cell_type": "code", 254 | "execution_count": 7, 255 | "metadata": {}, 256 | "outputs": [ 257 | { 258 | "data": { 259 | "text/plain": [ 260 | "Index([u'PassengerId', u'Survived', u'Pclass', u'Name', u'Sex', u'Age',\n", 261 | " u'SibSp', u'Parch', u'Ticket', u'Fare', u'Cabin', u'Embarked'],\n", 262 | " dtype='object')" 263 | ] 264 | }, 265 | "execution_count": 7, 266 | "metadata": {}, 267 | "output_type": "execute_result" 268 | } 269 | ], 270 | "source": [ 271 | "df.columns" 272 | ] 273 | }, 274 | { 275 | "cell_type": "code", 276 | "execution_count": 8, 277 | "metadata": {}, 278 | "outputs": [ 279 | { 280 | "data": { 281 | "text/plain": [ 282 | "PassengerId int64\n", 283 | "Survived int64\n", 284 | "Pclass int64\n", 285 | "Name object\n", 286 | " ... \n", 287 | "Ticket object\n", 288 | "Fare float64\n", 289 | "Cabin object\n", 290 | "Embarked object\n", 291 | "Length: 12, dtype: object" 292 | ] 293 | }, 294 | "execution_count": 8, 295 | "metadata": {}, 296 | "output_type": "execute_result" 297 | } 298 | ], 299 | "source": [ 300 | "df.dtypes" 301 | ] 302 | }, 303 | { 304 | "cell_type": "code", 305 | "execution_count": 9, 306 | "metadata": {}, 307 | "outputs": [ 308 | { 309 | "name": "stdout", 310 | "output_type": "stream", 311 | "text": [ 312 | "\n", 313 | "RangeIndex: 891 entries, 0 to 890\n", 314 | "Data columns (total 12 columns):\n", 315 | "PassengerId 891 non-null int64\n", 316 | "Survived 891 non-null int64\n", 317 | "Pclass 891 non-null int64\n", 318 | "Name 891 non-null object\n", 319 | "Sex 891 non-null object\n", 320 | "Age 714 non-null float64\n", 321 | "SibSp 891 non-null int64\n", 322 | "Parch 891 non-null int64\n", 323 | "Ticket 891 non-null object\n", 324 | "Fare 891 non-null float64\n", 325 | "Cabin 204 non-null object\n", 326 | "Embarked 889 non-null object\n", 327 | "dtypes: float64(2), int64(5), object(5)\n", 328 | "memory usage: 83.6+ KB\n" 329 | ] 330 | } 331 | ], 332 | "source": [ 333 | "df.info()" 334 | ] 335 | }, 336 | { 337 | "cell_type": "code", 338 | "execution_count": 10, 339 | "metadata": {}, 340 | "outputs": [ 341 | { 342 | "data": { 343 | "text/plain": [ 344 | "array([[1, 0, 3, ..., 7.25, nan, 'S'],\n", 345 | " [2, 1, 1, ..., 71.2833, 'C85', 'C'],\n", 346 | " [3, 1, 3, ..., 7.925, nan, 'S'],\n", 347 | " ..., \n", 348 | " [889, 0, 3, ..., 23.45, nan, 'S'],\n", 349 | " [890, 1, 1, ..., 30.0, 'C148', 'C'],\n", 350 | " [891, 0, 3, ..., 7.75, nan, 'Q']], dtype=object)" 351 | ] 352 | }, 353 | "execution_count": 10, 354 | "metadata": {}, 355 | "output_type": "execute_result" 356 | } 357 | ], 358 | "source": [ 359 | "df.values" 360 | ] 361 | }, 362 | { 363 | "cell_type": "code", 364 | "execution_count": 14, 365 | "metadata": {}, 366 | "outputs": [], 367 | "source": [ 368 | "df = pd.read_csv(\"support/titanic.csv\", header=None)" 369 | ] 370 | }, 371 | { 372 | "cell_type": "code", 373 | "execution_count": 15, 374 | "metadata": {}, 375 | "outputs": [ 376 | { 377 | "data": { 378 | "text/html": [ 379 | "
\n", 380 | "\n", 393 | "\n", 394 | " \n", 395 | " \n", 396 | " \n", 397 | " \n", 398 | " \n", 399 | " \n", 400 | " \n", 401 | " \n", 402 | " \n", 403 | " \n", 404 | " \n", 405 | " \n", 406 | " \n", 407 | " \n", 408 | " \n", 409 | " \n", 410 | " \n", 411 | " \n", 412 | " \n", 413 | " \n", 414 | " \n", 415 | " \n", 416 | " \n", 417 | " \n", 418 | " \n", 419 | " \n", 420 | " \n", 421 | " \n", 422 | " \n", 423 | " \n", 424 | " \n", 425 | " \n", 426 | " \n", 427 | " \n", 428 | " \n", 429 | " \n", 430 | " \n", 431 | " \n", 432 | " \n", 433 | " \n", 434 | " \n", 435 | " \n", 436 | " \n", 437 | " \n", 438 | " \n", 439 | " \n", 440 | " \n", 441 | " \n", 442 | " \n", 443 | " \n", 444 | " \n", 445 | " \n", 446 | " \n", 447 | " \n", 448 | " \n", 449 | " \n", 450 | " \n", 451 | " \n", 452 | " \n", 453 | " \n", 454 | " \n", 455 | " \n", 456 | " \n", 457 | " \n", 458 | " \n", 459 | " \n", 460 | " \n", 461 | " \n", 462 | " \n", 463 | " \n", 464 | " \n", 465 | " \n", 466 | " \n", 467 | " \n", 468 | " \n", 469 | " \n", 470 | " \n", 471 | " \n", 472 | " \n", 473 | " \n", 474 | " \n", 475 | " \n", 476 | " \n", 477 | " \n", 478 | " \n", 479 | " \n", 480 | " \n", 481 | " \n", 482 | " \n", 483 | " \n", 484 | " \n", 485 | " \n", 486 | " \n", 487 | " \n", 488 | " \n", 489 | " \n", 490 | " \n", 491 | " \n", 492 | " \n", 493 | " \n", 494 | " \n", 495 | " \n", 496 | " \n", 497 | " \n", 498 | " \n", 499 | " \n", 500 | " \n", 501 | " \n", 502 | " \n", 503 | " \n", 504 | " \n", 505 | " \n", 506 | " \n", 507 | " \n", 508 | " \n", 509 | " \n", 510 | " \n", 511 | " \n", 512 | " \n", 513 | " \n", 514 | " \n", 515 | " \n", 516 | " \n", 517 | " \n", 518 | " \n", 519 | " \n", 520 | " \n", 521 | " \n", 522 | " \n", 523 | " \n", 524 | " \n", 525 | " \n", 526 | " \n", 527 | " \n", 528 | " \n", 529 | " \n", 530 | " \n", 531 | " \n", 532 | " \n", 533 | " \n", 534 | " \n", 535 | " \n", 536 | " \n", 537 | " \n", 538 | " \n", 539 | " \n", 540 | " \n", 541 | " \n", 542 | " \n", 543 | " \n", 544 | " \n", 545 | " \n", 546 | " \n", 547 | " \n", 548 | "
01234567891011
0PassengerIdSurvivedPclassNameSexAgeSibSpParchTicketFareCabinEmbarked
1103Braund, Mr. Owen Harrismale2210A/5 211717.25NaNS
2211Cumings, Mrs. John Bradley (Florence Briggs Th...female3810PC 1759971.2833C85C
3313Heikkinen, Miss. Lainafemale2600STON/O2. 31012827.925NaNS
.......................................
88888811Graham, Miss. Margaret Edithfemale190011205330B42S
88988903Johnston, Miss. Catherine Helen \"Carrie\"femaleNaN12W./C. 660723.45NaNS
89089011Behr, Mr. Karl Howellmale260011136930C148C
89189103Dooley, Mr. Patrickmale32003703767.75NaNQ
\n", 549 | "

892 rows × 12 columns

\n", 550 | "
" 551 | ], 552 | "text/plain": [ 553 | " 0 1 2 \\\n", 554 | "0 PassengerId Survived Pclass \n", 555 | "1 1 0 3 \n", 556 | "2 2 1 1 \n", 557 | "3 3 1 3 \n", 558 | ".. ... ... ... \n", 559 | "888 888 1 1 \n", 560 | "889 889 0 3 \n", 561 | "890 890 1 1 \n", 562 | "891 891 0 3 \n", 563 | "\n", 564 | " 3 4 5 6 \\\n", 565 | "0 Name Sex Age SibSp \n", 566 | "1 Braund, Mr. Owen Harris male 22 1 \n", 567 | "2 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38 1 \n", 568 | "3 Heikkinen, Miss. Laina female 26 0 \n", 569 | ".. ... ... ... ... \n", 570 | "888 Graham, Miss. Margaret Edith female 19 0 \n", 571 | "889 Johnston, Miss. Catherine Helen \"Carrie\" female NaN 1 \n", 572 | "890 Behr, Mr. Karl Howell male 26 0 \n", 573 | "891 Dooley, Mr. Patrick male 32 0 \n", 574 | "\n", 575 | " 7 8 9 10 11 \n", 576 | "0 Parch Ticket Fare Cabin Embarked \n", 577 | "1 0 A/5 21171 7.25 NaN S \n", 578 | "2 0 PC 17599 71.2833 C85 C \n", 579 | "3 0 STON/O2. 3101282 7.925 NaN S \n", 580 | ".. ... ... ... ... ... \n", 581 | "888 0 112053 30 B42 S \n", 582 | "889 2 W./C. 6607 23.45 NaN S \n", 583 | "890 0 111369 30 C148 C \n", 584 | "891 0 370376 7.75 NaN Q \n", 585 | "\n", 586 | "[892 rows x 12 columns]" 587 | ] 588 | }, 589 | "execution_count": 15, 590 | "metadata": {}, 591 | "output_type": "execute_result" 592 | } 593 | ], 594 | "source": [ 595 | "df" 596 | ] 597 | }, 598 | { 599 | "cell_type": "code", 600 | "execution_count": 16, 601 | "metadata": {}, 602 | "outputs": [], 603 | "source": [ 604 | "xtrain = df.iloc[:,1:11]\n", 605 | "ytrain = df.iloc[:,0]" 606 | ] 607 | }, 608 | { 609 | "cell_type": "code", 610 | "execution_count": 17, 611 | "metadata": {}, 612 | "outputs": [ 613 | { 614 | "data": { 615 | "text/plain": [ 616 | "(892, 10)" 617 | ] 618 | }, 619 | "execution_count": 17, 620 | "metadata": {}, 621 | "output_type": "execute_result" 622 | } 623 | ], 624 | "source": [ 625 | "xtrain.shape" 626 | ] 627 | }, 628 | { 629 | "cell_type": "code", 630 | "execution_count": 18, 631 | "metadata": {}, 632 | "outputs": [ 633 | { 634 | "data": { 635 | "text/plain": [ 636 | "(892,)" 637 | ] 638 | }, 639 | "execution_count": 18, 640 | "metadata": {}, 641 | "output_type": "execute_result" 642 | } 643 | ], 644 | "source": [ 645 | "ytrain.shape" 646 | ] 647 | }, 648 | { 649 | "cell_type": "code", 650 | "execution_count": 19, 651 | "metadata": {}, 652 | "outputs": [ 653 | { 654 | "data": { 655 | "text/plain": [ 656 | "0 PassengerId\n", 657 | "1 1\n", 658 | "2 2\n", 659 | "3 3\n", 660 | " ... \n", 661 | "888 888\n", 662 | "889 889\n", 663 | "890 890\n", 664 | "891 891\n", 665 | "Name: 0, Length: 892, dtype: object" 666 | ] 667 | }, 668 | "execution_count": 19, 669 | "metadata": {}, 670 | "output_type": "execute_result" 671 | } 672 | ], 673 | "source": [ 674 | "ytrain" 675 | ] 676 | }, 677 | { 678 | "cell_type": "code", 679 | "execution_count": null, 680 | "metadata": {}, 681 | "outputs": [], 682 | "source": [] 683 | } 684 | ], 685 | "metadata": { 686 | "kernelspec": { 687 | "display_name": "Python 2", 688 | "language": "python", 689 | "name": "python2" 690 | }, 691 | "language_info": { 692 | "codemirror_mode": { 693 | "name": "ipython", 694 | "version": 2 695 | }, 696 | "file_extension": ".py", 697 | "mimetype": "text/x-python", 698 | "name": "python", 699 | "nbconvert_exporter": "python", 700 | "pygments_lexer": "ipython2", 701 | "version": "2.7.12" 702 | } 703 | }, 704 | "nbformat": 4, 705 | "nbformat_minor": 2 706 | } 707 | -------------------------------------------------------------------------------- /Signal Processing and Pattern Classification/basics/pickleandh5py.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 29, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import pickle" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 30, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | "Courses = { \"McA\": \"MCA\", \"mtech\": \"mCa\" }" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 31, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "pickle.dump( Courses, open( \"data/save.p\", \"wb\" ) )" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 32, 33 | "metadata": {}, 34 | "outputs": [ 35 | { 36 | "name": "stdout", 37 | "output_type": "stream", 38 | "text": [ 39 | "{'mtech': 'mCa', 'McA': 'MCA'}\n" 40 | ] 41 | } 42 | ], 43 | "source": [ 44 | "import pickle\n", 45 | "Courses = pickle.load( open( \"data/save.p\", \"rb\" ) )\n", 46 | "print(Courses)" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 33, 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "#In Python 2, you can speed up your pickle access with cPickle\n", 56 | "import cPickle as pickle" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 34, 62 | "metadata": {}, 63 | "outputs": [], 64 | "source": [ 65 | "import numpy as np\n", 66 | "import h5py\n", 67 | "a = np.random.random(size=(100,20))\n", 68 | "h5f = h5py.File('data/places.h5', 'w')\n", 69 | "h5f.create_dataset('Coimatore', data=a)\n", 70 | "h5f.close()" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 35, 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "hf = h5py.File('data/places.h5', 'r')" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 36, 85 | "metadata": {}, 86 | "outputs": [ 87 | { 88 | "data": { 89 | "text/plain": [ 90 | "[u'Coimatore']" 91 | ] 92 | }, 93 | "execution_count": 36, 94 | "metadata": {}, 95 | "output_type": "execute_result" 96 | } 97 | ], 98 | "source": [ 99 | "hf.keys()" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 37, 105 | "metadata": {}, 106 | "outputs": [], 107 | "source": [ 108 | "n1 = hf.get('Coimatore')" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": null, 114 | "metadata": {}, 115 | "outputs": [], 116 | "source": [] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": 38, 121 | "metadata": {}, 122 | "outputs": [ 123 | { 124 | "name": "stdout", 125 | "output_type": "stream", 126 | "text": [ 127 | "[[ 0.33412934 0.0354671 0.03424124 ..., 0.82633875 0.48229887\n", 128 | " 0.98241557]\n", 129 | " [ 0.11882759 0.01912331 0.86190162 ..., 0.46347191 0.08417392\n", 130 | " 0.74313231]\n", 131 | " [ 0.61045655 0.66399382 0.36930377 ..., 0.81665796 0.27434181\n", 132 | " 0.78094389]\n", 133 | " ..., \n", 134 | " [ 0.04744102 0.92129318 0.53562008 ..., 0.21281105 0.47548767\n", 135 | " 0.94044184]\n", 136 | " [ 0.49178111 0.9164625 0.8547971 ..., 0.09878714 0.94332963\n", 137 | " 0.46193126]\n", 138 | " [ 0.36357596 0.43156031 0.05778233 ..., 0.55206482 0.52448766\n", 139 | " 0.50722936]]\n" 140 | ] 141 | } 142 | ], 143 | "source": [ 144 | "print(a)" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 39, 150 | "metadata": {}, 151 | "outputs": [ 152 | { 153 | "name": "stdout", 154 | "output_type": "stream", 155 | "text": [ 156 | "Keys: [u'Coimatore']\n" 157 | ] 158 | } 159 | ], 160 | "source": [ 161 | "# List all groups\n", 162 | "print(\"Keys: %s\" % hf.keys())\n", 163 | "a_group_key = list(hf.keys())[0]\n", 164 | "\n", 165 | "# Get the data\n", 166 | "data = list(hf[a_group_key])" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": 40, 172 | "metadata": {}, 173 | "outputs": [ 174 | { 175 | "name": "stdout", 176 | "output_type": "stream", 177 | "text": [ 178 | "Coimatore\n" 179 | ] 180 | } 181 | ], 182 | "source": [ 183 | "print(a_group_key)" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 41, 189 | "metadata": {}, 190 | "outputs": [ 191 | { 192 | "name": "stdout", 193 | "output_type": "stream", 194 | "text": [ 195 | "[array([ 0.33412934, 0.0354671 , 0.03424124, 0.89937763, 0.09572119,\n", 196 | " 0.82996797, 0.07969331, 0.92355212, 0.44463925, 0.400989 ,\n", 197 | " 0.06538742, 0.29574138, 0.29177662, 0.75951842, 0.84803715,\n", 198 | " 0.63214215, 0.91844603, 0.82633875, 0.48229887, 0.98241557]), array([ 0.11882759, 0.01912331, 0.86190162, 0.20284504, 0.4912432 ,\n", 199 | " 0.32814231, 0.88265262, 0.43564324, 0.01234813, 0.04796363,\n", 200 | " 0.57409627, 0.90118027, 0.71926124, 0.43430019, 0.25483602,\n", 201 | " 0.17677151, 0.04328219, 0.46347191, 0.08417392, 0.74313231]), array([ 0.61045655, 0.66399382, 0.36930377, 0.33835312, 0.18730692,\n", 202 | " 0.44042376, 0.87502288, 0.53053159, 0.1430692 , 0.41255183,\n", 203 | " 0.09101736, 0.58020815, 0.902813 , 0.09091128, 0.53084077,\n", 204 | " 0.73222609, 0.30134066, 0.81665796, 0.27434181, 0.78094389]), array([ 0.50487673, 0.23710423, 0.80385224, 0.51063001, 0.86233119,\n", 205 | " 0.10900983, 0.49127642, 0.25016005, 0.07797914, 0.66870407,\n", 206 | " 0.78221828, 0.51007802, 0.99832106, 0.62288118, 0.1683249 ,\n", 207 | " 0.7525314 , 0.69460146, 0.59128161, 0.59061495, 0.32699768]), array([ 0.0857672 , 0.96575849, 0.36911509, 0.19924829, 0.75557197,\n", 208 | " 0.45073704, 0.56881812, 0.97304101, 0.51668881, 0.76404514,\n", 209 | " 0.43201382, 0.81672609, 0.66265716, 0.21983509, 0.89277784,\n", 210 | " 0.74637666, 0.15003896, 0.99884255, 0.00827794, 0.03044679]), array([ 0.26745057, 0.27679865, 0.14351287, 0.32459745, 0.3815334 ,\n", 211 | " 0.34027801, 0.97735589, 0.87398677, 0.71990233, 0.72154494,\n", 212 | " 0.22681545, 0.85376315, 0.0952333 , 0.36493838, 0.91969656,\n", 213 | " 0.18371707, 0.71605876, 0.38007362, 0.58841258, 0.575532 ]), array([ 0.69631899, 0.83582973, 0.41229829, 0.3231506 , 0.47875469,\n", 214 | " 0.07058501, 0.94281592, 0.68891917, 0.57913733, 0.56051118,\n", 215 | " 0.27128302, 0.19538283, 0.23457199, 0.41665562, 0.09955617,\n", 216 | " 0.946618 , 0.90682081, 0.16004832, 0.7391994 , 0.85304799]), array([ 0.84597589, 0.52002348, 0.31580561, 0.93301382, 0.26223347,\n", 217 | " 0.899356 , 0.35184717, 0.88499342, 0.17864543, 0.19714562,\n", 218 | " 0.77576539, 0.13689711, 0.67981864, 0.64918301, 0.02873039,\n", 219 | " 0.99628379, 0.73751166, 0.48216184, 0.99378892, 0.45763074]), array([ 0.85143934, 0.40596622, 0.15118186, 0.53644064, 0.18063643,\n", 220 | " 0.64784601, 0.26118838, 0.56686633, 0.45326998, 0.8824986 ,\n", 221 | " 0.65957871, 0.11519755, 0.41735304, 0.28101692, 0.99529812,\n", 222 | " 0.57438577, 0.53812913, 0.11442615, 0.32585277, 0.67361072]), array([ 0.06403026, 0.29385007, 0.71330925, 0.82115613, 0.63045343,\n", 223 | " 0.35217981, 0.9282999 , 0.96407849, 0.50960003, 0.92367278,\n", 224 | " 0.09141858, 0.19946895, 0.18653208, 0.47699248, 0.44793969,\n", 225 | " 0.41920977, 0.94602225, 0.76707758, 0.63592095, 0.52433823]), array([ 0.99021263, 0.67416982, 0.36582163, 0.40447755, 0.71048561,\n", 226 | " 0.26527264, 0.38699395, 0.32569994, 0.83787144, 0.75126581,\n", 227 | " 0.76976135, 0.64330301, 0.56560268, 0.38328627, 0.77540495,\n", 228 | " 0.1877362 , 0.83244607, 0.620707 , 0.66914652, 0.93654371]), array([ 0.24056687, 0.93790808, 0.93127351, 0.83923957, 0.31662022,\n", 229 | " 0.36986059, 0.48378872, 0.03189749, 0.81329056, 0.87937346,\n", 230 | " 0.82682666, 0.45203374, 0.60675798, 0.94199171, 0.69185527,\n", 231 | " 0.45736954, 0.58776103, 0.84766452, 0.09152362, 0.45126258]), array([ 0.64116517, 0.39607506, 0.11751262, 0.30645659, 0.0465223 ,\n", 232 | " 0.73106586, 0.54079853, 0.35095884, 0.00798507, 0.98648263,\n", 233 | " 0.9919218 , 0.27940194, 0.29826322, 0.70818423, 0.24822831,\n", 234 | " 0.74151597, 0.98323345, 0.27466345, 0.65418044, 0.79778 ]), array([ 0.30942603, 0.81645492, 0.89868167, 0.82710636, 0.84970895,\n", 235 | " 0.48271063, 0.54170049, 0.65018497, 0.87998082, 0.52721075,\n", 236 | " 0.35867585, 0.80298298, 0.19936245, 0.41834875, 0.77970954,\n", 237 | " 0.58480344, 0.32349978, 0.70839923, 0.92665534, 0.02491341]), array([ 0.52302916, 0.23559812, 0.83161704, 0.76136229, 0.93354774,\n", 238 | " 0.49292465, 0.87870381, 0.74414091, 0.0353813 , 0.98104381,\n", 239 | " 0.83214727, 0.1646372 , 0.23121399, 0.1787815 , 0.54017369,\n", 240 | " 0.89499639, 0.45383134, 0.03520215, 0.46806071, 0.46176572]), array([ 0.60469089, 0.98010776, 0.56636572, 0.99696813, 0.88663649,\n", 241 | " 0.7887306 , 0.80017273, 0.47482173, 0.70846737, 0.27717555,\n", 242 | " 0.79148651, 0.93622761, 0.58819216, 0.36960473, 0.26871954,\n", 243 | " 0.59625453, 0.15712762, 0.84045248, 0.65895141, 0.11461495]), array([ 0.6344016 , 0.46075421, 0.24136032, 0.50105721, 0.16884837,\n", 244 | " 0.67747601, 0.90763003, 0.27510698, 0.42961259, 0.69030832,\n", 245 | " 0.59733014, 0.61620317, 0.28819004, 0.23937517, 0.06246736,\n", 246 | " 0.68856359, 0.24273646, 0.67381242, 0.97786256, 0.64475139]), array([ 0.32288739, 0.71635535, 0.42157163, 0.16809069, 0.52351112,\n", 247 | " 0.84805392, 0.30567489, 0.31852676, 0.08638158, 0.80075531,\n", 248 | " 0.03704927, 0.93903878, 0.23741966, 0.49721859, 0.43878683,\n", 249 | " 0.7344603 , 0.33096925, 0.11116562, 0.11627387, 0.83724531]), array([ 0.14032417, 0.17868308, 0.64052052, 0.30870295, 0.15000398,\n", 250 | " 0.48162565, 0.47651431, 0.6233291 , 0.15613158, 0.12226224,\n", 251 | " 0.84779309, 0.87320068, 0.20643878, 0.57939991, 0.58356088,\n", 252 | " 0.25148913, 0.70798547, 0.26903951, 0.01921452, 0.51431718]), array([ 0.24072057, 0.9124664 , 0.32175963, 0.45342626, 0.06252907,\n", 253 | " 0.44252187, 0.25747357, 0.56631395, 0.78308696, 0.39574901,\n", 254 | " 0.27228597, 0.09063364, 0.62503011, 0.6555527 , 0.15946473,\n", 255 | " 0.00742955, 0.57693557, 0.41526285, 0.24751148, 0.07965775]), array([ 0.05986667, 0.94456417, 0.53020912, 0.25530898, 0.37243571,\n", 256 | " 0.76413443, 0.22734412, 0.72779204, 0.95028586, 0.0556483 ,\n", 257 | " 0.60371589, 0.20813514, 0.46703442, 0.37674065, 0.4220374 ,\n", 258 | " 0.559812 , 0.7887816 , 0.34496148, 0.17300727, 0.64530011]), array([ 0.30909237, 0.14063954, 0.90167558, 0.476521 , 0.27164764,\n", 259 | " 0.27380887, 0.21983387, 0.4193566 , 0.60804715, 0.46382873,\n", 260 | " 0.18111719, 0.3155292 , 0.43285873, 0.35419367, 0.79566778,\n", 261 | " 0.4603183 , 0.27645701, 0.85537465, 0.93278375, 0.16636886]), array([ 0.74841235, 0.32058454, 0.66190478, 0.87759825, 0.85020932,\n", 262 | " 0.76594732, 0.35014417, 0.20625371, 0.11716557, 0.7627029 ,\n", 263 | " 0.10902284, 0.34763977, 0.40124525, 0.57512482, 0.52390412,\n", 264 | " 0.86301774, 0.86394999, 0.23979831, 0.82574692, 0.89788296]), array([ 0.62380559, 0.98676048, 0.50682367, 0.79181811, 0.16486089,\n", 265 | " 0.8407482 , 0.65406433, 0.08216571, 0.14441993, 0.76421063,\n", 266 | " 0.08353734, 0.78098996, 0.29558199, 0.89592771, 0.40780835,\n", 267 | " 0.32083275, 0.5186821 , 0.28201294, 0.58590379, 0.98485679]), array([ 0.63683576, 0.63718204, 0.5523145 , 0.59549285, 0.52406249,\n", 268 | " 0.37773168, 0.85896643, 0.17470264, 0.29862149, 0.83576978,\n", 269 | " 0.31530312, 0.57308014, 0.15340668, 0.26629467, 0.19166986,\n", 270 | " 0.47282193, 0.0102902 , 0.98606604, 0.98516897, 0.79429564]), array([ 0.53022109, 0.31246405, 0.91491002, 0.74907602, 0.29830645,\n", 271 | " 0.82349957, 0.4019071 , 0.73624777, 0.66141129, 0.81252736,\n", 272 | " 0.84316869, 0.62026427, 0.94449406, 0.38070835, 0.86315806,\n", 273 | " 0.62423956, 0.25809996, 0.43289112, 0.97311512, 0.98968372]), array([ 0.98810377, 0.04204589, 0.62043388, 0.47017524, 0.15244209,\n", 274 | " 0.91438577, 0.67405963, 0.58477957, 0.1962386 , 0.08794552,\n", 275 | " 0.5849903 , 0.14887548, 0.43692356, 0.9756212 , 0.56922875,\n", 276 | " 0.90948438, 0.47196821, 0.45122682, 0.08355763, 0.43871308]), array([ 0.83944768, 0.24550418, 0.13696499, 0.35957518, 0.59531826,\n", 277 | " 0.96460672, 0.48988026, 0.19366975, 0.42162475, 0.53867651,\n", 278 | " 0.69757373, 0.08568841, 0.33672409, 0.49549479, 0.53970582,\n", 279 | " 0.95363024, 0.13299145, 0.5649233 , 0.32065587, 0.12032257]), array([ 0.75486384, 0.68806318, 0.09277016, 0.55683453, 0.57020463,\n", 280 | " 0.17532731, 0.74465386, 0.61000688, 0.38199701, 0.33482437,\n", 281 | " 0.20347752, 0.07050644, 0.59606076, 0.02196206, 0.34171948,\n", 282 | " 0.98687919, 0.19908367, 0.60745985, 0.37830667, 0.58182355]), array([ 0.84022576, 0.29612904, 0.22623013, 0.15551285, 0.58910069,\n", 283 | " 0.79560364, 0.8302482 , 0.82950028, 0.00895665, 0.9823958 ,\n", 284 | " 0.5673566 , 0.58334644, 0.5139233 , 0.14794048, 0.18270755,\n", 285 | " 0.50663649, 0.08610121, 0.54224214, 0.16134055, 0.3997191 ]), array([ 0.34133473, 0.89894577, 0.38285376, 0.16131768, 0.76062727,\n", 286 | " 0.0386614 , 0.46126647, 0.59643901, 0.8297964 , 0.24698993,\n", 287 | " 0.83576639, 0.15564816, 0.12938228, 0.24450368, 0.35498112,\n", 288 | " 0.22878946, 0.03087461, 0.30868336, 0.28121572, 0.89984292]), array([ 0.89989619, 0.13388233, 0.17973658, 0.17308922, 0.27294878,\n", 289 | " 0.5913442 , 0.96041393, 0.42855834, 0.92804866, 0.03336084,\n", 290 | " 0.2250601 , 0.39287952, 0.73571875, 0.24991041, 0.96452991,\n", 291 | " 0.39668205, 0.51029506, 0.01743345, 0.53332032, 0.03570342]), array([ 0.1274326 , 0.24700717, 0.89990458, 0.50431182, 0.46321732,\n", 292 | " 0.92601352, 0.97053552, 0.69790452, 0.75458709, 0.34296004,\n", 293 | " 0.5242831 , 0.73964708, 0.48508197, 0.80681773, 0.65941829,\n", 294 | " 0.33028755, 0.70568498, 0.01726334, 0.31431107, 0.89488237]), array([ 0.54141618, 0.41579921, 0.2676019 , 0.75898964, 0.20241118,\n", 295 | " 0.04407448, 0.10719543, 0.2577562 , 0.60251305, 0.57605531,\n", 296 | " 0.40430957, 0.27403129, 0.84036909, 0.89347607, 0.70870986,\n", 297 | " 0.52521221, 0.85055223, 0.64234222, 0.62032456, 0.11828591]), array([ 0.33667117, 0.58288228, 0.59640126, 0.03776345, 0.90906783,\n", 298 | " 0.39262908, 0.65966921, 0.00795613, 0.62515374, 0.52102574,\n", 299 | " 0.06253338, 0.31711649, 0.38138159, 0.75778235, 0.12345666,\n", 300 | " 0.77209312, 0.57138083, 0.12123362, 0.5589344 , 0.30844924]), array([ 0.99187914, 0.07908026, 0.07885096, 0.6625358 , 0.67587317,\n", 301 | " 0.6739968 , 0.31326438, 0.10932175, 0.13688299, 0.73407959,\n", 302 | " 0.44378822, 0.15813756, 0.54161013, 0.36889806, 0.42567267,\n", 303 | " 0.72335321, 0.74948669, 0.2657276 , 0.58614797, 0.94966326]), array([ 0.10618584, 0.88799781, 0.38845999, 0.2352639 , 0.8836405 ,\n", 304 | " 0.91371653, 0.34762781, 0.79176451, 0.73817832, 0.1557509 ,\n", 305 | " 0.7668616 , 0.30031492, 0.98323198, 0.70881643, 0.90399744,\n", 306 | " 0.35790547, 0.45463699, 0.55408696, 0.48286924, 0.13909318]), array([ 0.31034055, 0.90497891, 0.94173428, 0.76968855, 0.40356134,\n", 307 | " 0.06075579, 0.32297101, 0.38720413, 0.03140948, 0.8367162 ,\n", 308 | " 0.36400473, 0.26732076, 0.25741501, 0.31429926, 0.62895857,\n", 309 | " 0.05605805, 0.70483844, 0.98516588, 0.74886183, 0.47143434]), array([ 0.9518505 , 0.16440741, 0.00391919, 0.58657325, 0.23468962,\n", 310 | " 0.4023548 , 0.36574139, 0.51290412, 0.36984301, 0.78636511,\n", 311 | " 0.04003828, 0.44984625, 0.30599398, 0.91956866, 0.38254428,\n", 312 | " 0.21148203, 0.5914734 , 0.91027548, 0.79759633, 0.3714822 ]), array([ 0.36780319, 0.25458014, 0.52124477, 0.61664471, 0.27405869,\n", 313 | " 0.58614037, 0.28341625, 0.8282134 , 0.427278 , 0.67735608,\n", 314 | " 0.23008854, 0.46688838, 0.41645149, 0.72584476, 0.54272269,\n", 315 | " 0.25868071, 0.07957283, 0.68847783, 0.83205645, 0.10633364]), array([ 0.10861256, 0.02435134, 0.9716361 , 0.38849594, 0.42892028,\n", 316 | " 0.08655371, 0.82547319, 0.47098392, 0.09623399, 0.27450393,\n", 317 | " 0.37370761, 0.29722561, 0.22346726, 0.56615039, 0.81363622,\n", 318 | " 0.04551807, 0.92396671, 0.50846567, 0.86853784, 0.24781385]), array([ 0.91514774, 0.20180222, 0.27923668, 0.03129198, 0.43788693,\n", 319 | " 0.59169314, 0.78698595, 0.12110785, 0.71829599, 0.62402729,\n", 320 | " 0.89980133, 0.19380813, 0.55920644, 0.69756247, 0.44412484,\n", 321 | " 0.53692249, 0.55140364, 0.60125596, 0.49105558, 0.12788975]), array([ 0.13527652, 0.82443085, 0.85696446, 0.49238657, 0.52167967,\n", 322 | " 0.4376396 , 0.57260305, 0.69075809, 0.67411728, 0.96045999,\n", 323 | " 0.63080199, 0.30432188, 0.77616501, 0.05859676, 0.46866808,\n", 324 | " 0.81084502, 0.96016621, 0.22474372, 0.46442522, 0.63494331]), array([ 0.5693625 , 0.63049958, 0.0494894 , 0.29948451, 0.03754532,\n", 325 | " 0.84783795, 0.40360939, 0.20700861, 0.23212117, 0.04388262,\n", 326 | " 0.55130094, 0.41572023, 0.84280315, 0.37769504, 0.28511118,\n", 327 | " 0.40285127, 0.06679994, 0.33063884, 0.55778407, 0.27978981]), array([ 0.95409582, 0.3794723 , 0.87282664, 0.64952328, 0.21965081,\n", 328 | " 0.32050308, 0.30099715, 0.18451036, 0.87083967, 0.0619387 ,\n", 329 | " 0.18570525, 0.65011326, 0.62784622, 0.73276228, 0.97570635,\n", 330 | " 0.40824097, 0.01470227, 0.92674463, 0.9076381 , 0.85966545]), array([ 0.08128788, 0.30519034, 0.10472275, 0.39662512, 0.11457715,\n", 331 | " 0.61817837, 0.95051006, 0.7661833 , 0.01660809, 0.9241858 ,\n", 332 | " 0.50847945, 0.1159777 , 0.73260154, 0.84523965, 0.65931199,\n", 333 | " 0.21946118, 0.80960113, 0.0788516 , 0.34917159, 0.41117749]), array([ 0.59677161, 0.17637862, 0.78127273, 0.98817544, 0.05304267,\n", 334 | " 0.03250061, 0.03531446, 0.4817139 , 0.77418789, 0.13103947,\n", 335 | " 0.63217694, 0.10786043, 0.31828343, 0.84226728, 0.79547167,\n", 336 | " 0.41924895, 0.49183813, 0.48048221, 0.91786986, 0.56895857]), array([ 0.54687281, 0.56210736, 0.8998789 , 0.64835865, 0.05733207,\n", 337 | " 0.64488502, 0.56925869, 0.48037429, 0.85299482, 0.22506786,\n", 338 | " 0.96290563, 0.6499531 , 0.29474186, 0.47744102, 0.34143668,\n", 339 | " 0.56140745, 0.71101121, 0.18466635, 0.4744607 , 0.34586111]), array([ 0.1004407 , 0.95357378, 0.57656957, 0.23925285, 0.28917398,\n", 340 | " 0.45992387, 0.67577509, 0.44829275, 0.9369201 , 0.10171777,\n", 341 | " 0.818923 , 0.48911 , 0.87319334, 0.34763659, 0.52563168,\n", 342 | " 0.20074252, 0.33111958, 0.84136599, 0.24817776, 0.99634331]), array([ 0.70406151, 0.32782485, 0.53855574, 0.74496208, 0.26352161,\n", 343 | " 0.05764105, 0.96282226, 0.44513169, 0.39890952, 0.82614626,\n", 344 | " 0.07143447, 0.36104369, 0.51673493, 0.38409463, 0.01181512,\n", 345 | " 0.52640343, 0.17891913, 0.14619745, 0.46002886, 0.56212681]), array([ 0.34736268, 0.53314599, 0.7091143 , 0.723194 , 0.99112341,\n", 346 | " 0.51357493, 0.39343714, 0.90934756, 0.24425083, 0.62169941,\n", 347 | " 0.13771337, 0.30494139, 0.69042166, 0.79208299, 0.75740741,\n", 348 | " 0.74261619, 0.19780077, 0.73084446, 0.29679203, 0.02840128]), array([ 0.12526954, 0.52312761, 0.55931907, 0.87325096, 0.42053027,\n", 349 | " 0.14947466, 0.53206587, 0.6883482 , 0.53434134, 0.67650593,\n", 350 | " 0.60778339, 0.20513305, 0.72306395, 0.31567403, 0.65739616,\n", 351 | " 0.19584595, 0.75227883, 0.20263995, 0.76328636, 0.67510592]), array([ 0.60301578, 0.64047841, 0.7341763 , 0.166039 , 0.78194356,\n", 352 | " 0.72820536, 0.61636074, 0.87308326, 0.03933361, 0.49308863,\n", 353 | " 0.24799302, 0.87529016, 0.53412941, 0.38182731, 0.26782664,\n", 354 | " 0.09981762, 0.09116605, 0.02287496, 0.69845709, 0.72318416]), array([ 0.40733671, 0.37758726, 0.76149077, 0.8518317 , 0.30280646,\n", 355 | " 0.9888462 , 0.98813683, 0.81906925, 0.17375291, 0.47169407,\n", 356 | " 0.93679709, 0.23434971, 0.80565351, 0.71716645, 0.40227144,\n", 357 | " 0.7523571 , 0.81236901, 0.1561457 , 0.9224099 , 0.57361255]), array([ 0.60783774, 0.23488054, 0.28192607, 0.38934323, 0.4910052 ,\n", 358 | " 0.49440535, 0.43149034, 0.09736366, 0.95324222, 0.95808069,\n", 359 | " 0.29206806, 0.38121706, 0.60080956, 0.82599512, 0.63278631,\n", 360 | " 0.39060005, 0.54556251, 0.57434643, 0.07606473, 0.24200442]), array([ 0.91601877, 0.42362163, 0.83097515, 0.93501706, 0.85895935,\n", 361 | " 0.15785662, 0.0467774 , 0.75334527, 0.8415935 , 0.44734859,\n", 362 | " 0.46378849, 0.12615284, 0.92275412, 0.5504828 , 0.13090902,\n", 363 | " 0.4058156 , 0.56094275, 0.6968157 , 0.9298614 , 0.80585959]), array([ 0.14632899, 0.26083437, 0.11098231, 0.61989362, 0.74931036,\n", 364 | " 0.51158542, 0.17336969, 0.18685508, 0.76301162, 0.89899824,\n", 365 | " 0.1526582 , 0.77957278, 0.6667217 , 0.12421759, 0.45470886,\n", 366 | " 0.2877372 , 0.98252437, 0.25634996, 0.50888935, 0.01059479]), array([ 0.92554981, 0.15201656, 0.27399815, 0.87048494, 0.73175519,\n", 367 | " 0.65607492, 0.6063959 , 0.31859466, 0.90906239, 0.51276729,\n", 368 | " 0.19338953, 0.06387829, 0.11311087, 0.89924643, 0.36681741,\n", 369 | " 0.1770718 , 0.14693477, 0.37416947, 0.46325388, 0.4655378 ]), array([ 0.98434445, 0.58826995, 0.08300465, 0.74027866, 0.49442563,\n", 370 | " 0.3596022 , 0.52021532, 0.52019074, 0.25024258, 0.86076108,\n", 371 | " 0.95520164, 0.58756422, 0.55975876, 0.5326024 , 0.93968306,\n", 372 | " 0.83908351, 0.37641404, 0.03394745, 0.35948818, 0.24276501]), array([ 0.13386418, 0.82862677, 0.20335469, 0.94934023, 0.98088927,\n", 373 | " 0.57085093, 0.96805649, 0.17898277, 0.46097335, 0.32088608,\n", 374 | " 0.62056487, 0.77004041, 0.05637851, 0.8372131 , 0.42858008,\n", 375 | " 0.12236919, 0.90421426, 0.8823293 , 0.42638511, 0.51031992]), array([ 0.17515477, 0.11630786, 0.55024551, 0.05845418, 0.7250635 ,\n", 376 | " 0.95903297, 0.70688927, 0.07559399, 0.42522809, 0.80362363,\n", 377 | " 0.87600886, 0.96093321, 0.67808836, 0.19229007, 0.39300414,\n", 378 | " 0.029601 , 0.24985355, 0.30095205, 0.09622067, 0.89520712]), array([ 0.0838588 , 0.24663113, 0.89255163, 0.5643498 , 0.2055652 ,\n", 379 | " 0.33445462, 0.58018182, 0.68836579, 0.55892124, 0.67500197,\n", 380 | " 0.20259172, 0.83257272, 0.59097811, 0.74617785, 0.88142296,\n", 381 | " 0.20916649, 0.39654835, 0.67517568, 0.70699594, 0.40981039]), array([ 0.25660155, 0.05696422, 0.60166256, 0.51596523, 0.87116637,\n", 382 | " 0.41075207, 0.41516105, 0.86146365, 0.74315205, 0.70322009,\n", 383 | " 0.91969973, 0.2939375 , 0.91920575, 0.76353141, 0.66249771,\n", 384 | " 0.02999689, 0.78848596, 0.6912991 , 0.90556731, 0.70476322]), array([ 0.95111536, 0.18171495, 0.10531644, 0.98235829, 0.99578385,\n", 385 | " 0.65880904, 0.51906725, 0.777267 , 0.98181897, 0.6710959 ,\n", 386 | " 0.50848051, 0.14680088, 0.47370322, 0.06916703, 0.46197714,\n", 387 | " 0.33197568, 0.10289692, 0.92591371, 0.01120383, 0.61828264]), array([ 0.44215773, 0.13561059, 0.62054125, 0.69128893, 0.72358167,\n", 388 | " 0.2318769 , 0.86205714, 0.08855037, 0.16200349, 0.58295625,\n", 389 | " 0.57482424, 0.3841957 , 0.22949898, 0.8363251 , 0.07428537,\n", 390 | " 0.7614504 , 0.65060646, 0.74532183, 0.10380658, 0.44745682]), array([ 0.4449255 , 0.75415986, 0.36690405, 0.32770942, 0.25862932,\n", 391 | " 0.22524772, 0.34215673, 0.92631468, 0.16154046, 0.32537495,\n", 392 | " 0.69541614, 0.02239689, 0.98563404, 0.9104173 , 0.02222683,\n", 393 | " 0.03138887, 0.39224202, 0.65161408, 0.29642874, 0.64682353]), array([ 0.64299618, 0.07755223, 0.92247523, 0.47742758, 0.1377274 ,\n", 394 | " 0.91712383, 0.94377689, 0.81313625, 0.25341389, 0.84783979,\n", 395 | " 0.5093955 , 0.76711608, 0.7726 , 0.46421541, 0.57001148,\n", 396 | " 0.86248577, 0.0520057 , 0.28607484, 0.68166441, 0.87264015]), array([ 0.53439714, 0.77933957, 0.32266637, 0.22555893, 0.2852877 ,\n", 397 | " 0.63004195, 0.53040794, 0.55542755, 0.84531733, 0.6128447 ,\n", 398 | " 0.83995206, 0.55776751, 0.92817743, 0.04598494, 0.83507929,\n", 399 | " 0.79830537, 0.89675967, 0.5685873 , 0.33394706, 0.89224781]), array([ 0.30980012, 0.66310371, 0.05989506, 0.37424649, 0.7019262 ,\n", 400 | " 0.17433078, 0.21658735, 0.08733424, 0.29427608, 0.66485348,\n", 401 | " 0.78277495, 0.11912427, 0.84211513, 0.48824915, 0.53088937,\n", 402 | " 0.88156041, 0.75599673, 0.26946534, 0.4089162 , 0.5978656 ]), array([ 0.79722574, 0.91482636, 0.5798544 , 0.16550068, 0.15105351,\n", 403 | " 0.78767023, 0.73029594, 0.46679132, 0.82049794, 0.61447846,\n", 404 | " 0.51206772, 0.64315451, 0.05285086, 0.80936377, 0.34107211,\n", 405 | " 0.49996361, 0.19848759, 0.7926883 , 0.58591451, 0.73015922]), array([ 0.3608853 , 0.56301137, 0.68769288, 0.65731987, 0.62892346,\n", 406 | " 0.97025388, 0.80778058, 0.89020806, 0.31555335, 0.48433901,\n", 407 | " 0.037016 , 0.6607401 , 0.04203794, 0.7196977 , 0.09884877,\n", 408 | " 0.93555107, 0.44774486, 0.14710262, 0.30843754, 0.92598077]), array([ 0.02986718, 0.0584033 , 0.02552367, 0.18031566, 0.55305681,\n", 409 | " 0.66160949, 0.59571583, 0.92146542, 0.5066514 , 0.99292982,\n", 410 | " 0.95943718, 0.75644657, 0.51091402, 0.64642265, 0.01203567,\n", 411 | " 0.19610925, 0.50494115, 0.78979935, 0.59968826, 0.47623085]), array([ 0.04892749, 0.41234795, 0.97256717, 0.55528762, 0.74738417,\n", 412 | " 0.23356086, 0.53217642, 0.700775 , 0.68183912, 0.03065892,\n", 413 | " 0.1587659 , 0.95670352, 0.12131263, 0.45501254, 0.11219561,\n", 414 | " 0.37331135, 0.3724025 , 0.72151377, 0.49454078, 0.95326496]), array([ 0.74287265, 0.80574582, 0.96522315, 0.25633982, 0.60625834,\n", 415 | " 0.48116751, 0.84346625, 0.04454595, 0.46418359, 0.58000731,\n", 416 | " 0.87429299, 0.71251573, 0.02163219, 0.13825988, 0.1434564 ,\n", 417 | " 0.04962746, 0.07001937, 0.38708373, 0.0088998 , 0.01456273]), array([ 0.45322881, 0.3924519 , 0.32495974, 0.36423429, 0.70136238,\n", 418 | " 0.00571332, 0.27985747, 0.40873383, 0.44817603, 0.65525083,\n", 419 | " 0.07600947, 0.51575848, 0.06866654, 0.89273181, 0.07099478,\n", 420 | " 0.71796834, 0.24639328, 0.19733692, 0.90995428, 0.72725704]), array([ 0.63123577, 0.88527502, 0.92241099, 0.36629214, 0.86308105,\n", 421 | " 0.27583519, 0.7614218 , 0.2138997 , 0.29012492, 0.75881758,\n", 422 | " 0.89465885, 0.12297196, 0.66400858, 0.94484494, 0.69806149,\n", 423 | " 0.12724927, 0.71197661, 0.98204176, 0.2539738 , 0.68670156]), array([ 0.28787302, 0.78831953, 0.70669448, 0.06255468, 0.60659149,\n", 424 | " 0.33708671, 0.10314269, 0.89816658, 0.77238669, 0.25054328,\n", 425 | " 0.29576443, 0.93609181, 0.95220396, 0.29698757, 0.04652734,\n", 426 | " 0.20702779, 0.50935378, 0.57323351, 0.3660004 , 0.20273574]), array([ 0.33842267, 0.81675385, 0.17758149, 0.48326373, 0.84518396,\n", 427 | " 0.46318925, 0.73483924, 0.74238932, 0.78431201, 0.81668483,\n", 428 | " 0.07798106, 0.48568836, 0.91093864, 0.1741048 , 0.38201399,\n", 429 | " 0.51464587, 0.92648677, 0.32640189, 0.96802698, 0.53880842]), array([ 0.40960996, 0.26835039, 0.3953201 , 0.01368038, 0.72050116,\n", 430 | " 0.92751003, 0.7578881 , 0.56116606, 0.32057024, 0.33732068,\n", 431 | " 0.81490278, 0.83739556, 0.01363097, 0.37066021, 0.69411678,\n", 432 | " 0.81969448, 0.57772565, 0.12199333, 0.26259815, 0.60758426]), array([ 0.24593704, 0.27921913, 0.06300056, 0.86871085, 0.812899 ,\n", 433 | " 0.585295 , 0.62938655, 0.33001885, 0.73462678, 0.84361372,\n", 434 | " 0.34186257, 0.53310571, 0.83775882, 0.72520226, 0.49700169,\n", 435 | " 0.68907361, 0.78251187, 0.79307358, 0.8304176 , 0.00952742]), array([ 0.76127588, 0.28243312, 0.95097941, 0.34583611, 0.00128836,\n", 436 | " 0.34970225, 0.45968474, 0.03741211, 0.65243421, 0.99097388,\n", 437 | " 0.60169504, 0.88026266, 0.86720694, 0.70137147, 0.76356955,\n", 438 | " 0.46956856, 0.92169894, 0.00962736, 0.99358841, 0.54761867]), array([ 0.99229321, 0.82387134, 0.87089276, 0.2452039 , 0.32269479,\n", 439 | " 0.93684562, 0.57569783, 0.72153892, 0.1284348 , 0.16031436,\n", 440 | " 0.04148449, 0.54304869, 0.50858588, 0.67230894, 0.774457 ,\n", 441 | " 0.73163509, 0.86408068, 0.24165712, 0.74021252, 0.61861593]), array([ 0.65272755, 0.94670795, 0.7316629 , 0.71779242, 0.03936378,\n", 442 | " 0.32672857, 0.05737164, 0.60756512, 0.18619454, 0.25058653,\n", 443 | " 0.66539677, 0.13870986, 0.03341419, 0.3697598 , 0.55936952,\n", 444 | " 0.02505808, 0.24831182, 0.02935587, 0.088787 , 0.87600716]), array([ 0.52412774, 0.38562236, 0.02250788, 0.219215 , 0.61239701,\n", 445 | " 0.30891648, 0.22742758, 0.77125119, 0.51926706, 0.55166412,\n", 446 | " 0.06375863, 0.76287699, 0.87991725, 0.59673962, 0.08980308,\n", 447 | " 0.55470606, 0.15391562, 0.94136896, 0.9325248 , 0.18705613]), array([ 0.25081598, 0.23508623, 0.78716452, 0.70649669, 0.57944963,\n", 448 | " 0.4493977 , 0.11356212, 0.09077332, 0.13135474, 0.27589211,\n", 449 | " 0.65821698, 0.82012538, 0.5235901 , 0.68717666, 0.81194518,\n", 450 | " 0.56520924, 0.92870453, 0.69872161, 0.58753777, 0.21003624]), array([ 0.83963823, 0.94258092, 0.15049986, 0.12054245, 0.89163738,\n", 451 | " 0.84423259, 0.47637235, 0.47629838, 0.87656461, 0.66109375,\n", 452 | " 0.65251395, 0.09494253, 0.11082197, 0.28081579, 0.46442435,\n", 453 | " 0.11776376, 0.26021796, 0.42958856, 0.38065111, 0.24815157]), array([ 0.90845578, 0.2500957 , 0.03781355, 0.95884809, 0.06634046,\n", 454 | " 0.46539327, 0.76516133, 0.50335795, 0.65939143, 0.49958353,\n", 455 | " 0.92502852, 0.03695533, 0.26612727, 0.89983202, 0.05442055,\n", 456 | " 0.73858605, 0.99511404, 0.67970717, 0.94173846, 0.21256163]), array([ 0.18676106, 0.57289084, 0.5722503 , 0.52239052, 0.41129887,\n", 457 | " 0.75306774, 0.92597515, 0.55043572, 0.58291754, 0.47664615,\n", 458 | " 0.92588991, 0.5410636 , 0.23213879, 0.24737063, 0.03834548,\n", 459 | " 0.20951563, 0.97255448, 0.92239376, 0.6128843 , 0.38463843]), array([ 0.88030038, 0.95244583, 0.97770276, 0.82402367, 0.48903848,\n", 460 | " 0.13001283, 0.24306753, 0.17254332, 0.65490973, 0.23867219,\n", 461 | " 0.21007849, 0.57892516, 0.99563341, 0.5337199 , 0.80280174,\n", 462 | " 0.33728733, 0.30707081, 0.31392542, 0.89532923, 0.29882963]), array([ 0.05154834, 0.22185166, 0.36118215, 0.37649854, 0.69878151,\n", 463 | " 0.09886306, 0.01758609, 0.94281587, 0.94069695, 0.33631274,\n", 464 | " 0.95134681, 0.50604882, 0.22207643, 0.85163838, 0.19667131,\n", 465 | " 0.98786609, 0.26739632, 0.88155286, 0.30291196, 0.11665702]), array([ 0.72034144, 0.27232881, 0.63010412, 0.80669216, 0.79468056,\n", 466 | " 0.48659488, 0.87007169, 0.19074783, 0.11770878, 0.05329434,\n", 467 | " 0.09796184, 0.50635116, 0.08686323, 0.96375894, 0.20602594,\n", 468 | " 0.02204981, 0.19324261, 0.03105199, 0.16140803, 0.04233259]), array([ 0.65659136, 0.41802512, 0.51428835, 0.96624841, 0.72954183,\n", 469 | " 0.18136827, 0.44576377, 0.76395949, 0.98044871, 0.75011932,\n", 470 | " 0.03183983, 0.65397467, 0.51112273, 0.61578063, 0.57942751,\n", 471 | " 0.02520393, 0.1012074 , 0.50352951, 0.10360671, 0.13576465]), array([ 0.22948326, 0.06717857, 0.52041667, 0.5831391 , 0.57674167,\n", 472 | " 0.48014058, 0.68492806, 0.77606324, 0.89667176, 0.03491702,\n", 473 | " 0.69448775, 0.04557776, 0.23344173, 0.28124751, 0.27738424,\n", 474 | " 0.73138358, 0.1048948 , 0.72188135, 0.3607123 , 0.33412967]), array([ 0.57700621, 0.53145036, 0.41100363, 0.08946568, 0.87496222,\n", 475 | " 0.91973781, 0.80399384, 0.47177818, 0.03893731, 0.34694055,\n", 476 | " 0.21536997, 0.1064528 , 0.98167125, 0.86614758, 0.83051144,\n", 477 | " 0.5089576 , 0.53510959, 0.40129215, 0.47837945, 0.93718161]), array([ 0.60138391, 0.45497034, 0.39735634, 0.50873147, 0.84436839,\n", 478 | " 0.21030626, 0.13658182, 0.49224417, 0.18004633, 0.67800654,\n", 479 | " 0.25549852, 0.32786757, 0.57751338, 0.70233833, 0.14316125,\n", 480 | " 0.45108654, 0.16644742, 0.46905061, 0.87494493, 0.40431841]), array([ 0.73957144, 0.16065321, 0.84388737, 0.00179676, 0.34459938,\n", 481 | " 0.78899456, 0.3534162 , 0.11367556, 0.4755725 , 0.23703435,\n", 482 | " 0.30483299, 0.95131304, 0.65001235, 0.37442921, 0.24153658,\n", 483 | " 0.99429876, 0.25249933, 0.27827189, 0.6955832 , 0.20098395]), array([ 0.54036487, 0.23628311, 0.28049566, 0.4272553 , 0.86104605,\n", 484 | " 0.37561944, 0.27803109, 0.87454934, 0.22119382, 0.77491374,\n", 485 | " 0.13845339, 0.48067665, 0.74834608, 0.60372579, 0.98051415,\n", 486 | " 0.73070893, 0.55190135, 0.55551593, 0.65319191, 0.65466012]), array([ 0.04744102, 0.92129318, 0.53562008, 0.32921514, 0.17902552,\n", 487 | " 0.55955095, 0.88680801, 0.10175529, 0.33735267, 0.835615 ,\n", 488 | " 0.45981646, 0.42588537, 0.04230923, 0.8032063 , 0.72370125,\n", 489 | " 0.76750436, 0.53950453, 0.21281105, 0.47548767, 0.94044184]), array([ 0.49178111, 0.9164625 , 0.8547971 , 0.14459076, 0.48737857,\n", 490 | " 0.68777605, 0.38719429, 0.36446316, 0.33339397, 0.30638449,\n", 491 | " 0.228032 , 0.5328283 , 0.32680703, 0.04020758, 0.48308573,\n", 492 | " 0.84804637, 0.57403561, 0.09878714, 0.94332963, 0.46193126]), array([ 0.36357596, 0.43156031, 0.05778233, 0.65284906, 0.77120038,\n", 493 | " 0.30426191, 0.22662835, 0.93045507, 0.49022122, 0.42415752,\n", 494 | " 0.49769133, 0.92861055, 0.68527678, 0.81513594, 0.67984534,\n", 495 | " 0.65194496, 0.57358736, 0.55206482, 0.52448766, 0.50722936])]\n" 496 | ] 497 | } 498 | ], 499 | "source": [ 500 | "print(data)" 501 | ] 502 | }, 503 | { 504 | "cell_type": "code", 505 | "execution_count": null, 506 | "metadata": {}, 507 | "outputs": [], 508 | "source": [] 509 | } 510 | ], 511 | "metadata": { 512 | "kernelspec": { 513 | "display_name": "Python 2", 514 | "language": "python", 515 | "name": "python2" 516 | }, 517 | "language_info": { 518 | "codemirror_mode": { 519 | "name": "ipython", 520 | "version": 2 521 | }, 522 | "file_extension": ".py", 523 | "mimetype": "text/x-python", 524 | "name": "python", 525 | "nbconvert_exporter": "python", 526 | "pygments_lexer": "ipython2", 527 | "version": "2.7.12" 528 | } 529 | }, 530 | "nbformat": 4, 531 | "nbformat_minor": 2 532 | } 533 | --------------------------------------------------------------------------------