Code for Depression Recognition by Deep Learning


Total downloads: 255

This Python code helps to detect depression using EEG signals. A stacked LSTM-CNN deep learning model is developed and coded in python for it. The classification accuracy of 84% is achieved by this code.

This repository includes:

  • Python (jupyter notebook) code for depression detection by EEG

Disclaimer: This python code is uploaded on the by a supporter. We admire and appreciate her support and belief to share the research codes for free.


Download Test
 Discuss Code


Highlights for Depression Recognition by Deep Learning

  • An RNN (i.e. LSTM) based Deep Learning model has been  modeled for the identification of depression.
  • The computer-aided techniques based on neural networks predominately work on EEG as a biomarker for depression analysis.
  • The authors’ model is an LSTM structure that has been layered.
  • The EEG signals   are recorded at a sampling rate of 500 Hz using a total of 64 scalp electrodes.
  • The data is preprocessed for artifacts removal and windowed into a chunk of 8 secs.
  • The MDD Patients and Healthy Controls EEG dataset can be downloaded from this link:


You are reading this article on depression recognition by deep learning and will download the free code at Like the rest of the globe, India has observed an upsurge in mental health cases during the pandemic. Several suicides have been linked to the elevated anxiety and terror caused by COVID-19. SARS and other pandemics unquestionably impacted people’s mental health at some time. It is difficult to interpret electrical data manually, thus the brain’s activity is recorded in milliamperes (mA). Depressed people have a hemispheric asymmetry in their thought signals, which means that EEG may detect that unusual activity.

For the purpose of minimizing problems and accurately analyzing depression circumstances, the authors of this paper have examined the most modern machine learning algorithms. The approach uses EEG data to check for depression using a computer or artificial intelligence. Three levels of stacked LSTM networks are used to extract the features at the highest level. Advanced approaches including data mining and Deep Neural Networks, Recurrent Neural networks (RNN), and Convolution Neural Networks (CNN) have emerged in recent years (CNN).

DeepNet (Stacked Deep Learning Model)

Neural network methods, which are becoming increasingly popular, are used in the bulk of computer-aided EEG screening procedures. Even when the data is insufficient for an extended period of time, the learning process with and without feedback is critical. This difficulty can be alleviated using the LSTM approach. As seen in figure 1, the model developed by the authors is a multi-layered LSTM structure.

The complete designed model for primarily screening of depression based on EEG-free-thesis
Figure 1: The complete designed model for primary screening of depression based on EEG

Feature extraction using 1D convolution and Dropout Layer

Features may be extracted using the approach of convolution, which is commonly utilized. It’s known as a Conv 1D layer if the operation is only done in one dimension (conversion in one dimension). To generate a kernel (weighted fitter) that slides over the input signal, the shift-compute process, or shift-fitter approach, is performed. It’s possible that the procedure is accidental or not. In this implementation, the author has used a non-casual convolution process.

The stacked structure of the proposed model

The suggested model uses three layers of LSTM layers. The following table provides a comprehensive breakdown of the model’s several layers: The input data vector is first convoluted, and then an activation function, which is the ReLU layer, is applied. Layered LSTM structures are piled on top of each other in the following three levels. The classification layer’s output neurons are included in the last three levels of consideration. The model is able to fulfill its goal using the Adam optimizer, which is a stochastic gradient descent technique with a learning rate of 0.001.

Stacked CNN LSTM layers & parameters-free-thesis
Stacked CNN LSTM layers & parameters-free-thesis

Performance Analysis

EEG signals taken for study in this work are taken from the analysis carried out in the psychology department, University of Arizona, USA. The complete designing and comparison of the model of screening model are carried out Colaboratory, also known as “Colab” popularly. The data has been bifurcated into training, validation, and testing with a ratio of 70% for training, and the rest 30% are again divided into 20% for validation and
10% for testing. With this ratio, there are 9428 EEG records for training and 2563 and 1000 for validation and testing respectively. The model has been tested for 10% of the untrained dataset. The dataset has been randomly shuffl to avoid the bias conditions. The accuracy achieved by the model is 84% for an epoch of 100 as shown in the Fig.2. While the model loss is around 0.35% as evident from the Fig.3. The model has taken 59 ms to complete an epoch of 100 with the testing conditions. Precision and recall values recorded are 85% and 80% respectively. Through these values, we can analyze the power of stacked LSTM memory cells. The model has exploited two main aspects of the structure that low complexity as compared to the other existing model with a comparable accuracy due to the inherent ability of the staked LSTM layer.

EEG signal of a healthy person-free-thesis
EEG signal PSD of a healthy person-free-thesis
EEG signal of a depressed person-free-thesis
EEG signal of a depressed person-free-thesis
Stacked LSTM CNN Model losses for Depression Detection-free-thesis
Stacked LSTM CNN Model losses for Depression Detection-free-thesis
Stacked LSTM CNN Model Accuracy for Depression Detection-free-thesis
Stacked LSTM CNN Model Accuracy for Depression Detection-free-thesis


Stacked LSTM structures are introduced in the model for depression identification. The stacking not only increases the model’s capacity to extract features, but also its ability to forecast. A total of 45 patients’ data has been used to test the model (24 normal and 21 depressed). With a false positive rate of 0.07 percent, the model achieves a classification accuracy of 84%. The authors want to introduce the ensemble notion to increase the model’s accuracy, which is currently at an early stage.

Similar Other Work available on

Multi Exposed Image Fusion using Deep Learning

Published Paper similar to this work

  1. Ranjani, M., and P. Supraja. “Diagnosing Mental Disorders based on EEG Signal using Deep Convolutional Neural Network.”
  2. Chen, Xun, Chang Li, Aiping Liu, Martin J. McKeown, Ruobing Qian, and Z. Jane Wang. “Towards Open-World EEG Decoding via Deep Learning.” arXiv preprint arXiv:2112.06654 (2021).
  3. Zhang, Tao, Minjie Liu, Tian Yuan, and Najla Al-Nabhan. “Emotion-Aware and Intelligent Internet of Medical Things Toward Emotion Recognition During COVID-19 Pandemic.” IEEE Internet of Things Journal 8, no. 21 (2020): 16002-16013.
  4. Zhang, Xiaowei, Junlei Li, Kechen Hou, Bin Hu, Jian Shen, and Jing Pan. “EEG-based depression detection using convolutional neural network with demographic attention mechanism.” In 2020 42nd Annual International Conference of the IEEE Engineering in Medicine & Biology Society (EMBC), pp. 128-133. IEEE, 2020.
  5. Acharya UR, Oh SL, Hagiwara Y, Tan JH, Adeli H, Subha DP. Automated EEG-based screening of depression using deep convolutional neural network. Comput Methods Programs Biomed. 2018 Jul;161:103-113. doi: 10.1016/j.cmpb.2018.04.012. Epub 2018 Apr 18. PMID: 29852953.





84 reviews for Code for Depression Recognition by Deep Learning

  1. vishal.gupta (verified owner)


  2. vishal.gupta (verified owner)


  3. otuo.acheampong (verified owner)

    very useful website

  4. otuo.acheampong (verified owner)

    very useful website

  5. vishal.gupta (verified owner)

    very useful and helpful

  6. chou_aib (verified owner)


  7. surumi.shajahan (verified owner)


  8. vijay.shinde (verified owner)


  9. vijay.shinde (verified owner)


  10. ftafta


  11. amolj (verified owner)


  12. aadil.hussain (verified owner)


  13. akbaralipaper (verified owner)


  14. dayanand.kumar (verified owner)

    thank you

  15. samiksha.khandelwal (verified owner)


  16. katswiri.felix (verified owner)


  17. dadasdas.sdadasd (verified owner)


  18. dadasdas.sdadasd (verified owner)


  19. dadasdas.sdadasd (verified owner)


  20. raja.kumar (verified owner)


  21. aniket.patel (verified owner)


  22. RP_luo0713


  23. raja.kumar (verified owner)

    didn’t get the code

  24. most khadeja.khatun

    It is helpful for begineers

  25. omid.mokhlessi (verified owner)


  26. omid.mokhlessi (verified owner)


  27. omid.mokhlessi (verified owner)


  28. omid.mokhlessi (verified owner)


  29. omid.mokhlessi (verified owner)


  30. omid.mokhlessi (verified owner)


  31. shubham.sharma-9224 (verified owner)


  32. palak.khurana (verified owner)

    very useful

  33. shubham.sharma-6885 (verified owner)

  34. john.daniel (verified owner)


  35. akshay.warade (verified owner)


  36. bijoy.harun (verified owner)

    very helpful

  37. bijoy.harun (verified owner)

    very hepful

  38. sujin.kumar (verified owner)


  39. sujin.kumar (verified owner)


  40. sujin.kumar (verified owner)


  41. sujin.kumar (verified owner)


  42. raja.abilash (verified owner)


  43. raja.abilash (verified owner)


  44. raja.abilash (verified owner)


  45. gohan.chaula (verified owner)


  46. sanduni.ridmika (verified owner)


  47. sravan satish.kondreddy (verified owner)


  48. anju.negi (verified owner)


  49. dsfsdfsd.dsfsdf (verified owner)


  50. panduranga.terlapu (verified owner)


  51. panduranga.terlapu (verified owner)


  52. ankita.kokkera (verified owner)


  53. panduranga.terlapu (verified owner)


  54. joy.j (verified owner)


  55. emmanuel.kinoti (verified owner)


  56. sam.gouehi (verified owner)


  57. sam.gouehi (verified owner)


  58. d.j (verified owner)


  59. savita yadav (verified owner)


  60. savita yadav (verified owner)


  61. saurabh.marshettiwar (verified owner)

    must try

  62. sumit.kumar-8291 (verified owner)


  63. sumit.kumar-8291 (verified owner)


  64. abirham.getie (verified owner)

    great work

  65. fatma.elshihna (verified owner)

    very good

  66. fatma.elshihna (verified owner)

    very good

  67. fatma.elshihna (verified owner)


  68. savneet.kaur (verified owner)


  69. unsa.soomro (verified owner)


  70. unsa.soomro (verified owner)


  71. muhammad ussama.siraj (verified owner)


  72. emmanuel.kinoti (verified owner)


  73. achraf.bag (verified owner)


  74. abdulraufgarba (verified owner)

    Thank you.

  75. gaurav.kakoti (verified owner)


  76. r.j (verified owner)


  77. frostshand (verified owner)


  78. kautilya.chap (verified owner)

    good and better than expected

  79. anshita.dhoot (verified owner)


  80. anshita.dhoot (verified owner)


  81. anshita.dhoot (verified owner)


  82. chitrabanu.b (verified owner)

    Thank you

  83. chitrabanu.b (verified owner)


  84. shiza_khan41


Only logged in customers who have purchased this product may leave a review.