key: cord-0291057-6l0ltiu8 authors: Batarseh, Feras A.; Gopinath, Munisamy; Monken, Anderson; Gu, Zhengrong title: Public Policymaking for International Agricultural Trade using Association Rules and Ensemble Machine Learning date: 2021-11-15 journal: nan DOI: 10.1016/j.mlwa.2021.100046 sha: 7ebf09a9a70e4435109485c03cf69caccbf669ce doc_id: 291057 cord_uid: 6l0ltiu8 International economics has a long history of improving our understanding of factors causing trade, and the consequences of free flow of goods and services across countries. The recent shocks to the free trade regime, especially trade disputes among major economies, as well as black swan events, such as trade wars and pandemics, raise the need for improved predictions to inform policy decisions. AI methods are allowing economists to solve such prediction problems in new ways. In this manuscript, we present novel methods that predict and associate food and agricultural commodities traded internationally. Association Rules (AR) analysis has been deployed successfully for economic scenarios at the consumer or store level, such as for market basket analysis. In our work however, we present analysis of imports and exports associations and their effects on commodity trade flows. Moreover, Ensemble Machine Learning methods are developed to provide improved agricultural trade predictions, outlier events' implications, and quantitative pointers to policy makers. In recent years, many countries are concerned about rising trade deficits (value of exports less imports) and their implications on production, consumption, prices, employment, and wages. For instance, the United States' goods and services trade deficit with China was $345.6 billion in 2019 (USTR, 2020). Such large gaps are forcing countries to either exit trade agreements or enforce tariffs, (e.g. Brexit, U.S. tariffs on Chinese goods, and other de-globalization movements). Other outlier events could lead to additional uncertainties in global production chains and irregularities in trade of essential goods (e.g. soybeans, steel, aluminum, and beef). While traditional economic models aim to be reliable predictors, we consider the possibility that AI methods (such as AR and EML) allow for better predictions to inform policy decisions. The 2020 U.S. National Artificial Intelligence Initiative Bill states: "Artificial intelligence is a tool that has the potential to change and possibly transform every sector of the United States economy" (S.1558 -AIIA, 2020). As AI methods are applied across different domains, they are often presented with a stigma of being irrelevant or a "black-box". Few studies have applied AI to economics; accordingly, some have called for increased attention to the role of AI tools (Mullainathan and Spiess, 2017) . A study by the National Bureau of Economic Research (NBER) points to the potential of economists adopting ML more than any other empirical strategy (Athey and Imbens, 2017) . While some success stories are recorded for deploying ML to international trade analysis, we present methods that elevate predictions' accuracy through EML, and evidence-based policy making through AR. Open-government data provide the fuel to power the mentioned methods. Unlike traditional approaches, e.g. expert-judgment based linear models or time-series methods, EML and AR methods provide a range of data-driven and interpretable projections. Prior studies indicate the high relevance of AI methods for predicting a range of economic relationships with a greater accuracy than traditional approaches (Athey and Agrawal, 2009 ). With recent international trade policies garnering attention for limiting cross-border exchange of essential goods and with trade's critical effects on production, prices, employment, and wages (ERS, 2020), our motivation in this study is to test the following two-tier hypothesis: (2) provides a review of traditional econometrics and presents the state of the art in applying AI methods to trade analysis. Section 3 introduces the methods (EML and AR) as they are applied to trade data; and section 4 presents all experimental results. Section 5 incorporates methods for validation, anomaly detection, outlier events and their manifestations on predictions. Section 5 also shows two use cases for policy making as well as other ideas for future work. Discussions, trade policy implications, and conclusions are presented in section 6. The success of AR for online and brick and mortar commerce is undeniable. Amazon's "people who bought this item are also interested in…" is a recommendation engine that tells us what items have been bought together. Many other success stories exist: the famous beer and diapers association at grocery stores, Netflix's movie recommendations, Walmart's placing of bananas next to cereal boxes, and Target's predictions of pregnancy based on buying trends (MapR, 2020). Those commercial algorithms that use AR are referred to as MBA. In our work, we ask the question, can MBA through AR be applied to international trade? Can we look into trade of commodities between countries and build associations that could manifest trade associations such as: "when the U.S. exports more Cereal to Mexico, Mexico will import less or no livestock and other animal products". We look at trade flows and aim to illustrate how the waves of trade are influenced by an increase or decrease of commodity's flow between countries. EML are meta-algorithms that combine several Machine Learning (ML) techniques into one model to decrease bias (such as through boosting) (Ke et al., 2017) , and improve predictions (through using multiple methods). In this paper, we develop methods for trade predictions using boosting and k-means clustering. K-means clustering is a commonplace method for grouping items using non-conventional means. We cluster the countries of the world, and use the highest quality outputs of the k-means model to execute tailored predictions through boosting algorithms. Boosting is a class of ML methods based on the idea that a combination of simple classifiers (obtained by a weak learner) can perform better than any of the simple classifiers alone. Additionally, boosting is used to classify economic variables, and measure their influence on trade projections. A ranking of variables is presented per commodity to aid in understanding relationships between variables (for instance: GDP, Distance, and Population), and their effect on trade during conventional (white swan) and outlier (black swan) events. Econometrics (and model calibration, and other empirical methods used by economists) aim to elucidate mechanisms and identify causalities, whereas AI aims to find patterns in the data. The challenge with the latter for any kind of forward-looking or policy analysis is the famous "Lucas Critique". Lucas (1976) argued that the economic parameters of traditional econometric models depended implicitly on expectations of the policy making process, and that they are unlikely to remain constant as events change and policymakers alter their behavior. In section 5, we present methods (for outlier detection and model's retraining) that aid policy makers in such situations, and allow them to amend their policies. Section 2.1 presents an overview of AI methods applied to trade; and section 2.2 outlines traditional econometrics, and contrasts both paradigms. Few studies have applied ML methods to economics. Storm (2016) expanded the scope, and developed a model for growth in GDP including its major components: agriculture, manufacturing, industry, and services. See also Kordanuli et al. (2016) for an application of neural networks for GDP predictions. Falat et al. (2015) developed a set of ML models for describing economic patterns, but did not offer predictions. In a recent study, presented boosting ML methods for trade predictions. In their study, many economic features were considered to identify which of them have the highest influence on trade predictions, and which ones could be controlled and tuned to change the forecasts. Different commodities had different rankings of economic variables, however population and GDP of both countries and tariffs had some of the highest impact on whether two countries would trade major commodities or not. AI methods are categorized into 3 areas: ML (including supervised and unsupervised), Deep Learning (DL), as well as Reinforcement Learning (RL). Table 1 presents a brief and relevant history of ML/DL/RL applications to international trade analysis. No method is found in literature that applied AR to country-commodity exports and imports (Serrano et al., 2015) , and EML has not been extensively tested for international trade. The work presented in this paper addresses that gap. A key objective of quantitative economic analyses is to uncover relationshipse.g. demand, supply, prices or tradefor use in making predictions or forecasts of future outcomes. However, when the current systems generates forecasts for decision making, they require a range of ad hoc, expert-driven or a combination of simple forecasting models supplemented by subject matter expertise to econometrics-based methods and mega-models, i.e. applied general equilibrium. Employing such approaches, many international institutions and government agencies project The sets of commodities Xa is called antecedents (left-hand-side or LHS) and the set of commodities Xb is called consequents (right-hand-side or RHS) of the rule. Besides antecedent-consequent rules, the quality of the associations is measured through the following three metrics: Support indicates that for example 67% of customers purchased beer and diapers together. Confidence is that 90% of the customers who bought beer also bought diapers (confidence is the best indicator of AR). While lift represents the 28% increase in expectation that someone will buy diapers, when we know that they bought beer (i.e. lift is the conditional probability). In our study, AR mining is performed using the arules library in R. Data Silhouette coefficient = max s(k). Where s(k) represents the mean s(i) over all data points in the trade dataset for a specific number of clusters k. The k-means model is developed for k=2 to k=20, "powerful" country clusters are then used to create better trade predictions/boosting. We aim to find the most appropriate Sum of Square Errors (SSE). For each k, a score is computed for SSE via the formula: SSE tends to decrease towards zero as k increases and so SSE is equal to 0 when k is equal to the number of data points in the trade dataset. Therefore, the goal is to choose a small value of k that has a low SSE. The result for all rows (n) and columns (t) is evaluated using an elbow diagram that indicates the most appropriate number of clusters. After clustering is performed, predictions are evaluated within the context of the clusters. Moreover, a "flag" validation and anomaly detection engine is deployed (with application to livestock) to allocate outliers and inform commodity-specific policy making; outcomes are collected and presented. All data, code, and scripts for the experiment are available on GitHub (refer to the data availability statement). The models' results are illustrated through a R-Shiny dashboard, Tableau dashboard, other text tables, and R plots. After the data are wrangled, few descriptive dashboards are developed, for instance, a heat map showing the history of trade is illustrated in Figure 1a . The rise of China is obvious in the figure, as well as how big traders seem to dominate international trade. Figure 1b The Tableau dashboards presented in this manuscript are shared on Tableau public (a public online repository) and available for anyone for further exploration. Certain countries trade more with each other due to treaties, distance, GDP, and other economic variables. Results from the associations (selected top confidence sums), for all countries are presented in Table 2 (showing agricultural and non-agricultural associations). An extended version of the table, with top 100 rules is added to Appendix 1. Table 3 presents the top multiple antecedent rules by HS code, along with their confidence, support, and lift. Figure 2 is another part of the Tableau dashboard that shows the top trade countries, and allows the user to browse for associations of commodity-country pairs. Every "dot" is a rule, and the graph consists of the resulted 4 million+ rules. In the figure, the rule: (Carpets → Starches and Glues for USA → China) is selected. Figure 3 illustrates the top rules' and their affinity towards low support and high confidence. Figure 5 shows the R-Shinny app that is developed to present the 6-clusters model (as well as the associations and correlations), and how countries relate to each other in it. The 6-clusters model illustrates the countries in cluster 1 are the biggest players (USA, Japan, China, EU…etc). That result is then used to predict the future of trade for year 2020 and beyond. For example, results for trade predictions through the XGBoost Model scored predictions' quality = 69%, and through LightGBM scored a quality of 88% (in contrast, GBoost scored the lowest of the three approaches). Data from cluster 1 countries are used to train the models, but scoring is applied to all countries. Parameter tuning for boosting models include: Number of leaves, Maximum Depth of the tree, Learning Rate, and Feature fraction. Small learning rates are optimal (0.01), with large tree depths. Additionally, to speed up training and avoid over-fitting, feature fraction is set to 0.6; that is, selecting 60% of the features before training each tree. Early stopping round is set to 500; that allowed the model to train until the validation score stops improving. Maximum tree depth is set to 8. Those settings led to the best output through LightGBM. Sugar for instance had an R 2 score (prediction quality) of 0.73, 0.88 for Beef, and 0.66 for Corn (three essential commodities). These initial results confirm the applicability of EML methods to projecting trade patterns and also point to accuracy gains over traditional approaches. However, after using only countries from cluster 1: the models yielded even better results. Figure 6 illustrates the boosting models quality (actual vs. predicted) before deployment of k-means outputs (i.e. using cluster 1), and after (i.e. with and without EML). improves to 92% only after having actual data for three-quarters of the forecasted year. Models presented in this paper offer forecast accuracy in the 69% -88% range (even before data for three quarters are available). Albeit models presented offer higher accuracy, but what happens when those data patterns are majorly disrupted by an outlier event such as trade wars, embargoes, or pandemics? How are economic variables such as tariffs, production, and prices influencing policy during black swan events? The next section presents methods to evaluate such shifts in trade patterns and use AI methods to provide pointers to policy alternatives. During the Covid-19 pandemic, the International Monetary Fund (IMF) updated their forecasts for the global economy. The IMF warned of soaring debt levels, as well as country's economies contracting (8% contraction for the US, 9.1% for Brazil, as well as 10.5% for Mexico). Moreover, the IMF estimates an overall contraction of 4.9% in global GDP in 2020 (IMF, 2020). Isolation forests, distance-based, and density-based approaches can be generally used for outlier detection within a learning environment, however, for explainability and clarity purposes, in our presented boosting models, we present commodity-specific variable correlations to support policy making during outlier events. For example, some commodities infer that the GDP of the importer is the main influencer (via classification measures) of the size of trade between both countries. Other commodities exchange depends on distance or population and so on. Hence, by looking at commodity-specific changes (within different contexts), implications on policies that shape production, pricing, or consumption of that commodity could be altered in a more acute manner. The "Big Four" meat packers account for more than 70% of beef processing in the U.S. (Dorsett, 2020 While all industries have been seriously affected by the Covid-19 pandemic, food and agriculture have been among the hardest hit segments of the U.S. economy. The primary reason lies in the composition of household food expenditures. The impacts of the pandemic appear to vary by commodity based on two critical issues: perishability and labor use. Perishables like milk are among the hardest hit. Specialty crops such as corn also depend on labor for growing and harvesting -both types of commodities are affected during outlier events. Figure 8 illustrates feature importance (using classification tree splits) for milk trade and compares that to corn. We consider commodity-specific distress during outlier events, for instance, on the biggest milk exporters: New Zealand, Germany and the U.S. If we know that GDP rates (as the IMF data showed) have sunk for those countries, and also, production is reduced due to closures and shutdowns; while other variables such as language, distance, and trade agreements stay the same, we are able to retrain the model with updated values and produce new real-time predictions that are suitable for the context at hand. Not all economic variables are influential during a pandemic, while other are more important to consider during conventional times (such as distance) and during policy making (such as tariffs and production). In our boosting models, we considered the following economic variables Year (all used in Figure 8 ). By using AI methods, issues such as endogeneity are marginalized. Most traditional methods for high-dimensional statistics are based on the assumption that none of the regressors are correlated with the regression error (i.e. they are exogenous). Yet, endogeneity can arise incidentally from a large pool of regressors in cases of a high-dimensional regression. This leads to the inconsistency of the penalized least-squares method, and to possible false outcomes and sub-optimal policies. Our methods are not affected by this notion. However, in the next section, we present methods for validation of trade data (including anomaly detection), as well as other potential methods such as RL and causal learning that we aim to explore as part of future work. In the system developed, a validation and outlier detection module is deployed. The Validation engine presented in this section is based on work from . The engine consists of two parts: flag validation, and anomaly (i.e. outlier) detection. We worked with USDA analysts to define the "acceptable" ranges for numbers within a sector, for example, if production of milk exceeds a certain amount, then our system should raise a "flag". For instance, for yearly values, a red flag means that the number is not within the accepted historical range, and it requires attention. Red flags are expected to be prominent during black swan events for example. An orange flag means the number is within the range but not the last 10 years, yellow means the value is within the last 10 years' range, but not 5 years range, then blue indicates 5 years range, and green indicates 3 years. The flag system is applied to livestock, in use case #2. Another measure to identify outliers is using statistical methods: Median and Median Absolute Deviation Method (MAD). For this outlier detection method, the median of the residuals is calculated. Then, the difference is calculated between each historical value and this median. These differences are expressed as their absolute values, and a new median is calculated and multiplied by an empirically derived constant to yield the median absolute deviation (MAD). If a value is a certain number of MAD away from the median of the residuals, that value is classified as an outlier. The default threshold is 3 MAD. This method is generally more effective than the mean and standard deviation method for detecting outliers, but it can be too aggressive in classifying values that are not really extremely different. Also, if more than 50% of the data points have the same value, MAD is computed to be 0, so any value different from the residual median is classified as an outlier. MAD is calculated for univariate and multivariate outliers, using these two formulas; given a two dimensional paired set of data (X1, Y1), (X2, Y2) … (Xn, Use case #2 (the box below) is an example analysis of USDA's Economic Research Service (ERS) livestock data using validation and outliers (all code and data are available in a public Github repositoryrefer to the data availability section): Usecase#2: U.S. livestock trade are collected from the National Agricultural Statistics Service (NASS) and the United States Department of Commerce (Foreign Trade Division). The flag and the anomaly detection modules were executed. Table 5 illustrates example results from the flag system. Table 6 presents example outlier values per commodity for the same dataset. All results are presented in Appendix 3. Such results are presented to a federal analyst for decision making and policy analysis. Additionally, in our future work, we aim to deploy HS4 and HS6 AR analysis to influence production decisions at farm level, provide commodity-based tariff insights, and other potential pointers to economic policies. A digital platform with "bigger" data shall provide acute associations on commodities' trade. HS4 or HS6 ARs for example, can point to some interesting pairing of countries and commodities. HS4 and HS6 codes will produce many more AR rules, which require more computational power, something we anticipate to do in the future. Methods presented in this paper provide ways of evaluating and managing policy scenarios. For instance, as presented in use cases 1 and 2, production of certain commodities can be hindered or amplified due to shifts in markets, changes in consumption, or other issues such as shipping and prices. Classification splits and gains lead to understanding these variables effects. Additionally, for instance: the amount of food available is calculated as the difference between available commodity supplies and nonfood use (i.e. disappearance) (USDA ERS, 2020): Total annual food supply of a commodity = supply (production + imports + beginning stocks)disappearance (farm inputs + exports + ending stocks) (8) This (supply and use) allows analysts to produce reports that inform policy makers on commodities outlook, and so on policy decisions that influence variables per commodity. As presented in the two use cases and by using the presented EML and AR models, decision makers have better understanding of these variables, as they can predict them better, validate them and find outliers. Examples on policies across the world during outlier events include: a. Farm Credit banks will receive support from the federal government that will allow for an additional $5.2 billion in lending capacity to producers, agribusinesses, and food processors (IMF, 2020). a. New funds are available to assist producers under stress, mainly small-scale farmers operating in the poultry, livestock, and vegetables sectors (IMF, 2020). Policy on data sharing is critical to such studies. Encouraging government agencies to produce and share datasets on public repositories is essential for additional work in this context. In recent years, there has been a challenge to achieve consensus at international bodies such as myriad of studies. We can AI methods on data to allow for alternative and robust specifications of complex economic relationships and trade policies. FB defined the models, designed the experiments, developed the idea of the paper, presented the discussions and conclusions, and wrote the paper. GM provided economic insights, designed the policy story, aided with data collection, and critically reviewed the paper. AM developed the databases, wrote the scripts and code snippets, extracted results, and helped with technical writing. ZG helped with writing literature review, helped with paper's idea design, and reviewed the paper. All data, code, scripts, and dashboards used in this study are available in this public repository: https://github.com/ferasbatarseh/TradeAI No competing interests. Syn-thetic Control Methods for Comparative CaseStudies: Estimating the Effect of California's Tobacco Control Program The Economics of Artificial Intelligence: An Agenda Mining Association Rules between Sets of Items in Large Databases A latent variable model approach to work embeddings The impact of the 2018 trade war on US prices and welfare Determining the Number of Factors in Approximate Factor Models Machine Learning Methods for Demand Estimation The Coronavirus and the Great Influenza Pandemic: Lessons from the "Spanish Flu" for the Coronavirus's Potential Effects on Mortality and Economic Activity Federal Data Science: Transforming Government and Agricultural Policy Using Artificial Intelligence A comprehensive model for management and validation of federal big data analytical systems Context-driven data mining through bias removal and data incompleteness mitigation. 1st Workshop on Evaluation and Experimental Design in Data Mining and Machine Learning Application of Machine Learning in Forecasting International Trade Trends Understanding Context Before Using It, Lecture Notes in Computer Science The Economic Effects of Trade Policy Uncertainty The US-China Trade War: Technological Roots and WTO Responses DOJ subpoenas four largest meat packers Estimating China's Trade with Its Partner Countries within the Belt and Road Initiative Using Neural Network Analysis The Macroeconomics of Epidemics Quantitative Modelling in Economics with Advanced Artificial Neural Net-works The Inclusive Cost of Pandemic Influenza Risk Application of Artificial Neural Networks in Tendency Forecasting of Economic Growth. Proceedings of Economic Modeling The Return to Protectionism The Nexus between Artificial Intelligence and Economics Predicting Winning and Losing Business When Changing Electricity Tariffs The Dynamics of Comparative Advantage Boosting Insights in Insurance Tariff Plans with Tree-based Machine Learning Methods Trade and Inequality: From Theory to Estimation Causal Learning versus Reinforcement Learning for Knowledge Learning and Problem Solving Empirical confidence intervals for USDA commodity price forecasts The IMF and Covid-19 International Monetary Fund (IMF) LightGBM: A Highly Efficient Gradient Boosting Decision Tree Quantitative Trade Models: Developments and Challenges, Staff Report 537 Federal Reserve Bank of Minneapolis Appraisal of Artificial Neural Network for Forecasting of Economic Parameters Organization for Economic Cooperation and Development, Trade in Goods and Services Forecast Econometric Policy Evaluation: A Critique Map Reduce Blog Application of Artificial Neural Network with Extreme Learning Machine for Economic Growth Estimation Economic Growth Forecasting by Artificial Neural Network with Extreme Learning Machine Based on Trade, Import and Export Parameters Machine Learning: An Applied Econometric Approach Machine Learning: An Applied Econometric Approach Machine Learning in Gravity Models: An Application to Agricultural Trade Forecasting Economic and Financial Time Series: ARIMA vs Model for International Trade of Sawnwood Using Machine Learning Models. Natural Resources Institute Finland Analysis, and Presentation of Strong Rules. Knowledge Discovery in Databases Knowledge Discovery in Databases Estimating Trade Policy Effects with Structural Gravity G20 Strategy for Global Trade Growth Context-Based Reasoning: A Revised Specification Analysis of Bilateral Trade Flow and Machine Learning Algorithms for GDP Forecasting Country k=2 k=3 k=4 k=5 k=6 k=7 k=8 k=9 k=10 Appendix 3