Machine Learning Applied to Prevention and Mental Health Care in Peru

The present research aims to develop an application that allows the early and timely detection of signs of problems in the mental health of citizens. Agile methodology was used, with its SCRUM framework developing its four steps. In addition, technological tools such as artificial intelligence, mobile applications, social networks and the python programming language were used. Also using SQL Server, Android Studio and the Marvel applications, the latter for the design of the prototypes, through the method of sentiment analysis and machine learning, in order to create a mobile application that is as accurate as possible in its results. For this, several types of algorithm were evaluated, managing to select the most appropriate one since it works based on information collected through the social networks Facebook and Twitter. The result that was obtained was the application that uses machine learning to prevent and take care of mental health in Peru, thus benefiting the citizens of society. Keywords—Artificial intelligence; machine learning; mental health; scrum; sentiment analysis


I. INTRODUCTION
The current global health emergency caused by the SARS-CoV-2 virus has left behind countless deaths and confirmed cases due to the high level of contagion of the disease. Since then, the countries have focused their efforts mainly on controlling and taking the necessary preventive measures to avoid an increase in the number of infections by implementing public health policies [1]. At the same time, various academic articles regarding the coronavirus have been disseminated, the vast majority focusing on epidemiological, genetic and clinical aspects . However, know that the pandemic caused by COVID-19 [2], also brought uneasiness and negative thoughts in the general population that have been spreading since then threatening mental health.
Peru has been one of the countries most affected by the pandemic. Thus, the population had to respect the restrictions established by the governments of the day, remaining long periods of confinement, which in the short or long term represents a potential psychosocial impact on children, adolescents and adults. Due to a radical change in their way of life and the stressful environments caused by the pandemic, as a consequence, concern about the consequences arises not only on physical and mental health [3]. In a survey conducted during the current juncture of 546 people [4], the result was that 69.2% of the participants showed changes in behavior and emotions as well as high levels of stress (47.2%).
In addition to all the above and before the start of the pandemic, in Peru it is estimated that 1 in 5 individuals shows signs of a significant mental problem each year. In the last 4 decades, various initiatives have been promoted but these have not been sustainable, it is not until the approval of Law 29889 that a series of innovations in the provision of services take place in the period 2013-2018. All this has made it possible to implement more than a hundred new mental health care facilities [5]. However, everything is still subject to the commitment of the authorities, the gradual increase in public financing and joint national and international strategies.
In addition, a study of burden by disease category carried out in the country already revealed that mental and behavioral disorders were at the top of the list. It is estimated that approximately 20% of the adult and older population suffer from mental health problems, especially depression, anxiety and alcohol dependence. In addition to the above, 20% of boys and girls suffer from behavioral and emotional disorders; these antecedents are the consequence of an insufficient supply of mental health services by the state. The resources are still insufficient to manage to address the previous problems such as the new ones caused by psychosocial stress [6], linked to exposure to a possible contagion, insecurity and prolonged confinement.
Faced with this pandemic and the various challenges it poses in health matters, the College of Psychologists of Peru consider that in the face of this new reality it is important to be able to adapt to the changes and challenges country is going through. In this sense, they state that the use of technologies represents an opportunity to update knowledge with new learning and various challenges that promote research [7]. Therefore, in order to face mental health problems, it is important to promote mental health research because the country is at risk of continuing to increase the burden of disease from psychiatric institutions. So the need arises for this area to be included in the priorities of health research in Peru [8], the latter being recently ratified by the Ministry of Health for the period 2019-2023.
It is for these reasons that it is important to offer support to contribute and improve the efficiency of mental health plans promoted by the competent institutions. Thus, achieving to offer innovative ways of attending to mental health in the country through the use of technology, thus reinforcing the still fragile efforts to provide a service in conditions to the population. In this way, the effectiveness of the care of our professionals was increased, lightening the load of the functions they perform for better performance.
The objective of this work is to implement an app for the prevention and care of mental health in the country through the use of artificial intelligence. This app can be downloaded to any Smartphone which gives greater accessibility to the service since nowadays everyone has a mobile device. The purpose is to quickly anticipate possible reactions caused by mental illnesses and disorders, the application by means of the activity record in messaging services and / or social networks allow knowing the current situation of the user. If any risky behavior is detected, an alert notification was sent to 1 or more trusted persons. In addition, it was possible to know the mood on a daily basis, which is very important for a person with mental health problems, the latter was possible through a rating scale that have to be marked at the beginning of the day, which allows better monitoring and follow-up user.

II. LITERATURE REVIEW
In carrying out the research work, the subject of artificial intelligence was addressed and how this technology applied to health generates significant contributions to improve the precision and effectiveness of diagnoses and treatments of diseases. It focus mainly on mental health in the country, becoming a very helpful support for the work of specialized medical personnel.
According to the author [9], comments that suicide as a mental health problem is increasing worldwide with a figure of approx. 800,000 deaths per year added to a subjective suicide risk assessment process which limits its efficacy and accuracy. Due to this, suicide detection strategies are focusing on the use of artificial intelligence for the optimization of suicide risk prediction and behavior management. The methodology use was based on articles published between the years 1990 to 2019 and how artificial intelligence has had a positive impact on the care and monitoring of mental health. In addition, artificial intelligence has been used to support the clinical management of suicide, demonstrating the advantages of incorporating this technology. Ideal for use in remote locations with limited access to mental health care. The author concludes based on the observed benefits artificial intelligence has a proven advantage for suicide prediction and mental health care.
On the other hand the author [10], confirming that existing mental disorders have been even more affected by the current global situation caused by COVID-19 increasing mental health problems. To better understand the role of artificial intelligence in their research, the methodology used was based on a review of 253 articles. In the analysis of his framework, he consisted in deriving ideas, concepts and knowledge that was integrated into the development of his project. The results obtained were mainly the possible applications of telepsychiatry and artificial intelligence as well as characteristics and models of artificial intelligence in mental health. Finally, they conclude that even these new technologies cannot be fully adopted in the field of mental health care, they consider that health professionals must choose the most appropriate tools. Based on various aspects, a balance must be found between conventional care and technology-based care, which was achieved progressively.
It also coincides that in order to assess and treat the sequelae of mental health and possible psychiatric comorbidities, it is important to optimize patient care [11]. To ensure the efficient use of limited resources, artificial intelligence can help to achieve this. It considers for its methodology the use of artificial intelligence applications that include validations based on clinical trials. As a result, it is evident that most artificial intelligence applications use simulated data sets that limit the rate and restrict its applicability in a clinical population and in a real world environment. In conclusion, however, more upto-date and innovative test designs can generate better data sets that are generalizable to the entire world population. The acquisition of large volumes of data is of the utmost importance as they are vital to guarantee that the applications allow to obtain greater precision in the results, especially when they are used as part of a diagnosis or clinical treatment.
The objective of the study was a preliminary evaluation of real-world data to verify the effectiveness of a mental well-being mobile application that interacts through text with users with symptoms of depression [12]. The methodology put into use for this case was to observe a group of anonymous users who installed the application. The study used a mixed methods approach to evaluate the impact and levels of user participation. Quantitative analysis measured the impact of the app by comparing the average improvement in depression symptoms among users. The results obtained were the average improvement in the participants' state of mind, and 67.7% considered the application experience useful and encouraging. The effectiveness and levels of user participation were concluded as promising; however, these first findings have yet to be validated in much larger samples and over longer periods of time.
In addition to the aforementioned, he agrees that the current situation has aggravated various existing problems in the field of health and has focused on knowing a list of factors that could show a predisposition to a mental disorder [13]. For its methodology, a survey was conducted of 17,764 adults of different age groups, genders and economic status through statistical analysis and Bayesian network inference. Key factors that affected the mental health of the participants were identified during the pandemic, the integration of Bayesian networks with classic machine learning approaches allowed generating an effective model of the prevalence level of mental health. It was also recognized who were more prone to mental disorders and causes that cause mental pressure, with the aforementioned it was prefixed with a precision of approx. 80% that people are more mentally vulnerable. As a conclusion, it was determined that factors influence mental health problems during the pandemic and what activities help to keep at bay from disorders that may affect, confirming that caring for people with a history of mental illness seems to be more important during this time.
Finally, after what has been stated by the various authors mentioned, consider that the use of artificial intelligence is of utmost importance and is relevant for a faster, more efficient and optimal work with regard to mental health as it shows great advantages that serve as support health professionals in their work, reducing the workload which not only help better decision-making, but also ensures better care and more accurate results in diagnoses and treatments as well as monitoring and supervision of the patient until recovery.

III. METHODOLOGY
Next proceed to describe the methods and tools used for this research work. This framework implies a process management to tackle complex projects that require dynamic environments, so they demand speed of results and flexibility. It is an agile work methodology that has several objectives and that allows to accelerate processes, act quickly on possible changes and make periodic deliveries of work.
1) Beginning: In this first phase, the respective roles are identified and assigned, who was the Scrum Master and the Stakeholders [14]; the members of the work teams are defined according to their abilities and contributions to the project.
2) Planning and Estimation: In this second phase, the user stories are created, the sprint backlog [15], also be carried out taking into account the estimate for their correct implementation of each one of them [16].
3) Implementation: In this third phase, the respective prototypes are designed, taking into account the requirements of each of the stories raised.

4) Reviews and Retrospectives:
In this fourth phase, the respective review of the Sprint is carried out by the team, in an activity that allows the inspection and adaptation of the product, the most important thing is the conversation by the team to understand the situation and receive feedback [17]. In Fig. 1 observe the order of the processes for the Scrum methodology.

B. Technological Tools
The technologies used for this research work guarantee an optimal development of the mobile application based on the knowledge of the members, managing to finish it according to the specifications and in the established time.
1) Artificial Intelligence: This technology seeks to provide software with the capacity for learning based on data, with the latter patterns and opportunities arise through which performance tests are carried out to measure efficiency based on the percentage of errors and successes. The present research project opts for machine learning as it is not linear since it adapts through learning to new cases or situations, even not needing constant supervision. In Fig. 2 can see the steps of machine learning. 2) Mobile Apps: Refer to programs designed for exclusive use on mobile devices, generally smartphones, which allows the user access to various services and functions, both professional, entertainment, educational, among others, facilitating the development of their activities.
3) Social Networks: Social networks are communities made up of various people and organizations that relate to each other through internet access, allowing immediate communication between users, sharing information and leisure activities. For the present work, take advantage of the messaging service that these communities provide, serving as the basis for the analysis of the individual's behavior and considering the massive use of these tools. Table I shows the results of a survey carried out by IPSOS [18], confirming the high percentage of use of social networks in the country.

4) Python
: It is a high-level programming language that manages to process all kinds of data structures, whether text or numeric. It has taken the characteristics of its predecessors, it is free software, that is to say, open source and allows it to be used and distributed freely even for commercial use. It is accessible, simple and multiplatform, for this project it represents a great advantage due to its wide library, selection of frameworks and its simplicity in syntax.

C. System Requirements
The programs necessary for an adequate development environment are considered for this project, allowing the realization and implementation of the app correctly.
1) SQL Server: is a relational database management system (RDBMS). It supports a wide variety of transaction processing, business intelligence, and analytical applications in corporate IT environments.
2) Android Studio: is a development platform that allows you to build mobile applications exclusively for Android operating systems, as well as various tools that allow you to develop an app that is stable on the target devices. 3) Marvel App: is an online tool to make layout and prototypes of both web pages and applications on mobile devices.

A. Planning
This project is made up of several stages where various advances are made that must be completed in a certain time. These stages begin with the definition of user stories that allow identifying the system requirements. The project has 10 user stories with an approximate time of 15 weeks for the stories to be finalized. In Table II can see the description of each story, which allows to better understand the functions that the app has. As an administrator I want the application to show a friendly and intuitive interface so that it is easy to use and allows the user to register. H2 As an administrator, I want the application to ask the user to mark their state of mind on a daily basis. H3 As an administrator, I want the application to be able to collect information from social networks and messaging services used by the user. H4 As administrator I want the application to send a daily report to the email of the assigned medical specialist. H5 As an administrator, I want the app to display a questionnaire on the cell phone screen that the user must fill out on a mandatory basis in order to better control their mental health. H6 As a user, I want to be able to register the contact details of trusted people. H7 As a user, I want the application to show me information related to emotional well-being when entering the app. H8 As an administrator, I want the application to send an alert notification to the user's trusted persons in case risky behavior is detected. H9 As an administrator, I want the application interface design to be made based on colors and sounds that transmit calm and stimulate positive emotions in the user. H10 As an administrator, I want the application to show the user motivational and / or informative messages as a preventive function in case indications of possible risky behaviors are detected without having to enter the app.

B. Estimate
For this phase, the user stories that have been previously defined are organized through the product backlog allowing to have fixed goals and meet the established deadlines. The estimations are made by means of the planning poker technique where the team is in charge of assigning a number (Fibonacci series) to each user story to be able to classify them through previous agreements. As can be seen in Table III in the estimation column, the team determines the effort involved in developing each function and requirement raised based on history 6 since its development is the one with the least difficulty.
To define the priority of user stories, take into account the effort and difficulty that their respective development, operation and execution may require, as well as the importance and relevance that it supposes for the present project.
The development of the project is divided into three sprints, with the first sprint obtaining a total of 8 story points, being  Sprint  H3  5  1  3  H4  5  2  3  H10  8  3  3  H8  8  4  2  H5  3  5  2  H6  1  6  2  H2  2  7  2  H1  2  8  1  H7  3  9  1  H9 3 10 1 the one that requires the lowest speed, which allows the team to integrate and gain greater confidence in the process and progress of the sprint in question. The second and third sprints receive 14 and 18 points respectively and although the points have increased, the team is already able to organize and communicate much better, which allows a greater understanding and minimizes errors when working as a team. In Fig. 3, see in a graph the sprints already organized and with their respective story points.

C. Implementation and Development
In this phase, the process to develop the mobile application is detailed using the technologies and procedures proposed. The modeling of the Machine Learning software is carried out, in addition [19], at this stage make the choice of the algorithm for learning the artificial intelligence software.

1) Sentiment Analysis:
It is a process that analyzes opinions, behavior and impressions of users, basically it consists of extracting valuable information after having evaluated attitudes and emotions behind a series of words, focusing on the lexicon that expresses feelings. It has a generally commercial use with applications in marketing, politics, services, companies, surveys, brand positioning, etc. For the present project [20], this method is used for the analysis of data in social networks because the latter have gone from being simple means of communication to means of critical thoughts and / or opinion, allowing the content to be classified into two categories: positive and negative. In Fig. 4, observe the two methods that can be used for the process and development of sentiment analysis, for the present work the alternative of an automatic learning model is chosen to achieve better precision and accuracy of the results.
2) Supervised Learning: Machine learning is divided into 2 types of methods for the application of the project, supervised learning is chosen since it is the most recommended for jobs that require the use of classification and [22], allowing developers to more accurately identify the processes of intelligence software artificial and at the same time have a better control of the training material for the learning process.

3) Datasets:
The data set is divided into two parts, the first data is used for tests and the rest as training, the latter being used to achieve Machine Learning modeling that gives the most exact results possible and with the least margin of error. In Fig. 5, Facebook and Twitter are considered as social networks of reference for the extraction of data from the present project. To obtain the necessary data, the API that the platforms offer for developers is used. The results obtained from the model [23], are compared with information based on the medical history of patients who have presented disorders related to depression and anxiety.

4) Data Preprocessing:
The set of training and testing data for the algorithm is previously subjected to a series of techniques and procedures that allow cleaning and reducing certain characteristics of the texts that are irrelevant for processing. The purpose of this phase is to normalize the data by converting the text into vectors for the classification process and facilitating sentiment analysis using Machine Learning.

a) Filter:
In some cases the data may contain special characters that denote admiration, questions or some reference to web pages or tagging. These characters must be removed obtaining a clean data set for vector representation and model classification.

b) Tokenization:
It allows to divide the sentences into smaller parts called tokens, which are used for later stages of the processing, facilitating the use of the data. For the project, a token is equivalent to a word.

c) Anonymity of Personal Information:
The identity of the authors of social media posts must be kept anonymous so as not to expose users without their consent.

d) Remove Stop-Words:
In natural language there are many words that are used frequently and that by themselves do not keep any meaning. In the Spanish language these words are usually articles, conjunctions and pronouns.

5) Algorithm:
For this project, the Support Vector Machines classification algorithm is chosen, due to its advantage and ability to work with large databases in addition to performing text classification very well because it can handle large functions and in turn demonstrate robustness when the set of data is small and is distributed in a large area, for those reasons it has given reliable results in past research.
In Fig. 6, the process from when the data are obtained to their respective classification and modeling with the chosen algorithm is graphically represented. As mentioned in [24] correct data processing can make the difference between a model with lower or higher performance. This project takes these procedures into consideration to guarantee a model that is as accurate and precise as possible.
In Fig. 7, see a graph that represents the operation of the algorithm, dividing classes, that is, cases versus noncases, based on a line called the hyperplane. The hyperplane www.ijacsa.thesai.org Machines [25].
is created based on the greatest possible distance from the closest neighboring predictor data points between the classes [25]. More complex data that cannot be separated into two dimensions can be raised to a higher dimension through a process called kernelling.

A. Design and Prototypes
The designs are evidenced based on the sprints and user stories, each one is described to understand in greater detail the functions that are implemented in the mobile platform.

1) First Sprint:
This sprint focuses mainly on the user interface and menu section, in Fig. 8 can see on the left the prototype that shows the options to be able to register and log in to the application, the use of sober colors is considered in the realization of the prototypes so that they can transmit calm stimulating positive emotions to the user.
In the prototype on the right note the data that the user is required to register and create an account, in turn it has a section where you fill in the data of trusted people or close contacts.
2) Second Sprint: This sprint focuses on the part of mental health care of the user, in Fig. 9 the alert message sent to the trusted person or close contact of the user is shown, in this way preventive measures are reinforced and maintained an alert to any risky behavior that can be detected by the app based on the data obtained from the activity on the smartphone.
In the following figure, a form appears on the user's screen that must be filled out monthly in order to have greater control over the behaviors, moods or behaviors that the user may manifest, said screen appear without the need for the user. Once entered into the app, the questions allow to detect symptoms related to depression or anxiety. In addition, an interface appears to the user at the beginning of his day, he must fill it with a mandatory character to know her state of mind, this screen appear daily.  3) Third Sprint: This sprint is related to the collection of information based on the user's interactions with their social networks and messaging services. In Fig. 10 observe the report that it generates monthly to be sent to the health specialist or medical center where the information was evaluated and allows the user's diagnosis and treatment to be further adapted.

B. Mobile App
Once the model has been completed and put to the test, the application must now obtain the permissions to access the mobile device and begin to collect data on the user's activities through the use of their social networks and messaging applications. In Fig. 11, see graphically the steps that the application follows once it is installed on the mobile device and launched.
The information already being stored is examined by the artificial intelligence program and is responsible for comparing patterns through a database that determine indications or possible changes in the user's behavior and that may pose a  risk to this or their environment. In case a risky behavior is detected, an alert notification is sent to trusted people who have been registered by the user in the application, being relatives or the assigned health specialist. In Fig. 12, observe the architecture of the app and the processes it carries out communicating through internet access to notify in case the algorithm detects unusual behavior on the part of the user.

C. Algorithm Performance
The present work proposes an application for the care and prevention of mental health, mainly focused on depression and anxiety disorders that have worsened even more with the current pandemic. On [26], the good performance of the algorithm chosen for this project is verified, where 3 aspects are taken into consideration: precision, sensitivity and F-score. In Fig. 13, the Super Vector Machines (SVM) algorithm stands out for the results obtained in precision and F-score (accuracy) obtaining 0.95% and 0.92% respectively, demonstrating good performance to predict users that may present problems of mental health. In addition, the good result of the algorithm is recognized in the face of this type of problem.

D. Mental Health in Peru
Mental health problems in the country have increased with the current situation, according to data from INFOSALUD telephone line authorized by the state for citizens who want psychosocial support, it is confirmed that the first 2 places of the most made calls are related to mental health problems where anxiety and depression occupy second place only in the months of April to May 2020 with a total of 3144 calls [27]. In Fig. 14, a survey recently carried out by the IPSOS pollster is shown where 37% of those interviewed consider that one of the biggest problems facing the population is mental health.
The survey was carried out during the pandemic period, so the responses of the interviewees reflect the reality of a large part of the population that not only considers to have been affected by the economic situation but also psychologically by the long period of quarantine that still exists lives in the country, added to the fear and concern of being infected with the Covid-19 virus.
The results of this project favor to reduce the psychological effects caused by quarantine for this reason, the development of an application that serves as support to specialized health personnel turns out to be a support that generates a positive impact for both doctors and patients. In this way, access to personalized care is facilitated and appropriate preventive measures can be taken in the event of warning signs that may manifest as risk behaviors that are induced by mental health problems.

VI. CONCLUSION AND FUTURE WORK
The research concludes that the application of Machine Learning allowed effective and efficient monitoring of mental health care and prevention through better control of user behavior through the use of social networks, even allowing the appropriate measures to be taken. for behaviors that indicate possible harm to your mental health. In addition, the scrum methodology allowed making suitable prototypes to be able to prevent health and thus benefit citizens. For future work, it is recommended to continue increasing the data for the training of the Machine Learning model, allowing it to be more robust with information related to more mental health diseases and expanding its predictive capacity. This project has only been limited to exploring results considering an ideal environment for data collection, it is also recommended to improve the processing in cases where the data may not be objective, such as cases of sarcasm, spelling errors and spam in the content written by the users.