**5. Machine learning for respiratory signal pattern detection**

Machine Learning is the result of pattern recognition and the assumption that computers can learn to execute a task. As a field of artificial intelligence, machine learning is the ability of a machine to learn, identify, and classify from being exposed to specific data in an interactive way, and to not only learn and make reliable decisions but also to adapt when exposed to new data.

This technique can be useful for automatic pattern recognition in respiratory signals such as sleep apnea, respiratory patterns, and talking detection [10, 49, 50]. The steps to implement a machine learning algorithm are introduced in the following sections.

#### **5.1 Feature extraction**

First, for machine learning classification, some features must be given to the classification algorithm. These features must be extracted from the original signal, and they must be well chosen for better results.

For example, when working with a wearable acoustic sensor [50] aiming to recognize activity patterns like sitting, eating, and drinking and respiratory patterns such as whispering, deep breath, and coughing, the features extracted from the sensor signals were related to time, frequency, and cepstral:


It is also possible to use a tool that automatically extracts the features of the signals being studied. With the purpose of identifying talking in respiratory signals [10], more than 10 features were extracted using the Python library "tsfresh" [51]; those that presented more than 10% of recurrence between the tests were manually selected in order to use that feature for classification in the algorithm.

It is common to extract a variety of features in a study, but the effectiveness of a machine learning algorithm strongly depends on which one will be selected and how the data will be selected for training and validation.

## **5.2 Classification selection**

After the selection of features to be used in the algorithm, it is important to decide which the classes are and how the data will be processed. It is important to select what will be used to train the algorithm and what will be used to validate it. There are several ways of separating the acquired data so that the network is trained without the risk of overfitting.

For instance, in Yatani and Tuong [25], two approaches were carried out:


A different approach was used by Ejupi and Menon [10]: the data were obtained executing different activities such as walking, standing, and sitting, and an algorithm was trained for each one. For classification, 70% of the database was used for training and 30% for validation.

These techniques prevent the major problem in machine learning, overfitting [52]. In case an algorithm is overfitted, it will produce inaccurate results creating unrealistic patterns. It is always wise to select which data will be used to train the algorithm and which will be used to validate the results, never using all dataset to just one task.

**65**

*Breathing Monitoring and Pattern Recognition with Wearable Sensors*

The strategy or algorithm to be used in a project as well as its effectiveness and performance are strongly dependent on the problem domain (e.g., data structure, database size, etc.) [53]. It is therefore impossible to choose a method as the best one regardless of domain intricacies. Some popular machine learning algorithms are

In order to identify speech pattern using a wearable textile-based sensor [10], the best results were obtained with Support Vector Machines (SVMs). The basic approach for SVM algorithms is to give a set of basic examples and their weight, generally understood as positive and negative (binary) examples for the algorithm, interpreted as classes, where there is a degree of similarity between them, a kernel

SVM was applied for identifying activities using an acoustic sensor [50]. They used more than two classes, comparing one against the other as a strategy to obtain results, using the Radial Basis Function (RBF) as a kernel function. All the implementation using a library "LIBSVM" [54] reaches almost 80% of accuracy.

The Naïve Bayes algorithm can be used when it is necessary to recognize the user activities in real time [25]. The theorem is based on the Bayes statistical theorem that describes the probability of an event based on conditions or previous knowledge. The "naïve" comes from the naivety of the assumption that the results are

where, P(A|B) is the probability that hypothesis A is true given data of type

P(A) is the probability that A is true independently of data, and P(B) is the

sets, which can lead to another set of classification or decision and, at the same

This algorithm is simple, computationally cost-effective and can be used for small datasets, as it was used to identify activity patterns such as speaking, laugh-

The algorithm uses this probability structure to classify at least two independent

An artificial neural network (ANN) is a technique based on a series of connected inputs and outputs. Its structure resembles neurons, each one connected and with associated weights. The weights represent information being used by the net to solve the problem and can be adjusted as required. The networks can be supervised or not, the fundamental difference is that in supervised learning, the target vectors

B. P(B|A) is the probability of data B given that hypothesis A was true.

\_\_\_\_\_\_\_\_\_\_\_\_

*<sup>P</sup>*(*B*) (6)

*DOI: http://dx.doi.org/10.5772/intechopen.85460*

**5.3 Machine learning algorithms**

presented in the following topics.

function, as a means of comparison [52].

independent given the cause [52].

time, to another independent set.

*5.3.3 Artificial neural networks*

indicate what is wanted from the network.

From the Bayes' theorem, we have Eq. (6):

probability of data B regardless of the hypothesis.

*<sup>P</sup>*(*A*|*B*) <sup>=</sup> *<sup>P</sup>*(*B*|*A*) <sup>∗</sup> *<sup>P</sup>*(*A*)

ing, and coughing, presenting good results of accuracy [25].

*5.3.1 Support Vector Machines*

*5.3.2 Naïve Bayes*
