<?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 Vikash Krishna on Medium]]></title>
        <description><![CDATA[Stories by Vikash Krishna on Medium]]></description>
        <link>https://medium.com/@vikash.krishna?source=rss-a7b880dae01b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*8vGxq6R88xco-U_7</url>
            <title>Stories by Vikash Krishna on Medium</title>
            <link>https://medium.com/@vikash.krishna?source=rss-a7b880dae01b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 16:38:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vikash.krishna/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[Web Traffic Time-series Forecasting]]></title>
            <link>https://medium.com/@vikash.krishna/web-traffic-time-series-forecasting-6e495814bb51?source=rss-a7b880dae01b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e495814bb51</guid>
            <dc:creator><![CDATA[Vikash Krishna]]></dc:creator>
            <pubDate>Thu, 15 Aug 2024 12:51:13 GMT</pubDate>
            <atom:updated>2024-08-15T12:51:13.336Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C1fm7rpoPprlaD23.png" /></figure><h4>Introduction</h4><p>Time series forecasting is a crucial aspect of data science, especially for businesses that rely on predicting future trends to make informed decisions. Whether it’s predicting sales, stock prices, or web traffic, the ability to forecast accurately can give companies a competitive edge. In this blog, we’ll dive into the comprehensive analysis of web traffic time series forecasting, using a Jupyter Notebook that implements multiple forecasting models. We’ll explore the exploratory data analysis (EDA) techniques, preprocessing steps, the various forecasting algorithms used, evaluation metrics, and the significant inferences drawn from the data analysis.</p><h4>Understanding the Dataset</h4><p>Before diving into the EDA, it’s essential to understand the dataset used in this analysis. The dataset comprises web traffic data for various Wikipedia articles over a specified period. The training data spans from July 1, 2015, to December 29, 2016, and the testing data from January 1, 2017, to March 1, 2017. The dataset captures daily traffic, aiming to forecast future traffic trends based on past observations.</p><p>The dataset includes the following components:</p><ul><li><strong>Page Name</strong>: The title of the Wikipedia page.</li><li><strong>Date</strong>: The date for which the traffic data is recorded.</li><li><strong>Traffic Data</strong>: The number of visits to the page on a particular date.</li></ul><p>This time series data presents unique challenges, such as missing values, seasonality, and trends, which must be addressed through careful analysis and model selection.</p><h4>Exploratory Data Analysis (EDA)</h4><p>EDA is the first step in any data analysis project. It involves summarizing the main characteristics of the data, often through visual methods. EDA helps identify patterns, detect outliers, and understand the underlying structure of the data. In this project, the EDA process was crucial in setting the stage for effective forecasting.</p><p><strong>Handling Missing Values</strong></p><p>Missing values are a common issue in time series data, and the web traffic dataset was no exception. Missing data can occur for various reasons, such as page unavailability or data recording errors. The presence of missing values can significantly affect model performance, leading to inaccurate predictions.</p><p><strong>Techniques Used</strong>:</p><p><strong>Interpolation</strong>: For some pages, missing values were filled using linear interpolation, which estimates missing values based on the surrounding data points. This method is suitable for time series data with a smooth and continuous pattern.</p><p><strong>Forward Fill and Backward Fill</strong>: These methods involve filling missing values with the last available observation (forward fill) or the next available observation (backward fill). These methods are useful when data continuity is essential, and abrupt changes are unlikely.</p><p><strong>Impact</strong>: Proper handling of missing values ensures that the dataset remains robust, allowing models to learn effectively without being skewed by gaps in the data.</p><p><strong>Visualizing the Data</strong></p><p>Data visualization is a powerful tool for understanding time series data. In this analysis, various plots were used to gain insights into the dataset’s structure:</p><p><strong>Time Series Plots</strong>: Plotting the daily web traffic for each page over time revealed important patterns, such as seasonality and trends. Most pages exhibited weekly seasonality, with traffic peaking on specific days of the week. Additionally, some pages showed clear trends, either upward or downward, indicating changes in user interest over time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*g-feKqdIwHP9dEtSFjJoDw.png" /></figure><p><strong>Seasonal Decomposition</strong>: The data was decomposed into its seasonal, trend, and residual components. This decomposition helped in isolating the seasonal effects from the overall trend, making it easier to model each component separately.</p><p><strong>Outlier Detection</strong>: Visualization also helped in identifying outliers — data points that deviated significantly from the rest of the dataset. These outliers were often caused by events such as promotions, news coverage, or other external factors that temporarily boosted traffic.</p><p><strong>Identifying Patterns and Trends</strong></p><p><strong>Weekly Seasonality</strong>: Most pages exhibited strong weekly seasonality, with traffic peaking on certain days, likely driven by user behavior. For instance, educational pages might see more traffic during weekdays, while entertainment-related pages peak on weekends.</p><p><strong>Holiday Effects</strong>: Traffic patterns also varied around holidays, with some pages experiencing spikes during specific periods, such as Christmas or New Year’s. Understanding these effects was crucial for model selection, as some models are better suited to handling such seasonal variations.</p><p><strong>Trend Analysis</strong>: Some pages showed clear upward or downward trends, reflecting changes in popularity over time. For example, a page related to a trending topic might see an increase in traffic, while older, less relevant pages might see a decline.</p><h4>Data Preprocessing Techniques</h4><p>Preprocessing is a critical step in preparing the data for modeling. It involves transforming the raw data into a format that can be effectively used by forecasting models. In this analysis, several preprocessing techniques were employed to ensure the data was ready for accurate forecasting.</p><p><strong>Data Transformation</strong></p><p>Raw time series data often needs to be transformed to enhance model performance. The following transformations were applied:</p><p><strong>Log Transformation</strong>: Many pages exhibited a highly skewed traffic distribution, with a few days having significantly higher traffic than others. A log transformation was applied to stabilize the variance and reduce the impact of outliers. This transformation helps in making the data more normally distributed, which is beneficial for many forecasting models.</p><p><strong>Differencing</strong>: To remove trends and make the data stationary (i.e., having a constant mean and variance over time), differencing was applied. This technique involves subtracting the previous observation from the current one, which helps in highlighting the changes or differences over time rather than the absolute values.</p><p><strong>Feature Engineering</strong></p><p>Creating new features from the existing data can significantly improve model performance. In this analysis, the following features were engineered:</p><p><strong>Day of the Week</strong>: Given the strong weekly seasonality observed in the data, a feature representing the day of the week was created. This feature allowed models to account for the different traffic patterns on different days.</p><p><strong>Holiday Indicator</strong>: A binary feature indicating whether a particular day was a holiday or not was added. This feature helped models capture the effect of holidays on web traffic.</p><p><strong>Rolling Mean</strong>: A rolling mean feature was created to smooth out short-term fluctuations and highlight longer-term trends. This feature helped in reducing noise and improving model stability.</p><p><strong>Splitting the Data</strong></p><p>To evaluate model performance, the data was split into training and validation sets. The training set included data from July 1, 2015, to December 29, 2016, while the validation set covered January 1, 2017, to March 1, 2017.</p><p><strong>Training Set</strong>: The training set was used to fit the models. It contained most of the historical data, allowing the models to learn from a substantial amount of information.</p><p><strong>Validation Set</strong>: The validation set was used to test the models’ performance on unseen data. This split simulates a real-world scenario where a model is used to make predictions on future data that it hasn’t seen before.</p><h4>Forecasting Models</h4><p>The core of this analysis lies in the application of various forecasting models. Each model has its strengths and weaknesses, and the choice of model depends on the nature of the data and the specific forecasting task. The following models were employed in this analysis:</p><p><strong>Simple Median Model</strong></p><p>The simple median model is a straightforward approach to forecasting. It calculates the median traffic for each page over the training period and uses this median value as the forecast for all future dates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/0*Lv0vonjh_sFA6SDd.png" /></figure><p><strong>Advantages</strong>:</p><p><strong>Simplicity</strong>: The model is easy to implement and requires no parameter tuning.</p><p><strong>Robustness</strong>: The median is less sensitive to outliers than the mean, making this model robust in the presence of noise.</p><p><strong>Limitations</strong>:</p><p><strong>Lack of Flexibility</strong>: The model does not account for seasonality, trends, or other temporal patterns, which can lead to inaccurate forecasts for time series with complex structures.</p><p>Despite its simplicity, the simple median model provided a useful baseline for comparison with more complex models.</p><p><strong>Median Model with Weekday/Weekend/Holiday Adjustments</strong></p><p>To address the limitations of the simple median model, an extended version was developed that accounts for different traffic patterns on weekdays, weekends, and holidays. This model calculates separate medians for each type of day and uses these values for forecasting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/0*qqVE-zw4Psu13Kmo.png" /></figure><p><strong>Advantages</strong>:</p><p><strong>Improved Accuracy</strong>: By accounting for different traffic patterns on different days, this model can produce more accurate forecasts, especially for time series with strong weekly seasonality.</p><p><strong>Customization</strong>: The model can be easily customized to include other types of day-based adjustments, such as special events or promotional periods.</p><p><strong>Limitations</strong>:</p><p><strong>Increased Complexity</strong>: The model is more complex than the simple median model, requiring additional data preprocessing and feature engineering.</p><p><strong>Potential Overfitting</strong>: There is a risk of overfitting if too many adjustments are made, especially with limited data.</p><p><strong>ARIMA Model</strong></p><p>The ARIMA (AutoRegressive Integrated Moving Average) model is a classical statistical method for time series forecasting. It combines three components: autoregression (AR), differencing (I), and moving average (MA).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/0*gODo6IC4bCVr_zaQ.png" /></figure><p><strong>AR Component</strong>: The AR part involves regressing the variable on its own lagged (past) values.<strong>I Component</strong>: The I (integrated) part represents differencing the data to make it stationary.<strong>MA Component</strong>: The MA part models the error term as a linear combination of past error terms.</p><p><strong>Advantages</strong>:</p><p><strong>Versatility</strong>: ARIMA can model a wide range of time series data, making it a popular choice for many forecasting tasks.</p><p><strong>Incorporation of Temporal Dependencies</strong>: ARIMA explicitly models the temporal dependencies in the data, which can lead to more accurate forecasts.</p><p><strong>Limitations</strong>:</p><p><strong>Parameter Tuning</strong>: ARIMA requires careful selection of parameters (p, d, q), which can be challenging, especially for complex time series.</p><p><strong>Computational Intensity</strong>: The model can be computationally expensive, particularly for large datasets with many time series.</p><p>In this analysis, ARIMA was applied to a subset of pages with simpler traffic patterns, where it performed reasonably well.</p><p><strong>Facebook Prophet Model</strong></p><p>The Facebook Prophet model is a robust, scalable forecasting tool designed for time series data with missing values and outliers. Prophet fits the data with a piecewise linear model, incorporating trend and seasonality components.</p><p><strong>Advantages</strong>:</p><p><strong>Handling of Missing Data</strong>: Prophet is designed to handle missing data effectively, making it ideal for real-world time series with gaps.</p><p><strong>Incorporation of Holiday Effects</strong>: The model allows for easy incorporation of holiday effects, which is particularly useful for web traffic data that varies around holidays.</p><p><strong>Scalability</strong>: Prophet is scalable and can handle large datasets with multiple time series.</p><p><strong>Limitations</strong>:</p><p><strong>Complexity</strong>: While powerful, Prophet is more complex than simpler models and requires careful tuning of its parameters.</p><p><strong>Assumptions about Seasonality</strong>: The Prophet assumes a fixed periodicity for seasonality, which may not be accurate for all time series.</p><p>In this analysis, Prophet outperformed the other models, especially on pages with strong and irregular seasonal patterns. Its ability to handle missing data and incorporate holiday effects made it a versatile tool for forecasting web traffic.</p><h4>Evaluation Metrics</h4><p>Evaluating the performance of forecasting models is crucial to determine their accuracy and reliability. In this analysis, the Symmetric Mean Absolute Percentage Error (SMAPE) was used as the primary evaluation metric.</p><p><strong>SMAPE Formula</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/0*ZzQa33GJpKh70Wgc.png" /></figure><p>Where Ft and At are the forecasted and actual values, respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/0*A-gyqK0iWzUkOepq.png" /></figure><p><strong>Advantages of SMAPE</strong>:</p><p><strong>Normalization</strong>: SMAPE normalizes the error, making it easier to compare across different time series, especially those with varying scales.</p><p><strong>Sensitivity to Large Errors</strong>: SMAPE penalizes large errors more heavily, making it a reliable metric for assessing the accuracy of forecasting models.</p><p><strong>Limitations of SMAPE</strong>:</p><p><strong>Handling of Small Values</strong>: SMAPE can be sensitive to small values, which can lead to disproportionately high error rates in some cases.</p><p>The models were evaluated on the validation set using SMAPE, allowing for a fair comparison of their performance. The results showed that while simpler models like the median model provided reasonable forecasts, more sophisticated models like Prophet achieved significantly lower SMAPE scores, indicating higher accuracy.</p><h4>Inferences from the Analysis</h4><p>The comprehensive analysis of web traffic time series forecasting led to several important inferences:</p><p><strong>Effectiveness of Simple Models</strong></p><p>Simple models like the median model, especially when adjusted for weekdays, weekends, and holidays, performed surprisingly well. This highlights the importance of understanding the basic patterns in the data before applying more complex models. In some cases, simple models can provide a strong baseline and may even outperform more sophisticated models when the data is noisy or the patterns are not too complex.</p><p><strong>Strength of the Prophet for Complex Seasonality</strong></p><p>The Facebook Prophet model outperformed the other models, particularly on pages with strong and irregular seasonal patterns. Its ability to handle missing data, incorporate holiday effects, and model complex seasonality made it the best choice for forecasting web traffic in this analysis. Prophet’s versatility and scalability also make it suitable for a wide range of other time series forecasting tasks.</p><p><strong>ARIMA’s Limitations</strong></p><p>While ARIMA is a powerful tool for certain types of time series, it struggled with high-dimensional web traffic data, particularly due to the need for manual parameter tuning and its computational intensity. However, for pages with simpler, more linear patterns, ARIMA provided solid forecasts. This suggests that ARIMA may be better suited for smaller, less complex datasets or for situations where manual tuning is feasible.</p><p><strong>Importance of EDA</strong></p><p>The EDA process was crucial in guiding the model selection and preprocessing steps. By thoroughly exploring the data, identifying key patterns, and understanding the underlying structure, the analysis was able to tailor the models to the specific characteristics of the web traffic data. EDA also helped in identifying potential challenges, such as missing values and outliers, which could have negatively impacted model performance if not addressed properly.</p><p><strong>Validation and Real-world Application</strong></p><p>The validation process revealed that even well-performing models in training might struggle with unseen data. This underlines the importance of continuously validating and refining models to maintain their accuracy in real-world applications. It also emphasizes the need for robust evaluation metrics, such as SMAPE, to ensure that models are not just optimized for the training data but are also capable of generalizing to new, unseen data.</p><p><strong>Customizability of Forecasting Models</strong></p><p>The analysis demonstrated that forecasting models can be highly customizable, allowing them to be tailored to the specific needs of the task at hand. For example, the median model was extended to account for weekday, weekend, and holiday effects, significantly improving its accuracy. Similarly, the Prophet model’s ability to incorporate custom seasonality and holiday effects made it a powerful tool for this particular forecasting task.</p><p><strong>Challenges in Time Series Forecasting</strong></p><p>Time series forecasting presents unique challenges, such as dealing with missing data, seasonality, trends, and outliers. Each of these challenges requires careful consideration and appropriate techniques to ensure accurate forecasts. This analysis highlighted the importance of a structured approach to time series forecasting, starting with EDA and preprocessing, followed by model selection and validation.</p><h4>Conclusion</h4><p>Time series forecasting is a complex task that benefits greatly from a structured approach involving EDA, thoughtful preprocessing, and careful model selection. This analysis of web traffic forecasting demonstrated that while sophisticated models like Facebook Prophet offer powerful capabilities, simpler models can also provide valuable insights, particularly when well-tuned to the data.</p><p>By following a similar process, practitioners can apply these techniques to their time series data, tailoring the approach to the specific challenges and opportunities presented by their datasets. The inferences drawn from this study can guide future web traffic forecasting efforts, helping businesses optimize their strategies and improve decision-making.</p><p>Whether you are working with web traffic data, sales data, or any other type of time series, the principles outlined in this blog can help you achieve more accurate and reliable forecasts. As time series forecasting continues to evolve, staying informed about the latest techniques and tools will be key to maintaining a competitive edge in any data-driven industry.</p><p><a href="https://github.com/Vikashkrishna/ADA/blob/e16252dfec9edee959fd4d2a19b4a8420a20fc73/Web_Traffic_Timeseries_Forecasting.ipynb">GitHub Link</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e495814bb51" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>