<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged prophet</title>
<link>https://coderlegion.com/tag/prophet</link>
<description>Powered by Question2Answer</description>
<item>
<title>Thomas Bayes: The Reverend Who Taught Us to Update Our Beliefs with Data</title>
<link>https://coderlegion.com/22967/thomas-bayes-the-reverend-who-taught-us-to-update-our-beliefs-with-data</link>
<description>&lt;p&gt;There is a question every professional who works with data should ask — and almost no one formulates explicitly: &lt;strong&gt;How should I change my opinion when I receive new evidence?&lt;/strong&gt; I don't mean a philosophical answer, but a mathematical one. If I believe there's a 30% probability that an electronic component will become obsolete this year, and I suddenly receive an email from the supplier announcing a production capacity reduction, how much should my estimate increase? To 50%? To 70%? How do I calculate it rigorously?&lt;/p&gt;
&lt;p&gt;The answer to that question was formulated by an English Presbyterian reverend sometime before 1761, and it wasn't published until two years after his death. His name was &lt;strong&gt;Thomas Bayes&lt;/strong&gt;, and his posthumous essay is, without exaggeration, one of the most influential documents in the history of science. From the spam filters in your email to the probabilistic forecasting models we used in the &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/sop-engineering-part2-forecasting/&quot;&gt;S&amp;amp;OP Engineering series&lt;/a&gt; with Facebook Prophet, everything passes through Bayes' Theorem.&lt;/p&gt;
&lt;p&gt;In the lineage of historical figures who shaped our relationship with data — &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/florence-nightingale/&quot;&gt;Florence Nightingale&lt;/a&gt; and visualization, &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/john-snow/&quot;&gt;John Snow&lt;/a&gt; and geolocation, &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/abraham_wald/&quot;&gt;Abraham Wald&lt;/a&gt; and survivorship bias, &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/kantorovich/&quot;&gt;Kantorovich&lt;/a&gt; and optimization, &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/deming/&quot;&gt;Deming&lt;/a&gt; and quality, &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/claude_shannon/&quot;&gt;Claude Shannon&lt;/a&gt; and information — Bayes occupies a singular place: he taught us to think of &lt;strong&gt;uncertainty as something quantifiable and updatable&lt;/strong&gt;, not as an obstacle but as raw material.&lt;/p&gt;
&lt;h4 id=&quot;the-reverend-and-the-posthumous-essay&quot;&gt;The Reverend and the Posthumous Essay&lt;/h4&gt;
&lt;p&gt;Thomas Bayes was born in London in 1702 into a family of religious dissenters. His father, Joshua Bayes, was one of the first Presbyterian ministers ordained in England. Thomas followed in his father's footsteps, was ordained a minister, and spent most of his life as a pastor in Tunbridge Wells, a quiet spa town southeast of London.&lt;/p&gt;
&lt;p&gt;But Bayes was no ordinary pastor. He was a Fellow of the &lt;strong&gt;Royal Society&lt;/strong&gt; (elected in 1742), which indicates that his mathematical reputation was recognized by the scientific elite of his era. He is known to have published a work defending the logical foundations of Newton's calculus, but during his lifetime he was a discreet figure, almost invisible in the great intellectual debates of the Enlightenment.&lt;/p&gt;
&lt;p&gt;History might have completely forgotten Bayes were it not for his friend &lt;strong&gt;Richard Price&lt;/strong&gt;, a distinguished Welsh philosopher and mathematician. After Bayes's death in 1761, Price found among his papers an unfinished manuscript titled &lt;em&gt;&quot;An Essay towards solving a Problem in the Doctrine of Chances&quot;&lt;/em&gt;. Price immediately recognized its importance, completed it, and presented it to the Royal Society in 1763.&lt;/p&gt;
&lt;p&gt;The problem Bayes was trying to solve was deceptively simple in its formulation and profoundly revolutionary in its implications: &lt;strong&gt;given a series of observations, what is the probability that the underlying cause is one thing or another?&lt;/strong&gt; In other words, how do we reverse the direction of probability? Not &quot;given that the coin is fair, what is the probability of getting 7 heads in 10 flips?&quot; but the inverse question: &quot;given that I observed 7 heads in 10 flips, what is the probability that the coin is fair?&quot;&lt;/p&gt;
&lt;h4 id=&quot;the-theorem-updating-beliefs-with-evidence&quot;&gt;The Theorem: Updating Beliefs with Evidence&lt;/h4&gt;
&lt;p&gt;Bayes' Theorem can be expressed without intimidating formulas using three intuitive concepts:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://datalaria.com/en/posts/thomas_bayes/bayes_updating.png&quot; alt=&quot;Visualization of Bayesian updating: from prior to posterior&quot;&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prior (Previous Belief)&lt;/strong&gt;: What you believe before seeing the data. Your initial estimate based on experience, intuition, or historical data. In an S&amp;amp;OP context, the &lt;em&gt;prior&lt;/em&gt; might be: &quot;Historically, we sell about 10,000 units of this product in July.&quot;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Evidence (Likelihood)&lt;/strong&gt;: The new data you observe and the probability of observing that data under different hypotheses. For example: &quot;This June we've received 40% more advance orders than last year.&quot;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Posterior (Updated Belief)&lt;/strong&gt;: Your new estimate after integrating the evidence with your previous belief. The &lt;em&gt;posterior&lt;/em&gt; mathematically combines what you knew before with what the new data tells you. It doesn't discard your prior experience nor lets itself be blinded by a single new data point: &lt;strong&gt;it weighs both&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The beauty of the Bayesian approach is that it's &lt;strong&gt;iterative&lt;/strong&gt;: today's &lt;em&gt;posterior&lt;/em&gt; becomes tomorrow's &lt;em&gt;prior&lt;/em&gt;. Each new piece of data refines your estimate. It's not a static photograph; it's a movie that updates frame by frame. It is exactly the same philosophy as &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/deming/&quot;&gt;W. Edwards Deming's&lt;/a&gt; PDCA cycle: plan, do, check, adjust. Repeat.&lt;/p&gt;
&lt;h4 id=&quot;modern-connection-prophet-and-demand-forecasting&quot;&gt;Modern Connection: Prophet and Demand Forecasting&lt;/h4&gt;
&lt;p&gt;Where does Bayes appear in modern data engineering? Virtually everywhere, but the most direct connection with this blog is &lt;strong&gt;Facebook Prophet&lt;/strong&gt;, the tool we used in &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/sop-engineering-part2-forecasting/&quot;&gt;Part 2 of the S&amp;amp;OP series&lt;/a&gt; to generate probabilistic demand forecasts.&lt;/p&gt;
&lt;p&gt;Prophet is, at its core, a &lt;strong&gt;Bayesian additive model&lt;/strong&gt;. It decomposes a time series into three components — trend, seasonality, and holiday effects — and generates not a point prediction, but a &lt;strong&gt;confidence interval&lt;/strong&gt;. That confidence interval is, literally, a Bayesian posterior distribution: it reflects the model's uncertainty given the historical evidence.&lt;/p&gt;
&lt;p&gt;Why does this matter in practice? Because the &lt;strong&gt;Safety Stock&lt;/strong&gt; we calculated in &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/sop-engineering-part3-optimization/&quot;&gt;Part 3 of the S&amp;amp;OP series&lt;/a&gt; — the amount of buffer inventory to absorb demand variability — is calculated on the upper bound of that confidence interval (typically at 95%). If Prophet used a deterministic model (a single number, no uncertainty), our Safety Stock would be a guess. Thanks to Bayes, it's a &lt;strong&gt;decision grounded in the probability distribution of future demand&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;prior&lt;/em&gt; in this context is the accumulated experience of the demand planning team and the historical patterns of the time series. The &lt;em&gt;evidence&lt;/em&gt; is the new data arriving each week or month. The &lt;em&gt;posterior&lt;/em&gt; is the updated forecast that feeds the &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/sop-engineering-part3-optimization/&quot;&gt;PuLP linear programming engine&lt;/a&gt; to optimize the production plan. Bayes is at the heart of the chain, even though his name is never mentioned in S&amp;amp;OP meetings.&lt;/p&gt;
&lt;h4 id=&quot;modern-connection-a-b-testing-and-netflix&quot;&gt;Modern Connection: A/B Testing and Netflix&lt;/h4&gt;
&lt;p&gt;When &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/netflix/&quot;&gt;Netflix&lt;/a&gt; decides which thumbnail to show for a series, it runs a massive A/B test: it shows version A to millions of users and version B to millions of others, then measures which generates more clicks. The classical (frequentist) approach requires waiting until a predetermined sample size is reached to declare a &quot;winner&quot; with statistical significance. If you do &lt;em&gt;peeking&lt;/em&gt; — looking at results before time — you invalidate the experiment.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;Bayesian&lt;/strong&gt; approach to A/B testing eliminates this problem. Instead of a binary hypothesis test (is there a difference or not?), Bayesian A/B testing continuously calculates the &lt;strong&gt;probability that version A is better than version B&lt;/strong&gt; given the data observed so far. You don't need to wait for a fixed sample size because the posterior distribution updates with each new data point.&lt;/p&gt;
&lt;p&gt;This has enormous practical implications for startups and teams with limited traffic. If your product doesn't have millions of users, a frequentist test can take weeks or months to be conclusive. A Bayesian test gives you a useful probability estimate much sooner, with the honesty of telling you: &quot;With current data, there's a 78% probability that A is better than B.&quot; You decide if that 78% is enough to act on.&lt;/p&gt;
&lt;h4 id=&quot;modern-connection-spam-filters-and-classification&quot;&gt;Modern Connection: Spam Filters and Classification&lt;/h4&gt;
&lt;p&gt;One of the first triumphs of machine learning in production at scale was the &lt;strong&gt;Bayesian spam filter&lt;/strong&gt;. The &lt;strong&gt;Naive Bayes&lt;/strong&gt; algorithm (called &quot;naive&quot; because it assumes independence between words, a crude simplification that's surprisingly effective) calculates the probability that an email is spam given the words it contains.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;prior&lt;/em&gt; is the base rate of spam (approximately 45% of all global email). The &lt;em&gt;evidence&lt;/em&gt; is the email's words: &quot;offer,&quot; &quot;free,&quot; &quot;urgent&quot; increase the posterior probability of spam; &quot;meeting,&quot; &quot;budget,&quot; &quot;attached&quot; reduce it. Each word updates the probability, exactly as Bayes prescribed 260 years ago.&lt;/p&gt;
&lt;p&gt;The connection with &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/abraham_wald/&quot;&gt;Abraham Wald's survivorship bias&lt;/a&gt; is direct: in a spam filter, the data you &lt;strong&gt;don't see&lt;/strong&gt; (legitimate emails erroneously filtered as spam) is as important as what you do see. If your filter has a high false positive rate, you're making the same mistake as the WWII engineers who only analyzed the planes that returned. Bayes and Wald, separated by two centuries, are talking about the same problem: &lt;strong&gt;absent information distorts your conclusions&lt;/strong&gt;.&lt;/p&gt;
&lt;h4 id=&quot;modern-connection-medical-diagnosis-and-the-perfect-test-paradox&quot;&gt;Modern Connection: Medical Diagnosis and the Perfect Test Paradox&lt;/h4&gt;
&lt;p&gt;There's a classic example of Bayesian reasoning that should be mandatory in every engineer's training, because it destroys a very widespread intuition. Suppose there's a medical test for a rare disease (prevalence: 1 in 10,000 people). The test has a sensitivity of 99% (correctly detects 99% of the sick) and a specificity of 99% (correctly identifies 99% of the healthy).&lt;/p&gt;
&lt;p&gt;Question: if you test positive, &lt;strong&gt;what is the probability that you're actually sick?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The intuitive answer most people give — including many physicians — is &quot;99%.&quot; The correct Bayesian answer is approximately &lt;strong&gt;1%&lt;/strong&gt;. How is this possible? Because the prevalence (the &lt;em&gt;prior&lt;/em&gt;) is so low that, even with a 99% test, the vast majority of positives are false positives.&lt;/p&gt;
&lt;p&gt;This reasoning is directly applicable to AI system engineering. When we configure alerts in the &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/obs_part5_radar_agent/&quot;&gt;obsolescence radar&lt;/a&gt; or in any monitoring system, the false positive rate is the silent enemy. An anomaly detection system with 99% accuracy can generate hundreds of false alerts if the base rate of actual anomalies is very low. Bayes forces us to think about the &lt;em&gt;prior&lt;/em&gt; before celebrating the &lt;em&gt;test's&lt;/em&gt; accuracy.&lt;/p&gt;
&lt;h4 id=&quot;the-legacy-think-in-distributions-not-points&quot;&gt;The Legacy: Think in Distributions, Not Points&lt;/h4&gt;
&lt;p&gt;Thomas Bayes's deepest contribution was not a formula; it was a &lt;strong&gt;mindset shift&lt;/strong&gt;. Before Bayes, probability was conceived as a fixed property of objects: a coin has a 50% chance of landing heads, period. After Bayes, probability became a measure of &lt;strong&gt;our degree of knowledge&lt;/strong&gt; about the world, continuously updated with new evidence.&lt;/p&gt;
&lt;p&gt;This distinction is the difference between an engineer who says &lt;em&gt;&quot;July demand will be 10,000 units&quot;&lt;/em&gt; and one who says &lt;em&gt;&quot;July demand has a 95% probability of falling between 8,500 and 11,500 units, and our production plan must absorb that variability.&quot;&lt;/em&gt; The first operates with false certainties; the second, with quantified uncertainty. The first is vulnerable to the &lt;em&gt;bullwhip effect&lt;/em&gt; that &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/sop_engineering-data-hygiene/&quot;&gt;destroys supply chains&lt;/a&gt;; the second is armored against it.&lt;/p&gt;
&lt;p&gt;In a world where AI models are stochastic by nature — as we painfully documented in the &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/ai_agents_part9/&quot;&gt;Autopilot post-mortem&lt;/a&gt;, where the same pipeline produces different results on each run — thinking Bayesianly isn't a philosophical option: it's an operational necessity. Don't ask &quot;what is the answer?&quot; Ask &quot;what is the distribution of possible answers, and with what confidence?&quot;&lt;/p&gt;
&lt;p&gt;A reverend from the 18th century, working in solitude with quill and ink in an English spa town, solved a problem that today powers medicine, marketing, cybersecurity, supply chain management, and artificial intelligence. And he did it with an idea so simple it fits in a single sentence: &lt;strong&gt;update what you believe with what you observe&lt;/strong&gt;. Two hundred and sixty years later, we still haven't found better advice.&lt;/p&gt;
&lt;hr&gt;
&lt;h5 id=&quot;sources-of-interest-&quot;&gt;Sources of Interest:&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://plato.stanford.edu/entries/bayes-theorem/&quot;&gt;&lt;strong&gt;Stanford Encyclopedia of Philosophy&lt;/strong&gt;: Bayes' Theorem — Foundations and Historical Context&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://royalsociety.org/people/thomas-bayes-11313/&quot;&gt;&lt;strong&gt;Royal Society&lt;/strong&gt;: Thomas Bayes — Fellow Profile&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.youtube.com/watch?v=HZGCoVF3YvM&quot;&gt;&lt;strong&gt;3Blue1Brown&lt;/strong&gt;: Bayes' theorem, the geometry of changing beliefs (YouTube)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/descriptive-analysis/&quot;&gt;&lt;strong&gt;Datalaria&lt;/strong&gt;: Descriptive Statistics — Data Analysis Fundamentals&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/sop-engineering-part2-forecasting/&quot;&gt;&lt;strong&gt;Datalaria&lt;/strong&gt;: S&amp;amp;OP Part 2 — Demand Planning with Prophet (Bayesian Model)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/abraham_wald/&quot;&gt;&lt;strong&gt;Datalaria&lt;/strong&gt;: Abraham Wald — The Epistemology of Missing Data&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/netflix/&quot;&gt;&lt;strong&gt;Datalaria&lt;/strong&gt;: Netflix — How Data Forges an Empire (A/B Testing)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/claude_shannon/&quot;&gt;&lt;strong&gt;Datalaria&lt;/strong&gt;: Claude Shannon — Entropy as Uncertainty&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/22967/thomas-bayes-the-reverend-who-taught-us-to-update-our-beliefs-with-data</guid>
<pubDate>Sat, 18 Jul 2026 16:44:19 +0000</pubDate>
</item>
<item>
<title>S&amp;OP Engineering II: Demand Planning from Guessing to Probability</title>
<link>https://coderlegion.com/13607/sop-engineering-ii-demand-planning-from-guessing-to-probability</link>
<description>&lt;p&gt;Your Excel says &quot;we'll sell 100 units.&quot; A round, clean, deterministic number. What if you sell 120? Stockout, unhappy customer, contractual penalty. What if you sell 50? 50 units sitting in your warehouse, immobilizing capital that could be generating returns.&lt;/p&gt;
&lt;p&gt;The problem isn't the forecast itself. It's the &lt;strong&gt;arrogance of the single number&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;In &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/sop_engineering-data-hygiene/&quot;&gt;Chapter 1&lt;/a&gt; we built a &quot;Quality Valve&quot; that filters ERP noise. Now that we have a pure signal, we're going to do something Excel can't: &lt;strong&gt;measure uncertainty&lt;/strong&gt;.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Executive Summary:&lt;/strong&gt; A probabilistic forecast doesn't tell you &quot;you'll sell 100.&quot; It tells you &quot;with 95% probability, you'll sell between 35 and 157.&quot; That uncertainty band is the mathematical foundation for calculating your Safety Stock without resorting to rules of thumb.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;the-architecture-mlops-not-scripts&quot;&gt;The Architecture: MLOps, Not Scripts&lt;/h3&gt;
&lt;p&gt;We haven't written a throwaway script. We've connected our mathematical brain (Python/Prophet) directly to our Single Source of Truth (Supabase/PostgreSQL).&lt;/p&gt;
&lt;p&gt;The key design is the &lt;code&gt;demand_forecasts&lt;/code&gt; table. Notice one column that separates this from a basic tutorial:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sql&quot;&gt;CREATE TABLE demand_forecasts (
    id              UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    execution_date  DATE NOT NULL,     -- ← When we ran the model
    ds              DATE NOT NULL,     -- Predicted future date
    yhat            NUMERIC NOT NULL,  -- Central prediction
    yhat_lower      NUMERIC NOT NULL,  -- Lower bound (Safety Stock)
    yhat_upper      NUMERIC NOT NULL,  -- Upper bound (Risk)
    model_version   TEXT NOT NULL,     -- Traceability
    UNIQUE(execution_date, ds)         -- One forecast per execution and date
);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Why &lt;code&gt;execution_date&lt;/code&gt;?&lt;/strong&gt; Because in 6 months, when you want to audit whether your model was accurate, you need to know &lt;em&gt;when&lt;/em&gt; you made the prediction versus &lt;em&gt;what actually happened&lt;/em&gt;. This is what MLOps calls &lt;strong&gt;Snapshotting&lt;/strong&gt;: recording the context of each execution to evaluate model drift over time.&lt;/p&gt;
&lt;p&gt;Without this column, you have a model. With it, you have an &lt;strong&gt;auditable system&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;the-engineering-why-prophet-and-not-a-textbook-arima-&quot;&gt;The Engineering: Why Prophet (and Not a Textbook ARIMA)&lt;/h3&gt;
&lt;p&gt;Prophet is a time series engine developed by Meta, designed for irregular business data: gaps, holidays, trend changes. Exactly what a real supply chain has.&lt;/p&gt;
&lt;p&gt;Here's the core fragment from our &lt;code&gt;ProphetPredictor&lt;/code&gt; class:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;def train_model(self, country_code='ES'):
    &quot;&quot;&quot;
    Trains Prophet with two key S&amp;amp;OP configurations:
    - interval_width: Confidence interval width
    - country_holidays: Country operational context
    &quot;&quot;&quot;
    self.model = Prophet(
        interval_width=0.95,     # ← 95% confidence interval
        weekly_seasonality=True,
        yearly_seasonality=True
    )
    # Holidays that alter loading/unloading patterns
    self.model.add_country_holidays(country_name=country_code)
    self.model.fit(self.ts_df)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Two engineering decisions that separate us from a YouTube tutorial:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;interval_width=0.95&lt;/code&gt;&lt;/strong&gt;: This is not a decorative parameter. The upper bound (&lt;code&gt;yhat_upper&lt;/code&gt;) represents the maximum probable demand with 95% confidence. This is literally your calculation basis for &lt;strong&gt;Safety Stock&lt;/strong&gt;: &lt;code&gt;Safety Stock = yhat_upper - yhat&lt;/code&gt;. Without this interval, your safety stock is a gut feeling; with it, it's mathematics.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;add_country_holidays('ES')&lt;/code&gt;&lt;/strong&gt;: In S&amp;amp;OP, holidays aren't &quot;days off.&quot; They're operational anomalies: the factory closes, the warehouse doesn't dispatch, transportation stops. If the model doesn't know that August 15th is a national holiday in Spain, it will interpret the drop in orders as a downward trend. This corrupts the September prediction.&lt;/p&gt;
&lt;h3 id=&quot;translating-math-into-business-decisions&quot;&gt;Translating Math into Business Decisions&lt;/h3&gt;
&lt;p&gt;Theory is nice. But a CEO doesn't approve budgets based on Python code. They need visual evidence.&lt;/p&gt;
&lt;h4 id=&quot;the-probabilistic-forecast&quot;&gt;The Probabilistic Forecast&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://datalaria.com/en/posts/sop-engineering-part2-forecasting/prophet_forecast_plot.png&quot; alt=&quot;Probabilistic demand forecast with 95% confidence intervals&quot;&gt;&lt;br&gt;
&lt;em&gt;The black dots are your actual historical demand. The central blue line is the prediction (yhat). The shaded band is the 95% confidence interval. The greater the historical volatility, the wider the band → the more Safety Stock you need → the more cash you immobilize. This band is the conversation you should be having with your CFO.&lt;/em&gt;&lt;/p&gt;
&lt;h4 id=&quot;explainability-separating-trend-from-seasonal-noise&quot;&gt;Explainability: Separating Trend from Seasonal Noise&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://datalaria.com/en/posts/sop-engineering-part2-forecasting/prophet_components_plot.png&quot; alt=&quot;Model component decomposition: trend, weekly and yearly seasonality&quot;&gt;&lt;br&gt;
&lt;em&gt;This is XAI (Explainable AI) applied to business. The model separates Trend (is the business growing or shrinking?) from Seasonality (are there spikes by time of year?) and holiday effects. This is what the CEO needs to see to approve the operations plan: knowing whether growth is real or just a calendar effect.&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;open-kitchen-try-it-yourself&quot;&gt;Open Kitchen: Try It Yourself&lt;/h3&gt;
&lt;p&gt;I distrust articles I can't execute. That's why I've prepared an isolated environment where you can train the model on an anonymized snapshot of the data we just cleaned in Chapter 1.&lt;/p&gt;
&lt;p&gt;You don't need to install Python, Prophet, or configure Supabase. You just need a browser:&lt;/p&gt;
&lt;p&gt; &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://colab.research.google.com/drive/1q_iZ3rPmcoXXJ3qXQzSrlxMYCSstyP12?usp=sharing&quot;&gt;Open the interactive Notebook on Google Colab&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Hit &quot;Play&quot; on the cells and watch a probabilistic forecast with uncertainty bands being generated. Modify the horizon, the country, the confidence interval. Do engineering, not faith.&lt;/p&gt;
&lt;h3 id=&quot;next-step-from-prediction-to-decision&quot;&gt;Next Step: From Prediction to Decision&lt;/h3&gt;
&lt;p&gt;Now we know the probability of what we're going to sell. The question shifts from &lt;em&gt;&quot;how much will we sell?&quot;&lt;/em&gt; to &lt;strong&gt;&quot;what should we manufacture or purchase to maximize margin and minimize risk?&quot;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;In Chapter 3, we'll introduce &lt;strong&gt;Mathematical Optimization&lt;/strong&gt; (PuLP) and &lt;strong&gt;Theory of Constraints&lt;/strong&gt; to transform predictions into supply decisions: how much to buy, when to produce, and how to distribute finite resources while minimizing costs.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;The difference between an Operations Director who reacts and one who decides is a mathematical model between the data and the action.&lt;/p&gt;
&lt;/blockquote&gt;
</description>
<category>Tutorials</category>
<guid isPermaLink="true">https://coderlegion.com/13607/sop-engineering-ii-demand-planning-from-guessing-to-probability</guid>
<pubDate>Sat, 28 Mar 2026 16:18:34 +0000</pubDate>
</item>
</channel>
</rss>