Most of the sensor data produced by connected devices in IoT incorporates a temporal aspect and can therefore be considered as time-series data. Time Series Analysis involves analyzing this data to extract meaningful insights and characteristics. Time Series Forecasting involves leveraging these insights on observed data to predict future values. In the context of planning, time-series forecasting has several use cases.
Recently, Water Demand Forecasting has become an essential strategy in effective water resource planning and management. Water demand forecasts are required for the cost-effective and sustainable management and expansion of urban water supply infrastructure. Water demand forecasts can provide valuable information to distribution-system operators for controlling the production, storage and delivery of drinking water.
Consider a water distribution company that supplies water to a community. The distribution company would maintain a reservoir tank for supplying water to the entire community. The tank must be refilled at times and should always maintain sufficient water level to meet the consumption demand of the community. It is observed that consumption of water is not uniform throughout the day. There is a peak consumption during the morning/evening hours whereas during the day, the consumption is lesser. Also, consumption during the weekends is higher than in the weekdays; same goes for the consumption during summer seasons than the winters.
Technically speaking, the distribution-system operators should adjust the pressure for water flow regularly in order to maintain sufficient water level to meet the demand. This process is continuous and needs to be performed at regular intervals throughout the day based on the water consumption. Here, the forecasting of water consumption would help the distribution-system operators to act appropriately. For example, when the demand is less, they can reduce the pressure for water flow which in turn would ascertain longevity of the water pipes. Also, when the demand is low, less water needs to be pumped which in turn would save a lot in terms of electricity consumed in pumping of water.
In this Demand Forecasting use case, we would like to forecast the peak/non-peak hours of water consumption using a Time Series model. For showcasing this, we would follow these steps.
- Create a demo device in Cumulocity IoT that mimics an actual device connected to the reservoir tank.
- Simulate measurements for the demo device.
- Generate forecasts based on the simulated data.
Download the DemandForecastingDemoProject.zip file which contains the scripts and sample data set used in this demo.
Running the demo scripts requires
- Prior experience with Python, Jupyter Notebook, JSON, REST and understanding of data science processes.
- Familiarity with Cumulocity IoT and its in-built apps.
- Subscription of the MLW microservice (10.13.0.x.x or higher), the Zementis microservice (10.6.0.x.x or higher), the Nyoka microservice (10.6.0.x.x or higher), the Machine Learning Workbench application and the Machine Learning application on the tenant.
We have added a CONFIG.json file to the attached ZIP file. This file is meant for capturing the tenant details and credentials which will be used by the demo scripts.
First of all, update the CONFIG.json with the appropriate values and save it. Replace
c_url with your tenant URL,
c_user with your tenant username and
c_pass with your tenant password. Leave the
c_device_source as is for now.
Demand forecasting using a demo device
A fully functional demand forecasting demo can be prepared with the help of a demo device. For this, use the artifacts provided as part of the project DemandForecastingDemoProject.zip file.
Start with Machine Learning Workbench
Follow the steps described in Machine Learning Workbench > Upload a project and upload the DemandForecastingDemoProject.zip project to MLW. This creates a new project named DemandForecastingDemoProject_uuid, which has a total of 5 resources. You will get 2 files in the Data folder and 3 notebooks in the Code folder.
Register a demo device in the platform
Instead of registering an actual device for the water demand forecasting use case, a demo device can be registered. This device can be used as a replica of an actual device connected to the reservoir tank. To do so, follow the steps below: We have added a script RegisterDevice.ipynb which registers a demo device in Cumulocity IoT.
- Open it and click the edit icon .
- Execute each cell one by one and you will have a registered device in Cumulocity IoT. Upon successful execution, a device named “DemandForecastDemoDevice” is registered in Cumulocity IoT.
- Once registered, try to get the device ID by looking up your device on the All Devices page of your tenant’s Device Management application. The device ID is already updated by the code and is saved in the CONFIG.json file.
Upon successful execution, a device named “DemandForecastDemoDevice” is registered in Cumulocity IoT. Once registered, try to get the device ID by looking up your device on the All Devices page of your tenant’s Device Management application. The CONFIG.json file is already updated by the code with the device ID.
This device is capable of simulating readings of water flow to Cumulocity IoT in the form of a measurement named c8y_Flow.
A higher value of c8y_Flow signifies higher water consumption.
Simulate measurements for the demo device
Use SimulateData.ipynb for simulating the measurements for the demo device.
- Open it and click the edit icon .
- Execute each cell one by one and you have a registered device in Cumulocity IoT. Upon successful execution,
c8y_Flow measurementsare sent to Cumulocity IoT on behalf of the demo device. The measurements are simulated dynamically for the last 8 days period and for every two hours (that is, 12 observations per day).
We use this data to generate a time series model and forecast the next day’s c8y_Flow values. Keep in mind that forecast intervals will match the observation intervals. This can be confirmed by checking the data points in the Cumulocity IoT Cockpit application.
Download the data for model building exercise
Follow the steps described in Machine Learning Workbench > Data pull > Cumulocity IoT and pull the measurements of the newly registered smartphone with “hourlyData.csv” as File name, data interval (i.e. interval during which the data was created), “HOURLY” as Aggregation and select “c8y_flow” as Data points.
This file can be previewed to verify the downloaded data and can be used for model building exercise.
Generate forecasts based on the simulated data
Run all the cells in TrainModelandPredict.ipynb notebook which does the following:
- Loads the data for building the Time Series model using the Nyoka microservice.
- Forecasts the next day’s (i.e. today) water consumption values along with the timestamps using the generated Time Series model by invoking the Zementis microservice.
The notebook provides you with an insight of the peak/non-peak values for the next day. To make the use case simpler, we considered only 8 days worth of data but it can be extended to any number of days. Also, the forecasts can be made for any number of time steps in the future.