<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Azumi Muhammed on Medium]]></title>
        <description><![CDATA[Stories by Azumi Muhammed on Medium]]></description>
        <link>https://medium.com/@azumimuhammed25?source=rss-566de20e47dc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2ZkS_NwCmCb4YIF0dSilhA.jpeg</url>
            <title>Stories by Azumi Muhammed on Medium</title>
            <link>https://medium.com/@azumimuhammed25?source=rss-566de20e47dc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 20:15:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@azumimuhammed25/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to forecast time series data with Facebook Prophet]]></title>
            <link>https://medium.com/@azumimuhammed25/how-to-forecast-time-series-data-with-facebook-prophet-9d0a815f6b69?source=rss-566de20e47dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d0a815f6b69</guid>
            <dc:creator><![CDATA[Azumi Muhammed]]></dc:creator>
            <pubDate>Thu, 13 Nov 2025 17:05:14 GMT</pubDate>
            <atom:updated>2025-11-14T11:01:25.592Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Have you ever wondered how data scientists forecast future sales or next week’s weather? That’s where time series forecasting comes in, using previous data to create informed predictions.</em></p><p><em>In this article, you’ll gain hands-on experience using Prophet to make future predictions, a forecasting tool developed by the Facebook data science team.</em></p><p><strong><em>Here’s what we’ll cover in this article:</em></strong></p><p><em>Brief Introduction to Time Series Analysis and Facebook Prophet.</em></p><p><em>Step-by-Step Guide on how to use Prophet in Google Colab.</em></p><p><strong><em>1. Introduction to Time Series Analysis</em></strong></p><p><em>A time series is essentially a collection of data points taken or recorded at regular intervals, such as daily power usage, monthly sales numbers, or hourly temperature observations. Unlike other datasets, time series data consist of information on how every value changes over time and the patterns that these changes reveal.</em></p><p><strong><em>Why is Time Series Important</em></strong></p><p><em>Time series analysis allows us to understand the past and forecast the future. Identifying patterns across time proves essential in sectors such as energy forecasting, economics, and weather prediction. For example, by evaluating previous years’ energy usage trends, we may forecast how much electricity will be required next month, or even next decade. This enables improved planning, budgeting and decision-making, allowing utilities to avoid shortages and companies to manage resources more efficiently.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zc0mMsz9yBHFeIsLNkoZfA.jpeg" /></figure><p><strong><em>Time Series Decomposition</em></strong></p><p><em>Time series data frequently has overlapping patterns. Decomposition is the process of breaking down data into simpler, more understandable components to understand what drives changes in the data. Generally, a time series is broken into three major components: Trend, Seasonality and Residual.</em></p><p><em>A trend is a long-term movement or direction in data (for example, a rise in power consumption as the population grows).</em></p><p><em>Seasonality refers to regular, repeated patterns that occur during certain time periods.</em></p><p><em>Residual (or irregular) noise refers to random or unexpected variations that cannot be explained by trend or seasonality.</em></p><p><em>When we separate these layers, we get a clearer picture of what’s really happening in our data, which will help us forecast the future more accurately.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7fAAIwTzuXT3AUI8VSfMRg.jpeg" /></figure><p><strong>2.<em> A Gentle Introduction to Facebook Prophet.</em></strong></p><p><em>When it comes to time-series forecasting, data scientists frequently face the challenge of balancing accuracy and usability. That’s where Facebook Prophet comes in. Prophet is an open-source application specifically built to handle organisation forecasting activities like sales, website traffic, and energy usage, with little setup time and amazing versatility.</em></p><p><em>Prophet’s standout feature is its intuitive design. It uses an additive model to categorise time series into trend, seasonality, and holiday effects. This means you may record daily, monthly, and yearly patterns without requiring much statistical knowledge. Even more, Prophet gracefully handles missing data, outliers, and unexpected trend changes, allowing you to concentrate on insights rather than data cleaning.</em></p><p><strong><em>3. Hands-on guide on how to use Facebook Prophet</em></strong></p><p><em>To create an environment for Time Series Analysis within Colab, you can follow these steps:</em></p><ol><li><em>Open </em><a href="https://colab.research.google.com/"><strong><em>https://colab.research.google.com/</em></strong></a><strong><em> </em></strong><em>and register for a free account</em></li><li><em>Create a new notebook within Colab</em></li><li><em>Install &amp; use the prophet package</em></li></ol><p><em>We are going to use data from the </em><a href="https://www.londonair.org.uk/"><strong><em>London Air Quality Network</em></strong></a><strong><em> </em></strong><em>obtained from the </em><a href="https://www.imperial.ac.uk/school-public-health/environmental-research-group/"><strong><em>Environmental Research Group of Imperial College London</em></strong></a></p><p>Download data if you want to follow along: <a href="https://drive.google.com/uc?export=download&amp;id=1AZ1zkW_PArvhrDtRtAVOhPrAmX-sPMBP"><strong><em>https://drive.google.com/uc?export=download&amp;id=1AZ1zkW_PArvhrDtRtAVOhPrAmX-sPMBP</em></strong></a></p><p><strong><em>Install prophet</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2igRiwOMBpGKkGuE0oMjDA.jpeg" /></figure><p>Import Libraries</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qTkBPKTyt3q1yhXneqEGVQ.jpeg" /></figure><p>Download the London air quality dataset to Colab</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jYd8n7eg-s5lVqiCLVPm4Q.jpeg" /></figure><p><em>Take these quick steps to explore and have a general understanding of the data.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U3fowKzawsAk7dBffvPO_A.jpeg" /></figure><p><strong><em>Let’s prepare our data for modelling.</em></strong></p><p><em>We first need to choose the pollutant we want to forecast, and keep only the necessary columns, such as the date </em><strong><em>(Month)</em></strong><em> and target variable </em><strong><em>(London Mean Roadside: Nitrogen Dioxide (µg/m³))</em></strong><em>. This stage identifies precisely what we want to forecast and reduces the dataset to only what’s required for modelling</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RDwRh4L9gX_fxqSkZRIbnA.jpeg" /></figure><p><em>Ensure that the date column is represented in datetime format. Prophet, like most time series models, relies on properly formatted dates to detect trends, seasonal patterns, and other time-related characteristics in the data.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VgC81Pjg7bE5Tzvpe4RSfg.jpeg" /></figure><p><em>Now, let’s arrange the data by month to eliminate duplicate dates and prepare the data for Prophet. We’ll resample the dataset to a monthly frequency (‘MS’), calculate the average nitrogen dioxide (NO₂) level for each month, reset the index, and rename the columns to Prophet’s requirement (ds) for the date and (y) for the target variable.</em></p><p><em>Prophet requires distinct dates and evenly spaced time periods. By aggregating the data monthly, with this step, we build a clean, consistent time series that can be used to forecast accurately.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iBupuqrknNOxYsTX1-FA2g.jpeg" /></figure><p><em>When dealing with </em><strong><em>missing numbers</em></strong><em>, we can interpolate them or fill them with the mean. Another approach is to use df.dropna(inplace=True) to totally remove them. Prophet is highly adaptable; it handles gaps in data without encountering issues.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pam2zvGt7Rq8xCllR2iRLw.jpeg" /></figure><p><strong><em>Incorporating External Regressors</em></strong></p><p><em>Adding external regressors to a Prophet model allows it to incorporate impacts other than time-based patterns, such as weather conditions, holidays, or any other events that may have an impact on the variable being predicted. Prophet can provide more accurate and realistic forecasts by including these additional elements.</em></p><p><em>For this example, we’ll add a new dataset, a CSV file with historical London weather data, taken from Kaggle.</em></p><p><em>Here is the link to the datasets: </em><a href="https://www.kaggle.com/datasets/emmanuelfwerr/london-weather-data?resource=download"><strong><em>https://www.kaggle.com/datasets/emmanuelfwerr/london-weather-data?resource=download</em></strong></a></p><p><em>Download the London weather dataset to Colab</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nVRwFl-nb6chqOnnX7qqRQ.jpeg" /></figure><p><em>We’ll prepare the weather data to use as an external regressor by following these simple steps:</em></p><ol><li><em>Select the relevant features for our forecast.</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pxKgnYBKiNz9gRQpexWYlw.jpeg" /></figure><p><em>2. Convert the date column to datetime, then aggregate the daily readings. to a monthly average, Shift by one month so that the model can forecast pollution levels for the following month based on the weather from the previous month, update the column names to reflect the shift, and interpolate any missing values to maintain the time series continuity</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5phz94Bd8xM_JWiD9szgwg.jpeg" /></figure><p><em>3. Merge the processed weather DataFrame with the main target DataFrame (df) based on the dates. This integrates the prior month’s weather features with the pollution data, resulting in a single dataset suitable for Prophet modelling.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d-AlxJNbmd1Abyc_iCHHew.jpeg" /></figure><p><strong><em>Train_test_split</em></strong></p><p><em>The train_test_split allows us to check how well our model generalises to new data. By training on one part of the dataset and testing on another, we can assess the model’s real-world forecasting performance and avoid overfitting.</em></p><p><em>First, we’ll compute the total number of months in the data, then utilise 90% (train_size = 0.9) for training and the remaining 10% for testing.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jPE_eI5SEO3j2lWWV79EOA.jpeg" /></figure><p><em>Then we’ll use iloc indexing to select the first portion (train_df) for training the model and the rest (test_df) for evaluating its performance.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HHW8nH76O5_8LXF0IEdjjQ.jpeg" /></figure><p><strong><em>Setting up the scoreboard</em></strong></p><p><em>We’ll create a simple function to calculate the key forecast accuracy metrics — </em><strong><em>MAE</em></strong><em>, </em><strong><em>MAPE</em></strong><em>, and </em><strong><em>RMSE</em></strong><em>, and store them in a dictionary. Then, we’ll create a scoreboard DataFrame to compare different models. This step is helpful in Prophet modelling because it allows us to see how well the model predicts real values and objectively measure its performance.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AhpJm3RJlPAk64hK1hphtA.jpeg" /></figure><p><strong><em>Prophet Model</em></strong></p><p><em>Let’s create our Prophet model! We will begin by creating a Prophet instance and automatically adding all columns in train_df (excluding </em><strong><em>ds</em></strong><em> and </em><strong><em>y</em></strong><em>) as external regressors. Setting </em><strong><em>mode=’multiplicative’</em></strong><em> instructs Prophet to scale pollution levels up or down based on changes in various features, such as weather, rather than simply adding or removing preset values.</em></p><p><em>We’ll also incorporate UK holidays so that the model can account for regular calendar effects such as lower traffic or unusual activities, which frequently affect pollution levels. Finally, we will fit the model to our training data to begin learning patterns and relationships.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Avf0LU6mbBcO4TtsqeA94Q.jpeg" /></figure><p><strong><em>Forecast and Visualisations</em></strong></p><p><em>We’ll use our trained Prophet model to make predictions with the test dataset (test_df) and generate forecasts for all dates in </em><strong><em>df </em></strong><em>using the </em><strong><em>model.predict()</em></strong><em> function.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x-aJHjEJkKAus8w9SXOPNg.jpeg" /></figure><p><em>Let’s evaluate the Prophet model’s forecasting accuracy. First, extract the actual values (y_test) from the test set and the corresponding predicted values (yhat) from the forecast DataFrame. Then we’ll use the score_model() function to calculate error metrics </em><strong><em>(MAE, MAPE, RMSE)</em></strong><em> and record the results in the scoreboard under the label </em><strong><em>“Prophet External Regressors”</em></strong><em>. This helps compare model performance and assess how well the forecast matches real data.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oN0a5pET_FV4gqUP8llHgw.jpeg" /></figure><p><em>Let’s analyse the accuracy:</em></p><ul><li><strong><em>MAE (Mean Absolute Error = 4.67): </em></strong><em>On average, the predictions miss the real NO₂ values by around 4.7 µg/m³. For something like air-quality data, where pollution can swing around because of weather, traffic, or other random factors, that’s actually pretty solid.</em></li><li><strong><em>MAPE (Mean Absolute Percentage Error = 11%): </em></strong><em>This means the model stays within roughly 11% of the true values. For time-series forecasts — especially messy environmental ones — that’s a strong result.</em></li><li><strong><em>RMSE (Root Mean Squared Error = 5.80): </em></strong><em>RMSE hits harder on big mistakes, but since it’s close to the MAE, it suggests the model isn’t making huge errors. The predictions are fairly consistent.</em></li></ul><p><em>Overall, these are good numbers for a Prophet model working with real-world environmental data. Prophet usually ends up somewhere in the 10–20% MAPE range when the data is cleaned up properly, so landing around 11% means the model is performing very well.</em></p><p><strong><em>Let’s visualise our model</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mjFcQYPIgp1h7hfMSTaD7Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*93kGyQ_VCSOo6gyNz0b9pw.png" /></figure><p><em>The model plot shows that the Prophet model successfully captures the </em><strong><em>strong seasonal patterns</em></strong><em> and overall </em><strong><em>downward trend</em></strong><em> in nitrogen dioxide levels over time. The blue line represents the predicted mean values, while the shaded region shows the </em><strong><em>uncertainty interval</em></strong><em>, which stays reasonably tight — indicating consistent confidence in the forecasts. The close alignment between the black dots </em><strong><em>(actual values)</em></strong><em> and the blue line confirms the model tracks real data well, supporting the good accuracy seen in the scoreboard (</em><strong><em>MAPE ≈ 11%)</em></strong><em>.</em></p><p><strong><em>Prophet Forecast Components</em></strong></p><p><em>Let’s plot our model components</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YStc8hQymbycbRqjL2uU0Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*FtDYEv6pet8ov61wV9ToDA.png" /></figure><p><em>The components plot explains how various elements contribute to the entire forecast.</em></p><p><strong><em>Trend:</em></strong><em> Nitrogen dioxide </em><strong><em>(NO₂) </em></strong><em>levels have steadily decreased since 2013, likely due to cleaner air policies and fewer emissions.</em></p><p><strong><em>Holiday:</em></strong><em> UK holidays have a consistent impact on pollution levels, probably due to the fluctuations in traffic and industrial activities </em><strong><em>(annual surges)</em></strong><em>.</em></p><p><strong><em>Yearly Seasonality:</em></strong><em> NO₂ levels tend to follow a pretty familiar pattern each year. They usually climb during the winter, mostly because of factors like increased heating and less favourable weather, and then ease off in the summer when the air mixes and disperses pollutants more easily.</em></p><p><strong><em>Weather Effect:</em></strong><em> Weather factors have a subtle impact on pollution, with the</em><strong><em>“extra_regressors_multiplicative” </em></strong><em>line indicating how they can increase or decrease NO₂ concentrations by a small proportion. These impacts change over time but serve to improve the model’s accuracy.</em></p><p><em>Next, we’ll plot two line charts, one with the full forecast and another that zooms in on just the test period. On each plot, we’ll fill the space between </em><strong><em>yhat_lower</em></strong><em> and </em><strong><em>yhat_upper</em></strong><em> so we can actually see Prophet’s confidence range instead of just reading numbers. It gives a clearer sense of how sure (or unsure) the model is at different points in time.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HVs3BSymr2j78yHQQpmGag.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OcC09jDAIbGhoLVXUWkTUg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UtpfxyrlYL3PhbrspH4Pdg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zijH45VqsO--NdEAPiusQA.png" /></figure><p><em>Looking at the results, the forecast lines show that Prophet does a good job. The predicted trend </em><strong><em>(the orange dashed line)</em></strong><em> sticks close to the real data </em><strong><em>(the blue line)</em></strong><em> and picks up the usual seasonal ups and downs, along with the general drop in pollution over time. The orange shaded band marks the confidence interval, and since it stays fairly tight, the model seems pretty stable. When we zoom in, we can spot a few small differences between the prediction and the actual values, but overall, the model follows the real observations surprisingly well.</em></p><p><strong><em>Let’s look into the future.</em></strong></p><p><em>We’ll forecast the next 60 months with just a few simple steps:</em></p><ol><li><em>Extend the date range forward by the number of months you want to predict.</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s5fUM6G3JJjDU90VLIKF2A.jpeg" /></figure><ol><li><em>Recreates the </em><strong><em>previous month’s average weather data</em></strong><em>, ensuring the same structure and column names used during training.</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rqBMTRPZhc6Y-Ld3DT2HJw.jpeg" /></figure><ol><li><em>Use model.predict() to generate forecasts that include trend, seasonality, holidays, and weather effects.</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lckqgieEELhRvSoaKHeAmw.jpeg" /></figure><ol><li><em>Displays the predicted values </em><strong><em>(yhat) </em></strong><em>and the confidence intervals </em><strong><em>(yhat_lower, yhat_upper).</em></strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ar-8ZONqOyDOR4E-p699Ig.jpeg" /></figure><ol><li><em>Plot the future forecast.</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I_uO5_h1i1GT8szRQm-HRw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g54CIBs0eVpddR57P6HvWg.png" /></figure><p><em>The forecast chart shows that Prophet does a good job of picking up both the seasonal ups and downs and the overall drop in nitrogen dioxide levels over time. The orange forecast line stays pretty close to the blue line showing the real data, which means the model is performing well. The shaded area around the forecast gets a bit wider further into the future, suggesting more uncertainty, but the general trend is still clear. Overall, the prediction points to NO₂ levels continuing to slowly decrease through 2024, in line with the steady improvement in air quality we’ve seen so far.</em></p><p><strong><em>How to improve the model performance</em></strong></p><p><em>We could boost Prophet’s accuracy by fine-tuning its seasonality and changepoints, adding relevant external factors that might influence air quality, cleaning up or handling outliers, and using better or longer historical data. It would also help to implement cross-validation to tweak the model’s settings and check how well our model performs.</em></p><p><strong><em>Conclusion</em></strong></p><p><em>Facebook Prophet turned out to be an easy and effective tool for time series forecasting. It does most of the heavy lifting on its own, handling things like seasonality, trends, holidays, and even extra regressors without making you jump through a bunch of setup hoops. That makes it great whether you’re just starting or you’ve been working with data for years.</em></p><p><em>In this analysis, its predictions were solid, and the breakdown of its components made it clear what was actually driving the forecast. That kind of transparency is super helpful when you’re dealing with real-world data that isn’t always neat and predictable.</em></p><p><em>Whether you’re trying to forecast environmental data, sales numbers, website traffic, or pretty much anything that changes over time, Prophet gives you a straightforward, dependable way to make sense of it.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d0a815f6b69" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>