Impact of weather on fashion retailers
Tags: datascience, machinelearning, githubsdp, octograd2020
Published: 2020-05-23 00:22:15

## [Trendcast](http://inderpartap.github.io/trendcast.html) - Demand Forecast for Fashion Retailers

> Exploring the Impact of Weather on Short-time Demand Forecast for Fashion Retailers.<br /> 
> Our `Dashboard` predicts the inventory requirements with the help of `past sales` and real-time `weather forecast`

Watch the project video here -
<p align="center">
	<a href="https://www.youtube.com/watch?v=9ela0BQeP9M" alt="Youtube Video">
        <img src="https://img.youtube.com/vi/9ela0BQeP9M/0.jpg" />
    </a>
	</p>



### The Pipeline - 
![Pipeline](https://dev-to-uploads.s3.amazonaws.com/i/cisv512ajo5dhx17qnda.png)

#### Data Collection:
The pipeline incorporates datasets from two sources to solve the problem:
- Retail Data: A historic time-series dataset containing six years of retail sales transactions. The dataset was hierarchical in nature containing: Date of purchase → Province → City → Category → Department → Class → Style → Quantity of items sold and Total sales.

- Weather Data: I fetched the weather-related information like min temperature, max temperature, precipitation, snow depth, wind speed, etc, for corresponding dates and cities in the retail data from Meteostat using their Historical Weather API. 

#### Extraction, Transformation and Loading [ETL]:
Data integration was performed at two levels, city and date. After combining the two data sources, the following ETL steps were performed.

- Weather features with more than 80% null values were dropped since interpolating them would lead to incorrect and biased data.

- Other missing data in weather was filled with interpolation using the nearest matching assuming that the weather would not vary a lot in small time-frames.

- Missing data in the retail sales records after integration was filled with zeroes assuming there were no sales that particular day.

#### Exploratory Data Analysis [EDA]:
For the initial EDA, AWS Quicksight was used to have an initial overview of the dataset. After this, I explored the distribution of the features to measure the skewness, cardinality and frequency distribution of the unique features in the feature vector.
After basic EDA, I tried to find multiple feature interactions with each other for which I made a heatmap visualizing the correlation of features using Matplotlib and Seaborn.
![EDA plots](https://dev-to-uploads.s3.amazonaws.com/i/zrjys3wo2pp4j95fi39d.png)

#### Data Modeling:
A Stacked Ensemble was created which is a technique where data is trained on base learners and then predictions from those models are fed into a meta-model which then predicts the final values.
In this implementation, I used random forest, extra trees, AdaBoost and gradient boosted trees regressor as our base learners or level-0 models. XGBoost was used as the meta-model or level-1 model which was trained on the predictions of level-0 (base learners).
I was able to achieve an RMSE of 0.08 and MAE of 0.11 with this approach.

#### Visualization
Once the model files were generated, Flask was used to create a front-end dashboard for the end-user. The user has the ability to choose the City and the Department for which he wants to view the predictions. The application then identifies the date of the latest transaction from the dataset and then calls the weather API to get the weather information for the upcoming week. This information is then fed into the appropriate model and the predictions are displayed on the dashboard using ApexCharts.js.
![Frontend](https://dev-to-uploads.s3.amazonaws.com/i/xuq1ylouo4gphvqaqk3z.png)

#### Future Notes
This project showed that the weather does have a modest impact on retail sales for some cities and classes of departments. Future analysis could work on modelling on the granular level of data such as style and class, which would give even more accurate forecasts regarding the items needed to stock for the coming week. In this project we focused on an ablation study, to analyze the impact of weather. A statistical approach to understand the causality of weather such as the Granger-Causality test could also be applied. The forecast horizon could also be extended for reliable predictions in future studies.

### Project source - 
{% github https://github.com/inderpartap/trendcast/ %}

[Final Note]: # (CONGRATULATIONS!!! You are amazing!)