Share E-Book

Simulation Models for Data Science (Early Release V2) (Dan Sullivan) (z-library.sk, 1lib.sk, z-lib.sk)

Author Dan Sullivan

Science
Language English

Organizations now rely on data and machine learning to guide decisions, yet questions about future actions remain. Historical analysis explains what occurred in the past and predictive models estimate outcomes, but neither explores alternative scenarios. Simulation modeling fills this gap, letting analysts ask 'what if' questions, experiment with change, and study how systems behave under different conditions before decisions are implemented. In this book, Dan Sullivan presents an introduction to four foundational simulation approaches used in data science and operations research: Monte Carlo methods, discrete event simulation, system dynamics, and agent-based modeling. Combining clear explanations with applied examples and peer-reviewed case studies, this book shows how Python tools and large language models make simulation modeling more accessible. You'll learn how simulation complements statistical modeling and machine learning by revealing bottlenecks, trade-offs, and interactions often hidden in traditional analyses.

Format PDF
Size 3.1 MB
2
Views
0
Downloads
0.00
Total Donations
(First 20 pages)

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Page 1
(This page has no text content)
Page 2
Simulation Models for Data Science Decoding Complexity With Early Release ebooks, you get books in their earliest form—the author’s raw and unedited content as they write—so you can take advantage of these technologies long before the official release of these titles. Dan Sullivan
Page 3
Simulation Models for Data Science by Dan Sullivan Copyright © 2027 Dan Sullivan. All rights reserved. Published by O’Reilly Media, Inc., 141 Stony Circle, Suite 195, Santa Rosa, CA 95401. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (https://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com. Acquisitions Editor: Aaron Black Development Editor: Jeff Bleiel Production Editor: Clare Laylock Cover Designer: Karen Montgomery Cover Illustrator: FILL IN Interior Designer: David Futato Interior Illustrator: Kate Dullea March 2027: First Edition Revision History for the Early Release 2026-03-25: First Release See https://oreilly.com/catalog/errata.csp?isbn=9798341668324 for release details.
Page 4
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Simulation Models for Data Science, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the author and do not represent the publisher’s views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. 979-8-341-66828-7 [FILL IN]
Page 5
Brief Table of Contents (Not Yet Final) Chapter 1. Why Use Simulation When You Have Data? Chapter 2. Building a Simulation Mindset: From Static Analysis to Dynamic Modeling Chapter 3. From Data to Distributions (unavailable) Chapter 4. How Do I Model Risk and Uncertainty in Decision Making? (unavailable) Chapter 5. How Do I Find and Fix Process Bottlenecks? (unavailable) Chapter 6. How Do I Predict System Behavior with Feedback Effects? (unavailable) Chapter 7. How Do I Model Market Dynamics and Competition? (unavailable) Chapter 8. How Do I Create Digital Twins That Connect to the Real World? (unavailable) Chapter 9. How Do I Deploy and Scale Simulations in Production? (unavailable) Chapter 10. How Do I Ensure My Simulations are Trustworthy? (unavailable) Chapter 11. How Do I Drive Adoption and Action from Simulation Insights? (unavailable)
Page 6
Chapter 1. Why Use Simulation When You Have Data? A NOTE FOR EARLY RELEASE READERS With Early Release ebooks, you get books in their earliest form—the author’s raw and unedited content as they write—so you can take advantage of these technologies long before the official release of these titles. This will be the 1st chapter of the final book. Please note that the GitHub repo will be made active later on. If you’d like to be actively involved in reviewing and commenting on this draft, please reach out to the editor at jbleiel@oreilly.com. Data professionals have no shortage of tools, historical datasets, and predictive models, but we still struggle to understand complex business processes. Consider supply chains. Small demand fluctuations can cascade into disproportionate order increases across retailers, distributors, and manufacturers. This is known as the bullwhip effect. This happens when each actor makes independent, rational decisions based on incomplete information, which can lead to system-wide disruptions. Or consider capacity planning. Predictive models can fail to account for backlogs, randomness in arrival times, and phase transitions at critical thresholds where systems experience catastrophic gridlock. Competitive pricing presents another challenge. Retailers can build price elasticity models based on historical data but cannot anticipate competitor reactions. This leaves them with static correlation analysis that offers little value for strategic decisions in dynamic markets.
Page 7
Clearly, we are missing something in our data analytics and data science toolkit. Simulation modeling fills those gaps in our suite of tools. A simulation model is an executable computer representation of a real-world system that defines the components of a system and describes rules that govern the interaction of those components. By considering both components and interactions, we can begin to understand how the system behaves over time and under different conditions. By modeling a large number of possible combinations of input parameters, we can reveal characteristics of novel situations that may not appear in historical data. By modeling components and interactions, we can discover feedback loops, time delays, and emergent properties that traditional statistical methods do not sufficiently model or predict. Simulation modeling complements, it does not replace, statistical and machine learning techniques in data science. Statistical methods are essential for descriptive and predictive analysis, while machine learning methods help us identify patterns in large datasets. Simulation models are exploratory and forward looking. They allow us to identify causal relationships and develop more explanatory hypotheses for complex business processes. This chapter begins with a quick look at why simulation is valuable today and how generative AI has revolutionized what data scientists can do. We then present an overview of complex business systems and why they are so hard to model and predict. We will look at three distinct business problems that highlight the challenges of analyzing complex systems. Next, we will move on to look at the limits of traditional analytics methods. We’ll explore the benefits of adopting a “systems thinking” approach to understanding dynamic and complex systems. Keeping in mind the aphorism that in theory, theory and practice are the same, but in practice they are not, we conclude the chapter with a case study. It describes a financial contagion that was not anticipated by traditional analytic tools but was elucidated by simulation modeling. This
Page 8
demonstrates the need for expanding our data science toolkit to include simulation. Why Simulation Now If simulation is so useful, why haven’t data scientists and data analysts employed it more? And why should you be adopting it now? There have been barriers to entry that have limited the adoption of simulation. Traditionally, simulation modeling required an understanding of specialized languages such as Simul8 and AnyLogic or the ability to code simulations in Python or R using specialized libraries. These are not the tools data professionals are used to working with, like SQL and Pandas. In addition, simulation modeling requires an understanding of probability distributions, statistical sampling methods, and queueing theory. Designing, building, and validating simulation could take a long time and can be hard to justify when using traditional simulation tools and software practices. Generative AI and specification-driven development are fundamentally altering the simulation landscape. Large language models and large reasoning models are increasingly proficient at creating simulation code. Specification-driven development practices employ the rapid, exploratory nature of vibe coding but combine it with detailed requirements, technical architecture design, data models, API contracts, and security best practices. The use of generative AI for simulation modeling is changing the scope of what data scientists can do. Today, a data scientist can use generative AI to help with the full lifecycle of simulation modeling, including: Researching and defining components and interaction rules of a system Choosing a simulation method, such as Monte Carlo, discrete event, system dynamics, or agent-based modeling Generating standard simulation code for component creation, resource allocation, event scheduling, and data collection
Page 9
Building statistical analysis scripts to understand the probability distributions of variables in the system to be modeled Creating data engineering pipelines to extract data from source systems, apply needed transformations, and provide data to simulation models Writing guides for end users as well as technical documentation, such as API documentation Generating validation tests to measure the quality of the model Defining appropriate ranges of sensitivity analysis tests Creating visualizations and user interfaces for working with the simulation Realistic simulations once required weeks of specialized training and months of development. Today we can use generative AI to help specify model requirements, understand fundamental mathematical principles, and generate production-quality code. This democratization does not eliminate the need for expertise and domain knowledge in complex simulation projects, but it reduces the barrier to entry for many use cases. Spreadsheets democratized financial modeling and SQL democratized data analysis. Now AI-assisted simulation is making systems thinking and what- if analysis available to data professionals and software developers who can clearly specify their business problem, identify appropriate modeling techniques, and validate models. Simulation is no longer a specialized niche capability; it is a general-purpose tool that should be in every data professional’s toolkit. This chapter begins with an overview of complex business systems and a discussion of why they are so hard to model and predict. We will look at three distinct business problems that highlight the challenges of analyzing complex systems: the bullwhip effect in supply chains, capacity planning, and the dynamics of competitive markets. Next, we will move on to look at the limits of traditional analytics methods, which includes dependence on
Page 10
historical patterns and the problem of novel situations, understanding correlation but not causation, using static snapshots to describe dynamic systems, focusing on central tendency without enough attention to extremes, and the risks of not understanding delays and latency in system dynamics. These issues motivate us to adopt a systems thinking approach to understanding dynamic and complex systems. Systems thinking employs several constructs including stocks and flows, feedback loops, delays and accumulations, as well as emergence and nonlinearity. Together, systems thinking and simulation modeling provide a powerful tool for analyzing problems with significant uncertainty, emergent properties, and the need to analyze novel, what-if scenarios. Keeping in mind the aphorism that in theory, theory and practice are the same, but in practice they are not, we conclude the chapter with a case study. It describes a financial contagion that was not anticipated by traditional analytic tools but was elucidated by simulation modeling. This demonstrates the need for expanding our data science toolkit to include simulation. Understanding Complex Business Systems There are numerous tools and techniques for analyzing and understanding data. Sometimes, it is pretty obvious which tools should be used for a particular problem. For example, if you want to compare two groups of customers, you might start with descriptive statistics about each group, such as the average amount spent per customer and the number of customers in each group. If you want to predict customer churn, you might start with a baseline machine learning model based on logistic regression, which is fast to train, works with both categorical and numerical features, and outputs probabilities. Many times, we do not have such obvious solutions to our problems. Let’s consider three such scenarios a data scientist might encounter when working in logistics, healthcare, and retail. Supply Chain Bullwhip Effect
Page 11
Let’s start with a simple question of how a change in one part of a supply chain can affect other parts of that supply chain. If a retailer decides to increase their average order size, it sounds reasonable to assume that change will lead to linear changes in other parts of the supply chain. That is often not what happens. A retailer sells 100 units per day with a standard deviation of 20. One week, the retailer sells 110 units per day for one week, totaling 770 units for the week. That is 70 more units sold than expected. The retailer assumes the daily average is increasing and they adjust their order from the distributor to accommodate the new increased level plus replenish the inventory that was drawn down during the week of higher-than-expected orders. If the retailer assumes the new level is 110 units per day, they may increase the inventory buffer they have on hand. This compounding of expected increase, replenishing stock, and increased inventory buffer might lead to a 30% increase in the number of products ordered from the distributor—from 700 units per week to 910 units per week. When the distributor sees this jump in order size, they may assume the retailer will continue with the 30% increase level, triggering the distributor to increase their orders from manufacturers. The distributor increases orders from 2,800 units per month to 3,780 units per month (a 35% increase). The manufacturers see an increase in orders and follow the pattern of increasing their target production. Manufacturers have to order raw materials and they tend to have longer lead times than retailers or distributors, so they place a large order for materials that may be 50% higher than what they would have ordered if the original retailer orders had stayed constant—from 11,200 units per quarter to 16,800 units per quarter. The amplification is striking: a 10% increase in retail demand cascades into a 50% increase in raw material orders. The amplification factor is 5× as shown in Figure 1-1.
Page 12
(This page has no text content)
Page 13
Figure 1-1. Bullwhip Effect Amplification Cascade Now imagine what happens the following week when demand for the retailer’s products drops back to 100. The retailer has excess inventory, so it cancels some orders while it works down stock on hand. The distributor sees a significant drop in orders and cancels outstanding orders to manufacturers. The manufacturer sees a precipitous drop in orders and cancels some of its production plans. The result of retailers, distributors, and manufacturers all making rational choices without full information about the state of the larger business system they operate in is highly disruptive. This phenomenon is known as the bullwhip effect in supply chains. It is caused by a combination of factors. Each actor in this system has limited information. They act only on information about their orders, not the demand of the end consumer. When all of the actors in the system order weekly instead of continuously, we risk having synchronization effects that can amplify swings. Also, each actor reasonably decides to accumulate stock instead of risking not being able to meet demand. Manufacturers and others with long lead times to fulfill orders require larger inventory positions. These multiple factors interact to create an outcome that is difficult to predict unless we consider all the factors that influence the outcome. Simulation is a tool that can help us better understand situations like the amplification phenomenon we see in the bullwhip effect. Simulation is especially helpful when we are dealing with: Dynamic systems, such as groups of actors making different kinds of choices Nonlinear impacts, such as when small changes in one part of a system trigger much larger changes in other parts of the system Actors that maintain state information and make decisions based on state
Page 14
Actors simultaneously making decisions with incomplete information Multiple sources of uncertainty Supply chains are not the only business process impacted by these phenomena. Capacity Planning: Averages Are Not Enough Imagine you are a data scientist working for a healthcare company. You have been tasked with helping model capacity planning for an emergency room. You develop a model that predicts the average patient arrival by hour, day, and season. You have carefully researched variation in historical data and accounted for things like flu season, adverse weather conditions, and local high-traffic events. You also know how important it is to validate your model, so you use time series cross-validation and track metrics like mean absolute error (MAE), mean absolute percentage error (MAPE), and root mean square error (RMSE). Your model works well, with average daily prediction MAPE of 8% and hourly arrival prediction MAPE of 15%. The validation results are promising, but how do they compare to reality? Let’s pick one time period, say Monday evenings 7 p.m. to 8 p.m., and see what one year of data looks like. Figure 1-2 shows actual arrivals on Mondays from 7 p.m. to 8 p.m. for 52 weeks.
Page 15
Week Arrivals Week Arrivals Wee 1 12 14 9 27 2 11 15 13 28 3 10 16 8 29 4 13 17 12 30 5 9 18 10 31 6 11 19 11 32 7 8 20 9 33 8 12 21 13 34 9 10 22 8 35 10 14 23 12 36 11 9 24 10 37 12 11 25 11 38 13 10 26 9 39
Page 16
(This page has no text content)
Page 17
Figure 1-2. Emergency Room Arrival Distribution Your model predicts an average of 10.5 patients per hour during this time slot. The average of the actual data is 10.5 patients per hour. Your model is accurate on average. The problem is that “on average” does not tell the full story. During 52 weeks of the year, the emergency room had 10 or 11 patients 32 times (62% of weeks). It had 8 or 9 patients 15 times (29% of weeks) and 12, 13, or 14 patients 5 times (10% of weeks). If the emergency room staffs for the average, they will be understaffed 10% of the time and overstaffed 29% of the time. This is where understanding variability becomes critical. The standard deviation of arrivals is 1.7 patients. If we want to ensure adequate staffing 90% of the time, we need to plan for approximately 12.7 patients per hour (mean + 1.3 standard deviations). If we want 95% coverage, we need to plan for 13.3 patients (mean + 1.65 standard deviations). But arrival rates are only part of the story. Service times also vary. If the average service time is 45 minutes with a standard deviation of 15 minutes, and we have two doctors on duty, queueing theory tells us the system utilization is: Utilization = (Arrival rate × Service time) / Number of servers = (10.5 × 0.75) / 2 = 0.39 or 39%
Page 18
(This page has no text content)
Page 19
Figure 1-3. Queueing Utilization vs. Wait Time At 39% utilization, average wait times are manageable. But what happens when arrivals spike to 14 patients per hour? Utilization jumps to 52.5%, and average wait times more than double due to nonlinear queueing effects. At 80% utilization, the system approaches gridlock, and wait times can exceed several hours. Simulations can help us identify the full range of variability so we can address different multiple likely scenarios rather than focus on only the average scenario. Competitive Market Dynamics Competitive dynamics present another challenge for traditional analytical methods. Consider a retail pricing problem. Two competing stores sell similar products. You have historical data on your own sales at different price points and have built a price elasticity model. Your model suggests that dropping your price by 10% will increase sales volume by 18%, leading to a 6% increase in gross revenue. You implement the price reduction and watch your competitor. Within a week, they match your price cut. Your sales volume increases by only 9% instead of 18%, and gross revenue drops by 2%. Your model failed to account for competitive response. Let’s quantify this with a simple example. Suppose both stores currently sell 1,000 units per week at $50 per unit, generating $50,000 in weekly revenue. Here’s what happens under different scenarios: Baseline – Your Price: $50 – Competitor Price: $50 – Your Volume: 1,000 – Competitor Volume: 1,000
Page 20
– Your Revenue: $50,000 – Competitor Revenue: $50,000 You cut, they hold – Your Price: $45 – Competitor Price: $50 – Your Volume: 1,800 – Competitor Volume: 600 – Your Revenue: $81,000 – Competitor Revenue: $30,000 You cut, they match – Your Price: $45 – Competitor Price: $45 – Your Volume: 1,090 – Competitor Volume: 1,090 – Your Revenue: $49,050 – Competitor Revenue: $49,050 Both increase – Your Price: $55 – Competitor Price: $55 – Your Volume: 850 – Competitor Volume: 850 – Your Revenue: $46,750
The above is a preview of the first 20 pages. Register to read the complete e-book.

Recommended for You

Loading recommended books...
Failed to load, please try again later

Tip the Site

Scan the WeChat Pay or Alipay code to tip. No login required.

WeChat Pay
Alipay
Back to List