Full text
UNIVERSITAT POLITÈCNICA DE CATALUNYA (UPC) – BarcelonaTech FACULTAT D'INFORMÀTICA DE BARCELONA (FIB) MASTER IN INNOVATION AND RESEARCH IN INFORMATICS - DATA SCIENCE Data analysis of socio-economic and financial factors from a public world-wide source Academic year 19/20 Date - 27/01/2020 Autor: Santiago Calvo Fantova Director/a: Prof. Marta Arias
1 1. Abstract 1 Many socio-economic studies are nowadays trying to accomplish a complete description of how the different elements of our society and world are connected. This work is an attempt to build an architecture that provides an explanation of the connections and impacts that exist among the different indicators (for now on also mentioned as sectors) of a state or population (Agriculture, Climate Change, Economy & Growth, Energy & Mining, Education, Health, Poverty, Science & Technology, Social Development, and others). We will focus our effort in the research of, not only the correlations that may exist between these indicators and thought the different countries analyzed, but also the causality that relates them. With causality (we will deploy a Bayesian Network architecture for each country to accomplish this task), we will be able to describe the impact and influence that one indicator may have in the others. This could lead to an accurate, powerful and global knowledge of the functioning of our world and each single country in particular, along with a vision of the dependencies between the different indicators that describe a country. Finally, we will also propose a clustering model where each individual will be a representation of the Bayesian Network obtained for each country. With this model, we will provide N aggrupation of countries with their Bayesian Network representation for each one, which will give us a global vision of the functioning of our world represented by the causal relationships between the different indicators that can be found in our countries or populations. 2. Introduction, motivation and goals The idea of this project born with the following questions: Given the huge, historical, complex and diverse amount of data that exist nowadays for one country or population; Is it possible to extract an accurate description of the functioning of a country from it?; Is it possible to create models that group the different countries in some clusters?; Can we create a global description of the functioning of our world?. We are aware that there exist many studies that are focused on the analysis of the different correlations between the diverse data variables that can be found for one country. But we wanted to go one step further and focus the analysis on not only the possible correlations that could exist between data variables but also the causal relationships that might exist among them. This is one of the key points of our project, the fact that we focus on the search of causality instead of correlation. The previous questions arise on us the necessity of developing an architecture that could try to give an answer to them. We first found the source of our project, we were looking for a good-quality statistical data of countries indicators and we found “The World Bank”[1]. The World Bank Group is one of the world’s largest sources of funding and knowledge for developing countries. One dataset per country can be downloaded, it contains data for the last 60 years (from 1960) and for more than 1500 variables grouped in 20 different sectors (Agriculture, Climate Change, Economy & Growth, Energy & Mining, Education, Health, Poverty, Science & Technology, Social Development, and others). We downloaded the data for the top 100 countries in the world with the highest GDP index. Then, our goal was to use 1 The sectors and countries will be sometimes referenced with a shortening, to understand them we provide a dictionary in another attached document.
2 this huge dataset to develop a model to study the causal relationships between these sectors and try to group these causal models (one for each country) in different sets so that we can clusterize the total set of countries in some different groups. And finally, provide a global model for each of those groups or clusters. 3. State of the art In this section, we will talk about the state of the art of the different methods and algorithms that we have used in our project and we will give a description and explanation of all them. Each sub-section is referenced to the source and authors of the corresponding books and articles from where we have gathered this theoretical information. a. Dimensionality reduction algorithms [2] In the modern age of technology, increasing amounts of data are produced and collected. In machine learning, however, too much data can be a bad thing. At a certain point, more features or dimensions can decrease a model’s accuracy since there is more data that needs to be generalized, this is known as the curse of dimensionality. Dimensionality reduction is a way to reduce the complexity of a model and avoid overfitting. There are two main categories of dimensionality reduction: feature selection and feature extraction. Via feature selection, we select a subset of the original features, whereas in feature extraction, we derive information from the feature set to construct a new feature subspace. We have considered two different dimensionality reduction methods, the well-known and linear method Principal Component Analysis (PCA) and a most recent non-linear methodology that consist of the use of a neural network for feature extraction (known as Autoencoders). i. PCA [2] Feature sets can be more compact than the data they represent. Dimension reduction provides compact representations for storage, transmission, and classification. Dimension reduction algorithms operate by identifying and eliminating statistical redundancies in the data. The optimal linear technique for dimension reduction is principal component analysis (PCA). PCA performs dimension reduction by projecting the original n-dimensional data onto the m < n dimensional linear subspace spanned by the leading eigenvectors of the data's covariance matrix. Thus, PCA builds a global linear model of the data (an m-dimensional hyperplane). Since PCA is sensitive only to correlations, it fails to detect higher-order statistical redundancies. One expects nonlinear techniques to provide better performance, which is more compact representations with lower distortion. This unsupervised linear transformation technique is widely used across different fields, most prominently for feature extraction and dimensionality reduction. PCA helps us to identify patterns in data based on the correlation between features. Briefly, PCA aims to find the directions of maximum variance in high-dimensional data
3 and projects it onto a new subspace with equal or fewer dimensions than the original one. The orthogonal axes (principal components) of the new subspace can be interpreted as the directions of maximum variance given the constraint that the new feature axes are orthogonal to each other, as illustrated in the Figure 1. In the preceding figure, x1 and x2 are the original feature axes, and PC1 and PC2 are the principal components. If we use PCA for dimensionality reduction, we construct a 𝑑 𝑥 𝑘 -dimensional transformation matrix W that allows us to map a sample vector x onto a new k– dimensional feature subspace that has fewer dimensions than the original d– dimensional feature space: 𝑥 =[𝑥1,𝑥2,…,𝑥𝑑], 𝑥 ∊ ℝ𝑑 𝑥𝑊, 𝑊 ∊ ℝ𝑑𝑥𝑘 𝑧 = [𝑧1,𝑧2,…,𝑧𝑘], 𝑧 ∊ ℝ𝑑 As a result of transforming the original d-dimensional data onto this new k-dimensional subspace (typically k ≪ d), the first principal component will have the largest possible variance, and all consequent principal components will have the largest variance given the constraint that these components are uncorrelated (orthogonal) to the other principal components. Even if the input features are correlated, the resulting principal components will be mutually orthogonal (uncorrelated). It is important to point out that the PCA directions are highly sensitive to data scaling, thus, we need to standardize the features prior to PCA if the features were measured on different scales and we want to assign equal importance to all features. Therefore, in summary, PCA algorithm could be described in the following simple steps: 1. Standardize the d-dimensional dataset. 2. Construct the covariance matrix. 3. Decompose the covariance matrix into its eigenvectors and eigenvalues. Figure 1. PCA representation in two spaces or dimensions example.
4 4. Sort the eigenvalues by decreasing order to rank the corresponding eigenvectors. 5. Select k eigenvectors which correspond to the k largest eigenvalues, where k is the dimensionality of the new feature subspace (k ≤ d). 6. Construct a projection matrix W from the “top” k eigenvectors. 7. Transform the d-dimensional input dataset X using the projection matrix W to obtain the new k-dimensional feature subspace. This is, therefore, how we get the features extracted for dimensionality reduction. ii. Autoencoders [3][4] An autoencoder is an unsupervised artificial neural network that learns how to efficiently compress and encode data then learns how to reconstruct the data back from the reduced encoded representation to a representation that is as close to the original input as possible. Autoencoder, by design, reduces data dimensions by learning how to ignore the noise in the data. In the Figure 2 we display an illustrative example of an autoencoder where the source data is an image. Autoencoders are neural networks that aims to copy their inputs to their outputs. They work by compressing the input into a latent-space representation, and then reconstructing the output from this representation. This kind of network is composed of two parts: Encoder: This is the part of the network that compresses the input into a latentspace representation. It can be represented by an encoding function h=f(x). Decoder: This part aims to reconstruct the input from the latent space representation. It can be represented by a decoding function r=g(h). The autoencoder as a whole can thus be described by the function g(f(x)) = r where we want r as close as the original input x. Copying the input to the output: If the only purpose of autoencoders was to copy the input to the output, they would be useless. Indeed, we hope that, by training the autoencoder to copy the input to the output, the latent representation h will take on useful properties. This can be achieved by creating constraints on the copying task. One way to obtain useful features from the autoencoder is to constrain h to have smaller dimensions than Figure 2. Example of autoencoder compression for image data.
5 x, in this case the autoencoder is called undercomplete. By training an undercomplete representation, we force the autoencoder to learn the most salient features of the training data. If the autoencoder is given too much capacity, it can learn to perform the copying task without extracting any useful information about the distribution of the data. This can also occur if the dimension of the latent representation is the same as the input, and in the overcomplete case, where the dimension of the latent representation is greater than the input. In these cases, even a linear encoder and linear decoder can learn to copy the input to the output without learning anything useful about the data distribution. Ideally, one could train any architecture of autoencoder successfully, choosing the code dimension and the capacity of the encoder and decoder based on the complexity of distribution to be modeled. What are autoencoders used for? Today data denoising and dimensionality reduction for data visualization are considered as two main interesting practical applications of autoencoders. With appropriate dimensionality and sparsity constraints, autoencoders can learn data projections that are more interesting than PCA or other basic techniques. Autoencoders are learned automatically from data examples. It means that it is easy to train specialized instances of the algorithm that will perform well on a specific type of input and that it does not require any new engineering, only the appropriate training data. However, there are some fields where autoencoders have important limitations and they are not working very well, this is the case of image compression, for example. As the autoencoder is trained on a given set of data, it will achieve reasonable compression results on data similar to the training set used but will be poor general-purpose image compressors. b. Imputation methods [5] Missing data is a common and exciting problem in statistical analysis and machine learning. They are necessary for evaluating data quality and can have different sources such as users not responding to questions in a recommender system, death of patients on treatment or non-compliance, errors in a database that describes the maintenance information of plant equipment, and so on. Missing Data Mechanism: To understand the importance of missing data, we need to identify the reasons for missing data occurrence. The first step is to understand the data and more importantly, the data collection process. This can lead to the possibility of reducing data collection errors. The nature or mechanism of missing data can be categorized into three major classes. These categories are based on the degree of relationship between the nature of the missing data and observed values: Missing Completely at Random (MCAR): This means that the nature of the missing data is not related to any of the variables, whether missing or observed. In this case, the missingness on the variable is completely unsystematic. Missing at Random (MAR): This means that the nature of the missing data is related to the observed data but not the missing data.
6 Missing Not at Random (MNAR): This is also known as non-ignorable because the missingness mechanism cannot be ignored. They exist when the missing values are neither MCAR or MAR. The missing values on the variable are related to that of both the observed and unobserved variables. The easiest way to assume a missing data mechanism from data is understanding the data collection process and use substantive scientific knowledge (critical in determining randomness in a missing data). The second method to understand the type of missing data mechanism is statistical testing. This method is mostly used when trying to figure out if the mechanism is either MAR or MCAR. Handling Missing Data: There are several methods used for treating missing data. Some of these methods started gaining a resurgence in the last decade because of their importance in clinical trials and biomedical studies. In addition, there are certain drawbacks associated with each of these methods when used for data mining and one needs to be careful to avoid bias or the under- or over-estimation of variability. Mean, Median and Mode Imputation: Using the measures of central tendency involves substituting the missing values with the mean or median for numerical variables and the mode for categorical variables. The major limitation of using this method is that it leads to biased estimates of the variances and covariance. The standard errors and test statistics can also be underestimated and overestimated respectively. This imputation technique works well with when the values are missing completely at random. Imputation with Regression: This is an imputation technique that uses information from the observed data to replace the missing values with predicted values from a regression model. The major drawback of using this method is that it reduces variability and overestimates the model fit and correlation coefficient. k-Neareast Neighbor (kNN) Imputation: For k-Nearest Neighbor imputation, the missing values are based on a kNN algorithm. These values are obtained by using similarity-based methods that rely on distance metrics (Euclidean distance, Jaccard similarity, Minkowski norm etc). They can be used to predict both discrete and continuous attributes. The main disadvantage of using kNN imputation is that it becomes time-consuming when analyzing large datasets because it searches for similar instances through all the dataset. Choosing the correct value for the number of neighbors (k) is also an important factor to consider when using kNN imputation. Multiple Imputation using MICE (Multiple Imputation by Chained Equations): Multiple imputation is a process where the missing values are filled multiple times to create “complete” datasets. Multiple imputation has many advantages over traditional single imputation methods. Multiple Imputation by Chained Equations (MICE) is an imputation method that works with the assumption that the missing data are Missing at Random (MAR). Recall that for MAR, the nature of the missing data is related to the observed data but not the missing data. The
7 MICE algorithm works by running multiple regression models and each missing value is modeled conditionally depending on the observed (non-missing) values. c. Bayesian Networks [6][7][8][9][10] Bayesian networks are probabilistic models based on direct acyclic graphs. These models enable a direct representation of causal relations between variables. Their structure is ideal for combining prior knowledge, which often comes in causal form, and observed data. These networks, also known as belief networks, belong to the family of probabilistic graphical models (GMs). These graphical structures are used to represent knowledge about an uncertain domain. In particular, each node in the graph represents a random variable, while the edges between the nodes represent probabilistic dependencies among the corresponding random variables. These conditional dependencies in the graph are often estimated by using known statistical and computational methods. Hence, BNs combine principles from graph theory, Probability Theory, computer science, and statistics. GMs with undirected edges are generally called Markov random fields or Markov networks. These networks provide a simple definition of independence between any two distinct nodes based on the concept of a Markov blanket. Markov networks are popular in fields such as statistical physics and computer vision. BNs correspond to another GM structure known as a directed acyclic graph (DAG) that is popular in the statistics, the machine learning, and the artificial intelligence societies. BNs are both mathematically rigorous and intuitively understandable. They enable an effective representation and computation of the joint probability distribution (JPD) over a set of random variables. The structure of a DAG is defined by two sets: the set of nodes (vertices) and the set of directed edges. The nodes represent random variables and are drawn as circles labeled by the variable names. The edges represent direct dependence among the variables and are drawn by arrows between nodes. In particular, an edge from node Xi to node Xj represents a statistical dependence between the corresponding variables. Thus, the arrow indicates that a value taken by variable Xj depends on the value taken by variable Xi, or roughly speaking that variable Xi “influences” Xj. Node Xi is then referred to as a parent of Xj and, similarly, Xj is referred to as the child of Xi. An extension of these genealogical terms is often used to define the sets of “descendants”—the set of nodes that can be reached on a direct path from the node, or “ancestor” nodes—the set of nodes from which the node can be reached on a direct path. The structure of the acyclic graph guarantees that there is no node that can be its own ancestor or its own descendent. Such a condition is of vital importance to the factorization of the joint probability of a collection of nodes as seen below. Note that although the arrows represent direct causal connection between the variables, the reasoning process can operate on BNs by propagating information in any direction. A BN reflects a simple conditional independence statement. Namely that each variable is independent of its non-descendants in the graph given the state of its parents. This property is used to reduce, sometimes significantly, the number of parameters that are
8 required to characterize the JPD of the variables. This reduction provides an efficient way to compute the posterior probabilities given the evidence. In addition to the DAG structure, which is often considered as the “qualitative” part of the model, one needs to specify the “quantitative” parameters of the model. The parameters are described in a manner which is consistent with a Markovian property, where the conditional probability distribution (CPD) at each node depends only on its parents. For discrete random variables, this conditional probability is often represented by a table, listing the local probability that a child node takes on each of the feasible values—for each combination of values of its parents. The joint distribution of a collection of variables can be determined uniquely by these local conditional probability tables (CPTs). Thus, we can define a Bayesian network B as an annotated acyclic graph that represents a JPD over a set of random variables V. The network is defined by a pair B = 〈 G, Θ 〉 , where G is the DAG whose nodes X1, X2, …, Xn represents random variables, and whose edges represent the direct dependencies between these variables. The graph G encodes independence assumptions, by which each variable Xi is independent of its nondescendants given its parents in G. The second component Θ denotes the set of parameters of the network. This set contains the parameter equation image for each realization xi of Xi conditioned on i, the set of parents of Xi in G. Accordingly, B defines a unique JPD over V, namely: 𝑃𝐵(𝑋1,𝑋2,…,𝑋𝑛)= ∏𝑃𝐵(𝑋𝑖|𝜋𝑖)= 𝑛 𝑖=1 ∏𝜃𝑋𝑖|𝜋𝑖 𝑛 𝑖=1 If Xi has no parents, its local probability distribution is said to be unconditional, otherwise it is conditional. If the variable represented by a node is observed, then the node is said to be an evidence node, otherwise the node is said to be hidden or latent. Inference via BN: Given a BN that specified the JPD in a factored form, one can evaluate all possible inference queries by marginalization, which is summing out over “irrelevant” variables. Two types of inference support are often considered: predictive support for node Xi, based on evidence nodes connected to Xi through its parent nodes (also called top‐down reasoning), and diagnostic support for node Xi, based on evidence nodes connected to Xi through its children nodes (also called bottom‐up reasoning). Such a support is formulated as follows: 𝑃(𝐶 =𝑇|𝐴 = 𝑇)= 𝑃(𝐶 =𝑇,𝐴 =𝑇) 𝑃(𝐴 = 𝑇) Where 𝑃(𝐶 = 𝑇,𝐴 = 𝑇) = = ∑ 𝑃(𝐶 =𝑇)𝑃(𝑆)×𝑃(𝑊|𝐶 =𝑇)𝑃(𝐵|𝑆,𝐶 = 𝑇)𝑃(𝐴 = 𝑇|𝐵) 𝑆,𝑊,𝐵,𝐶 ∈{𝑇,𝐹}
15 the different countries. To do that we had the information of those variables for the last 60 years. But, we do not need precisely one year or another, and the analysis won’t change if we lack for one country a lot of information for some years (for example 1960, 1963 and 1975) and for another country some different years (for example 1962, 1967 and 1971). For this reason, we decided to accomplish the missings dealing in two different steps. There are two ways of analyzing the missing values, by observations (rows) or by variables (columns). We decided to first look at the missingness by variables. Let us take the country Spain as example. What we found is that there were around 1078 variables, out of the total 1596, with more than 50% missing values. We decided to set the threshold of direct discard a variable in 50% of missingness, this means that we will keep those variables that have at least half of their data informed. To give a more illustrative picture of the amount of missings that we had at first, let us show an histogram of the number of missings by variables in Figure 8. Subsequently, we had to analyze the missingness of the dataset resultant form the previous operation by observations (rows). We found that from the remaining data 10 years (10 observations, out of the total 59) still had more than the 50% of the data missing and those years where from 1960 to 1969. Not surprisingly, we discovered that when running the rest of the countries almost always this behavior was the same. Now, the following task to complete our dataset is to impute the remaining missing values. Missings Imputation As we explained before, the step before applying a missing imputation algorithm is to identify the type of missing values that we have in our dataset. We pointed out that the type of missings that we have in a dataset depends on the data collection process. We are not the data collectors but we know that the source that we are using collects data from the different countries sources. Thus, we assume that when Figure 8. Missings Histogram example.
16 the data is missing could have been for very different reasons due to the huge variety of variables that we have and the wide range of years and different countries that conform our dataset. Therefore, taking also into account that there is not a clear line separating the two first types of missings, described before, (MCAR and MAR) our missing could be a combination of them. Consequently, among the different imputation methods that can be applied we decided to use KNN imputation because it is more efficient in terms of computational time and has reduced computing cost comparing to other more complex methods like MICE. It is true that using a more complex and powerful imputation method could improve the results in the way of having a more trustful dataset. However, for the moment, we decided that KNN imputation will be enough for this first attempt. Definitely, for a future work and new versions, invest more effort in the study and research of different imputation methods would be an improvement of the project. f. Dimensionality reduction and feature selection methods Now we have a dataset without any missing value, but still there are some things we have to take care before starting the analysis of the data. We still have a huge dataset in terms of variables (around 500) and the first thing we had to analyze was the content of those variables, what they were talking about and if some of them pointed out to the same information. To do this, we made a correlation analysis of the variables, as we expected the reduction of the data was very significant (there were a lot of variables representing the same information but in different terms, for example “Adjusted net national income (annual % growth)”, “Adjusted net national income (constant 2010 US$)” and “Adjusted net national income (current US$)”. Thus, it was not difficult to reduce a lot the number of variables with correlation analysis. In fact, the reduction was around ten times the number of variables, remaining by this way around 50 variables. We decided to remove those variables with more than 80% of correlation. Here it happens something similar with missing analysis and it is that there is no standard or procedure to decide which percentage of correlation is suitable and enough to decide to remove these variables. Therefore, we assumed that if we had for example two different variables with at least 80% of correlation is enough to decide to just take one of them and remove the other one. The decision of which of them will be remove is totally at random since it does not matter to us which of them remains, the information kept will be the same. g. Sub-setting by sectors After correlation analysis, the following part of our process is sub-set the data by the aforementioned different sectors. We will work with many sub-datasets as sectors we have. The size of each dataset will be the number of variables related to that sector times the number of observations that we already had (number of years for each country).
17 h. Second step of dimensionality reduction: PCA vs Autoencoders At this point, we have one data set for each sector. Now it is time to describe the two different solutions that we have worked with to accomplish the task of compressing all the variables of each sector into one, trying always to keep as much information as we are capable. Firstly, we used Principal Component Analysis. As we mentioned before, PCA is one of the best linear techniques for dimension reduction. PCA performs dimension reduction by projecting the original n-dimensional data onto the m < n dimensional linear subspace. Thus, PCA builds a global linear model of the data (an m-dimensional hyperplane) and the representation of the whole dataset is more accurate as closer is the value of m to n. Our following approach is to use a neural network as an encoder of information. As we explained before, an autoencoder is an unsupervised artificial neural network that learns how to efficiently compress and encode data then learns how to reconstruct the data back from the reduced encoded representation to a representation that is as close to the original input as possible. Autoencoder, by design, reduces data dimensions by learning how to ignore the noise in the data. Therefore, we encoded all the remaining variables for each sector with PCA and with an autoencoder. In Figure 9 we present the comparison of the error (the task of validation was done by reconstructing the original dataset with both methodologies, for PCA using one dimension and with Autoencoder using one neuron in the middle layer) of the reconstructions for one study case (country Spain) for each sector with PCA and with an autoencoder. As we expected, PCA does not behave so well when we reduce to one the dimensions used for reconstruction. That is why we wanted to find another solution and as it can be clearly observed the results with an autoencoder are much better. 0,00 0,10 0,20 0,30 0,40 0,50 0,60 0,70 0,80 ARD AEF CLC EAG EDC EAM ENV EXD FNS GND HLT INF PVR PRS PUS MSE Comparision PCA AUTOENCODER Figure 9. Comparison of the reconstruction error for PCA and Autoencoder measured with Mean Squared Error.
18 Therefore, even if the autoencoder is much more complex and less efficient in terms of computational cost, we will end up choosing this last option in order to have a better representation of the data. i. Bayesian networks Heretofore, we have one sub-datset for each sector reduced to one variable as the output of the autoencoder. To briefly summarize, our dataset up to this point is composed by one variable describing and representing each sector and each observation is the data for each of the aforementioned years. Now, we are ready to build the Bayesian network. As we explained before, Bayesian networks (BNs) are a type of graphical model that encode the conditional probability between different learning variables in a directed acyclic graph. But before, building it there are some things to take into account regarding mainly to the distribution of the input data of the Bayesian Network. Before build a Bayesian Network, it is interesting to check if the data is normally distributed and if the dependencies among the variables are linear. So now the questions that arises are: Is our input data normally distributed? Let us analyze some of the variables’ distribution for one example country (Spain). Figures 10 to 13 contain the histograms and QQplots for the variables “Climate Change” and “Economy & Growth” taken for this example. In the Table 1 it is shown the p-value obtained from the Shapiro-Wilk normality test for those variables. Figure 10. Histogram for country Spain and the variable Climate Change Figure 11. QQPlot for country Spain and the variable Climate Change Figure 12. Histogram for country Spain and the variable Economy & Growth. Figure 13. QQPlot for country Spain and the variable Economy & Growth.
19 These are just some samples of the global dataset, but the behavior for the rest of the countries and variables is the same, which is that the data does not follow a normal distribution. Are the dependencies among the variables linear? For this task we performed an analysis based on a Scatter Plot between some of the variables. Following the previous example, the Figures 14 and 15 illustrates the Scatter Plots among 2 different pairs of variables for the example case Spain. Therefore, we can as well as before, observe that the dependencies between variables are not linear. What to do now? The solution that we accomplished was to discretize the data and to model the resulting dataset with a Discrete Bayesian Network (DBN), which can accommodate skewness and nonlinear relationships at the cost of potentially losing the ordering information. When discretizing data, one variable to be chosen is the amount of levels and there is not an easy or standard way to do this. We decided to use 3 levels representing concentration levels of the different variables (low, average and high concentrations). We used the Hartemink’s Information-Preserving Discretisation method for discretization[19]. Now we are ready to develop the DBN. We used a scored-based algorithm, where each candidate DAG is assigned a score reflecting its goodness of fit, which is then taken as Country Variable P-Value ESP Climate Change 0,0000382 ESP Economy & Growth 0,00463 Table 1. Results from Shapiro-Wilk normality test. Figure 14. Scatter Plot for country Spain and the variables Climate change and Economy & Growth. Figure 15. Scatter Plot for country Spain and the variables Financial Sector and Economy & Growth.
20 an objective function to maximize. The algorithm used is a hill climbing greedy search that explores the space of the directed acyclic graphs by single-arc addition, removal and reversals, with random restarts to avoid local optima. It is important to mention that in order to be more robust, instead of just applying one time the mentioned algorithm, we decided to use a bootstrap solution. The used method estimates the strength of each arc as its empirical frequency over a set of networks learned from bootstrap samples. It computes the probability of each arc (modulo its direction) and the probabilities of each arc’s directions conditional on the arc being present in the graph (in either direction). This is how we get a Bayesian Network for each country in our dataset. In the Figures 16 to 19 we show some examples of the Bayesian Networks that we got from this experiment. Figure 16. Bayesian Network representation of the country Spain. Figure 17. Bayesian Network representation of the country United Arab Emirates. Figure 18. Bayesian Network representation of the country India. Figure 19. Bayesian Network representation of the country Iran.
21 j. Clustering Up to this point, we have generated one Bayesian Network for each country of our dataset, which is a graphical description of the causal relationships between the sectors or indicators of the country. The following step that we wanted to carry out was an attempt to group in several clusters those countries with similar causal relationships among their variables, which is those countries with similar Bayesian Networks. The goal is to find n clusters of countries in the world that allow us to describe the n different systems that we can find in the different societies or populations around the world and try to give in this way a global picture of the world’s most important architectures of functioning and socio-economic relationships for the different countries aggrupation. To do this we first deploy an algorithm to represent a single Bayesian Network with a binary vector of factors. We first create a matrix where the rows and columns are the different sectors. Then the algorithm runs row by row and sets a value of ‘1’ in each column if the selected pair row sector – column sector has a relationship father – child. This will give as a result a matrix as the one described in the Figure 20. Figure 20, represents the relationships matrix for the country Spain. For each row we will find a value of ‘1’ in those columns that belong to a sector that is a child in the BN of the sector related to the selected row. As consequence of that, if we look at one sector column, we will find a value of ‘1’ in those rows that are parents in the BN of it. For example, the sector Energy & Mining (EAM) have the following relationships: AEF ARD CLC EAG EAM EDC ENV EXD FNS GND HLT INF PRS PUS PVR SAT SCD SPL TRD URD AEF 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ARD 0 0 1 1 1 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0 CLC 0 0 0 1 0 0 0 0 0 0 0 1 1 1 0 1 0 0 1 0 EAG 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 EAM 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 EDC 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 ENV 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 EXD 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 FNS 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 GND 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 1 HLT 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 INF 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 PRS 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 PUS 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 PVR 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SAT 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 SCD 0 0 0 1 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 SPL 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 TRD 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 URD 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 Figure 20. Adjacency matrix for country Spain. For each row it has a value of ‘1’ in those columns that belongs to a sector which is a child in the Bayesian Network of the sector related to the selected row.
22 a) Childs: Economy & Growth (EAG), Environment (ENV), Health (HLT) and Urban Development (URD). b) Parents: Agriculture & Rural Development (ARD), Education (EDC) and Social Development (SDC). Once we have each country Bayesian Network represented in one relationship matrix, what we did was to convert them into vectors and generate a dataset where each observation (row) is the mentioned vector. This dataset is shown in the Figure 21. Therefore, now we have a dataset with all the representations of the Bayesian Networks of each country. This way, we can now clusterize this data. We want to point out that our data now is categorical and not numerical. On the contrary than clustering using numerical variables where the documentation and methods developed are abundant, it took us some time to find solutions for categorical data. It is due to the fact that categorical data clustering is less straightforward than numerical clustering and the methods for this task are still being developed. Our clustering process include the following steps: a) Calculating distance or dissimilarity matrix. b) Choosing the clustering method. c) Assessing clusters. The first step is to calculate the dissimilarity matrix, which is a mathematical expression of how different, or distant, the points in a data set are from each other, so we can later group the closest ones together or separate the furthest ones. As for numerical data we have algorithms like Euclidean distance, for categorical data the most used one is the Gower distance. V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 AUS 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 BRA 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 CAN 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 CHN 0 1 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 DEU 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ESP 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 FRA 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 GBR 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● URY 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 YEM 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Figure 21. Relationships matrix generated by appending the relationships vectors of each country.
23 To calculate the Gower distance we used the function daisy from R. Let us copy a fragment from R documentation to try to understand how the Gower distance works: Compared to dist whose input must be numeric variables, the main feature of daisy is its ability to handle other variable types as well (e.g. nominal, ordinal, (a)symmetric binary) even when different types occur in the same data set. The handling of nominal, ordinal, and (a)symmetric binary data is achieved by using the general dissimilarity coefficient of Gower (1971). If 𝑥 contains any columns of these datatypes, both arguments metric and stand will be ignored and Gower's coefficient will be used as the metric. This can also be activated for purely numeric data by metric = "gower". With that, each variable (column) is first standardized by dividing each entry by the range of the corresponding variable, after subtracting the minimum value; consequently the rescaled variable has range [0,1], exactly. In the daisy algorithm, missing values in a row of 𝑥 are not included in the dissimilarities involving that row. There are two main cases, 1. If all variables are interval scaled (and metric is not "gower"), the metric is "euclidean", and 𝑛𝑔 is the number of columns in which neither row 𝑖 and 𝑗 have NAs, then the dissimilarity 𝑑(𝑖,𝑗) returned is √𝑝/𝑛𝑔 (𝑝=𝑛𝑐𝑜𝑙(𝑥)) times the Euclidean distance between the two vectors of length 𝑛𝑔 shortened to exclude NAs. The rule is similar for the "manhattan" metric, except that the coefficient is 𝑝/𝑛𝑔. If 𝑛𝑔= 0, the dissimilarity is NA. 2. When some variables have a type other than interval scaled, or if metric = "gower" is specified, the dissimilarity between two rows is the weighted mean of the contributions of each variable. Specifically, 𝑑𝑖𝑗 =𝑑(𝑖,𝑗)= ∑𝑤𝑘𝛿𝑖𝑗 𝑘𝑑𝑖𝑗 𝑘 𝑝 𝑘=1 ∑𝑤𝑘𝛿𝑖𝑗 𝑘 𝑝 𝑘=1 In other words, 𝑑𝑖𝑗 is a weighted mean of 𝑑𝑖𝑗 𝑘 with weights 𝑤𝑘𝛿𝑖𝑗 𝑘, where 𝑤𝑘= 𝑤𝑒𝑖𝑔𝑡ℎ𝑠[𝑘], 𝛿𝑖𝑗 𝑘 is 0 or 1, and 𝑑𝑖𝑗 𝑘, the k-th variable contribution to the total distance, is a distance between 𝑥[𝑖,𝑘] and 𝑥[𝑗,𝑘], see below. The 0-1 weight 𝛿𝑖𝑗 𝑘 becomes zero when the variable 𝑥[,𝑘] is missing in either or both rows (i and j), or when the variable is asymmetric binary and both values are zero. In all other situations it is 1. The contribution 𝑑𝑖𝑗 𝑘 of a nominal or binary variable to the total dissimilarity is 0 if both values are equal, 1 otherwise. The contribution of other variables is the absolute difference of both values, divided by the total range of that variable. Note that “standard scoring” is applied to ordinal variables, i.e., they are replaced by their integer codes 1:K. Note that this is not the same as using their ranks (since there typically are ties). As the individual contributions 𝑑𝑖𝑗 𝑘 are in [0,1], the dissimilarity 𝑑𝑖𝑗 will remain in this range. If all weights 𝑤𝑘𝛿𝑖𝑗 𝑘 are zero, the dissimilarity is set to NA.
24 Thus, after calculating the Gower distance on our dataset we got the distance matrix showed in the Figure 22. Then, we go to the second step, choosing the clustering algorithm. We tried the two different methods from hierarchical clustering, agglomerative (bottom-up) and divisive (top-down). Agglomerative clustering will start with n clusters, where n is the number of observations, assuming that each of them is its own separate cluster. Then the algorithm will try to find most similar data points and group them, so they start forming clusters. In contrast, divisive clustering will go the other way around, assuming all your n data points are one big cluster and dividing most dissimilar ones into separate groups. To be honest, we made various trials with both algorithms and with different number of clusters and the results were very similar (we compare the results by calculating the correlation among the resulting dendograms), indeed, we could not say precisely that one of them was better or worse than the other one. We decided to carry out with the agglomerative (bottom-up) alternative (an illustration of the result is shown in the Figure 23). AUS BRA CAN CHN DEU ESP FRA GBR IDN IND IRN ITA ● ● SAU AUS 0 0,1275 0,13 0,1375 0,1275 0,1425 0,1525 0,155 0,13 0,125 0,14 0,15 ● ● 0,1275 BRA 0,1275 0 0,1425 0,14 0,125 0,15 0,13 0,1525 0,1125 0,0975 0,1275 0,1475 ● ● 0,12 CAN 0,13 0,1425 0 0,1425 0,1325 0,1475 0,1675 0,145 0,14 0,125 0,14 0,165 ● ● 0,1275 CHN 0,1375 0,14 0,1425 0 0,155 0,16 0,175 0,1625 0,1325 0,1175 0,1375 0,1675 ● ● 0,13 DEU 0,1275 0,125 0,1325 0,155 0 0,14 0,12 0,1575 0,1325 0,0975 0,1375 0,1475 ● ● 0,125 ESP 0,1425 0,15 0,1475 0,16 0,14 0 0,165 0,1725 0,1625 0,1325 0,1675 0,1475 ● ● 0,135 FRA 0,1525 0,13 0,1675 0,175 0,12 0,165 0 0,1825 0,1475 0,1375 0,1475 0,1675 ● ● 0,145 GBR 0,155 0,1525 0,145 0,1625 0,1575 0,1725 0,1825 0 0,155 0,145 0,165 0,155 ● ● 0,1325 IDN 0,13 0,1125 0,14 0,1325 0,1325 0,1625 0,1475 0,155 0 0,11 0,125 0,15 ● ● 0,1175 IND 0,125 0,0975 0,125 0,1175 0,0975 0,1325 0,1375 0,145 0,11 0 0,1 0,14 ● ● 0,0925 IRN 0,14 0,1275 0,14 0,1375 0,1375 0,1675 0,1475 0,165 0,125 0,1 0 0,165 ● ● 0,1225 ITA 0,15 0,1475 0,165 0,1675 0,1475 0,1475 0,1675 0,155 0,15 0,14 0,165 0 ● ● 0,1425 JPN 0,15 0,1475 0,165 0,1725 0,1525 0,1725 0,1625 0,185 0,16 0,15 0,165 0,175 ● ● 0,1575 KOR 0,15 0,1225 0,14 0,1375 0,1175 0,1625 0,1225 0,15 0,13 0,11 0,12 0,165 ● ● 0,1175 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 0,12 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 0,0775 SAU 0,1275 0,12 0,1275 0,13 0,125 0,135 0,145 0,1325 0,1175 0,0925 0,1225 0,1425 0,1575 0,1175 0,1 Figure 22. Dissimilarity matrix resulting from the calculation of the Gower distance over the relationship matrix.
31 These are the Bayesian Networks that describe the causal relationships of our defined 5 different clusters. Give a precise description of them is not an easy job, in fact, this kind of network is subjected to many different interpretations. Anyway, consecutively we are going to try to make a global interpretation of the final picture that we have shown before. In general terms, we can observe that in all cases there are some different kind of nodes: a) Those with many children and few or any parents, usually placed at the top of the graph (we will call them grand-father). b) Those with many parents anf few or any child, usually placed at the bottom of the graph (we will call them grand-child). c) Those with similar number of parents and children (we will call them standardnodes). Thus, we see some things that all the clusters have in common. For example, in all the cases the indicator “Agriculture & Rural Development” (ARD) is always a grand-father, this could have an easy interpretation and it is that the impact of the agriculture and the rural development along the last 60 years has been crucial for our countries and society. Not leaving the analysis of grand-fathers, we can observe that in the Cluster 1 the indicator “Trade” (TRD) which has variables related to trading operations (like imports and exports of services, technology or weapons) is also playing an important role as grand-father meaning that many of the rest of the sectors have a causal dependence with it. This could be interpreted as that the countries of the Cluster 1 have a huge dependence on their trading (imports and exports) activity. If we have a look at the indicator “Climate Change” (CLC) in the Clusters 1, 3 and 5 we can observe that it is also a grand-father in those cases. This could mean that for the countries of these Clusters the climate change is a very relevant indicator. Indeed, one interesting relationship is the one with the sector “Economy & Growth”, which means that economical and developing factors (like the total income of a country, the savings, the GNI or GDP for example) have a direct causal dependence with the climate change (composed by many different variables like CO2 emissions, droughts, floods, extreme temperatures or amount of oil as energy source used). Another interesting analysis is the position of the sector “Energy & Mining” (EAM) in the Cluster 5. Here, it has also a role of grand-father, and having a look at its children sectors we could interpret this as that the energy and mining activity have a huge influence or impact over the economy, society, private sector, health system and the infrastructures of those countries. We can also observe that the indicators “Public Sector” (PUS) and “Private Sector” (PRS) are, in most of the cases, at the bottom of the network. Are two of the described grand-children. This could be interpreted as that the public and private sector (which are composed by variables like Cost of business start-up procedures, Time required to build a warehouse, Investment in transport with private participation [PRS] or Central government debt, Goods and services expense or Tax revenue and payments [PUS]) have an important dependence of all the rest of the things that are happening in a country (like the economy of the country, the finance state or the external debt).
32 These are some examples of possible analysis and interpretations of the obtained Bayesian Networks but as we mentioned before, it is not a closed analysis, on the contrary, it is opened to different interpretations. 5. Conclusions After all this months of work (almost one year) the main conclusion that we have reached is that this project has complete a real data science challenge. First, we had an idea (Develop a data analysis of socio-economic and financial factors of different countries in the world) then we started gathering data from a real database with all the kind of issues that a real database brings with itself. Subsequently, there was a long travel of data analysis, facing problems, trying to find solutions, evaluate the different possibilities and making decisions. Throughout this project, we have faced many different problems and all of them had different possible solutions or sometimes there even was not a solution itself. This was the real challenge, to make decisions. We had to take the decisions of how to deal with the different problems that we were finding in our way (missing values, high dimensionality, the dataset itself, and others) and we knew that these decisions could have an important impact in the final results. This is way we had to be very cautious and validate and challenge ourselves in every step that we decided to make. Regarding to our results and taking the previous analysis into account, we can say that we have achieved our initial goal. The final outcome that we got is a reliable representation of the functioning of our world and each single country in particular. Also, we have succeeded in the task of giving as well a global vision of the dependencies between the different indicators that describe a country through a description of the causal relationships among them. Besides, we have additionally complete a clustering task with which we are able to group the analyzed countries in different sets according to the causal relationships among their indicators which can be interpreted as the socio-economic systems of these populations.
33 6. References [1] World Bank. "World Bank Open Data" World Development Indicators, The World Bank Group, https://data.worldbank.org. [2] Lorraine Li, “Principal Component Analysis for Dimensionality Reduction”, Towards Data Science, May 24 - 2019, https://towardsdatascience.com/principal-component- analysis-for-dimensionality-reduction-115a3d157bad [3] Nathan Hubens, “Deep inside: Autoencoders”, Towards Data Science, Feb 25 - 2018, https://towardsdatascience.com/deep-inside-autoencoders-7e41f319999f [4] Will Badr, “Auto-Encoder: What Is It? And What Is It Used For? (Part 1)”, Towards Data Science, Apr 22 - 2019, https://towardsdatascience.com/auto-encoder-what-is-it-and- what-is-it-used-for-part-1-3e5c6f017726 [5] Wale Akinfaderin, “Missing Data Conundrum: Exploration and Imputation Techniques”, IBM Watson Data, Sep 11 - 2017, https://medium.com/ibm-data-science- experience/missing-data-conundrum-exploration-and-imputation-techniques- 9f40abe0fd87 [6] Ben‐Gal, I. (2008). Bayesian Networks. In Encyclopedia of Statistics in Quality and Reliability (eds F. Ruggeri, R.S. Kenett and F.W. Faltin). doi:10.1002/9780470061572.eqr089 [7] Gámez, José & Mateo, Juan & Puerta, Jose. (2011). Learning Bayesian networks by hill climbing: Efficient methods based on progressive restriction of the neighborhood. Data Mining and Knowledge Discovery. 22. 106-148. 10.1007/s10618-010-0178-6. [8] Hamed, “Bayesian network in R: Introduction”, R-Bloggers, Feb 15 - 2015, https://www.r-bloggers.com/bayesian-network-in-r-introduction/ [9] Marco Scutari, “Understanding Bayesian Networks”, Department of Statistics, University of Oxford, Jan 23 - 2017, https://www.bnlearn.com/about/teaching/slidesbnshort.pdf [10] Marco Scutari (2010). Learning Bayesian Networks with the bnlearn R Package. Journal of Statistical Software, 35(3), 1-22. http://www.jstatsoft.org/v35/i03/. [11] Valentina Alto, “Unsupervised Learning: K-means vs Hierarchical Clustering”, Towards Data Science, Jul 08 - 2019, https://towardsdatascience.com/unsupervised-learning-k- means-vs-hierarchical-clustering-5fe2da7c9554 [12] Anastasia Reusova, “Hierarchical Clustering on Categorical Data in R”, Towards Data Science, Apr 01 - 2018, https://towardsdatascience.com/hierarchical-clustering-on- categorical-data-in-r-a27e578f2995 [13] KAMBHATLA, Nandakishore; LEEN, Todd K. Dimension reduction by local principal component analysis. Neural computation, 1997, vol. 9, no 7, p. 1493-1516. [14] JENSEN, Finn V., et al. An introduction to Bayesian networks. London: UCL press, 1996. [15] PEARL, Judea. Bayesian networks. 2011.
34 [16] SAKURADA, Mayu; YAIRI, Takehisa. Anomaly detection using autoencoders with nonlinear dimensionality reduction. En Proceedings of the MLSDA 2014 2nd Workshop on Machine Learning for Sensory Data Analysis. ACM, 2014. p. 4. [17] WANG, Yasi; YAO, Hongxun; ZHAO, Sicheng. Auto-encoder based dimensionality reduction. Neurocomputing, 2016, vol. 184, p. 232-242. [18] R Core Team (2011). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria. ISBN 3-900051-07-0, URL http: //www.R-project.org/. [19] A. J. Hartemink. Principled Computational Methods for the Validation and Discovery of Genetic Regulatory Networks. PhD thesis, School of Electrical Engineering and Computer Science, Massachusetts Institute of Technology, 2001.