Weather Forecasting Using Machine Learning Algorithm: Nitin Singh Saurabh Chaturvedi Shamim Akhter
Weather Forecasting Using Machine Learning Algorithm: Nitin Singh Saurabh Chaturvedi Shamim Akhter
Algorithm
Nitin Singh Saurabh Chaturvedi Shamim Akhter
Department of Electronics and Department of Electronics and Department of Electronics and
Communication Engineering Communication Engineering Communication Engineering
Jaypee Institute of Information Jaypee Institute of Information Jaypee Institute of Information
Technology, NOIDA, India Technology, NOIDA, India Technology, NOIDA, India
singhnitin0523@gmail.com saurabh.chaturvedi@jiit.ac.in shamim.akhter@jiit.ac.in
Abstract - The activities of many primary sectors depend results are presented in Section V, and the paper is
on the weather for production, e.g. farming. The climate is concluded in Section VI.
changing at a drastic rate nowadays, which makes the old
weather prediction methods less effective and more hectic. II. OVERVIEW OF IMPLEMENTED SYSTEM
To overcome these difficulties, the improved and reliable
weather prediction methods are required. These
In the proposed system, an application has been
predictions affect a nation’s economy and the lives of developed on Raspberry Pi 3 B. This application gets
people. To develop a weather forecasting system that can the real-time data from humidity-temperature and
be used in remote areas is the main motivation of this pressure sensors to predict the possibility of rain on the
work. The data analytics and machine learning present day. Fig. 1 demonstrates the block-level
algorithms, such as random forest classification, are used diagram of the system. The GPIO pins of Raspberry Pi
to predict weather conditions. In this paper, a low-cost and communicate between the hardware (sensors) and
portable solution for weather prediction is devised. software (application).
The application is made from three different modules:
Keywords - Weather forecast, machine learning,
Raspberry Pi, Python, confusion matrix, sensor.
sense.py, backend.py, and frontend.py. The sense.py
module gets the sensor value when prompted by a user.
It uses Adafruit_DHT and Adafruit_BMP
I. INTRODUCTION libraries to collect the data through GPIO pins. The
The process of predicting weather conditions for future backend.py module includes the machine learning
is called weather forecasting. This paper presents the model which is trained according to the random forest
rain prediction with the use of real-time data of classification. It collects the data from sense.py as a
temperature, humidity, and pressure using various NumPy array of size three. The data include
sensors. Machine learning provides a capability to the temperature, humidity, and pressure. The system
systems to learn and improve from experience without produces the result in the form of 0 or 1, where 1 points
being programmed by a user [1], [2]. With the out that rain will happen and 0 points out that there will
introduction of machine learning concept, there is a be no rain. The frontend.py module provides a graphical
great ease for data analysis and prediction. Machine user interface (GUI) to the application. This part of
learning does not require to understand the physical application interacts with the user. It is connected to the
processes that control the atmosphere but uses the past sense.py and backend.py modules.
data to predict future data. Therefore, this process may
be used as a weather forecasting method [3].
The random forest classification, a machine learning
algorithm, uses an ensemble learning method in which
two or more machine learning models are combined to
form a single machine learning model. It operates by
making multiple decision trees while training the
dataset and outputs the mode of classification of the
different trees.
The rest of the paper is organized as follows: Section II
discusses the overview of the implemented system.
Section III presents the description of the machine
learning approach. Section IV explains the details of the
hardware and software involved in this work. The
171
Fig. 1. Block diagram of the system. The random forest classification model is trained with
75% of the derived data set and 25% is used as the test
The snap shot of the developed GUI is shown in Fig. 2. set for the model.
The raw data set had the details of temperature,
humidity, pressure, and rain for each hour of a day. As
shown in Table I, the new data set is derived by
averaging the values.
TABLE I. Derived data set from raw data by averaging
172
Fig. 6. DHT11 humidity and temperature sensor [8].
173
The random forest classification provides deep insights VI. CONCLUSION
into the data dependencies. The main result expected in The prime objective of this work is to develop a low-
this work is about whether rain will happen or not on a cost, reliable, and efficient weather forecasting
particular day according to the sensor data. In Fig. 8, the application using the machine learning concept in
graph shows the dependency of rain on temperature, Python on Raspberry Pi board.
humidity, and pressure. In this graph, 0, 1, and 2
indicate temperature, humidity, and pressure,
respectively. It can be inferred from the graph that
humidity is the most important factor while predicting
rain followed by temperature and pressure.
REFERENCES
[1] N. Hasan, M. T. Uddin, and N. K. Chowdhury,
“Automated weather event analysis with machine
learning,” in Proc. IEEE 2016 International Conference
on Innovations in Science, Engineering and Technology
(ICISET), 2016, pp. 1-5.
[2] L. L. Lai, H. Braun, Q. P. Zhang, Q. Wu, Y. N. Ma, W. C.
Sun, and L. Yang, “Intelligent weather forecast,” in Proc.
IEEE 2004 International Conference on Machine Learning
and Cybernetics, 2004, pp. 4216-4221.
[3] A. G. Salman, B. Kanigoro, and Y. Heryadi, “Weather
forecasting using deep learning techniques,” in Proc. IEEE
2015 International Conference on Advanced Computer
Fig. 8. Features of importance of the developed model. Science and Information Systems (ICACSIS), 2015,
pp. 281-285.
In this work, out of total 7339 data sets, the data sets are [4] Delhi Weather Data. [Online]. Available:
https://www.kaggle.com/mahirkukreja/delhi-weather-
divided into 75% as the training set and 25% as the test data/home
set, i.e. 5504 data for training and 1835 for testing. The [5] Raspberry Pi. [Online]. Available:
splitting between the training set and test set is random. https://en.wikipedia.org/wiki/Raspberry_Pi
[6] Raspberry Pi 3 Model B. [Online]. Available:
From sklearn.metrics, an inbuilt function, https://images-na.ssl-images-amazon.com/images/
[7] DHT11 Temperature and Humidity Sensor. [Online].
accuracy_score(), is used to check the accuracy Available: https://www.robot-r-us.com/vmchk/sensor-
of this model. An accuracy of 87.90% could be temp/humid/dht11-temperature-and-humidity-sensor.html
achieved in this machine learning model. [8] DHT11 Temperature and Humidity Module. [Online].
Available: https://www.makerfabs.com/DHT11-
The resultant confusion matrix of the test set is shown Temperature-and-Humidity-Module.html
in Table II. The size of the test set is 1835, out of which [9] Sensors - Pressure, Temperature and Altitude with the
BMP180. [Online]. Available:
the number 1491 represents the count of correct
https://thepihut.com/blogs/raspberry-pi-
predictions that rain will not happen and 122 is the tutorials/18025084-sensors-pressure-temperature-and-
number of correct predictions that rain will happen. altitude-with-the-bmp180
Therefore, total 1613 correct predictions are made out [10] BMP180 Barometric Pressure Sensor Module. [Online].
of 1835 test data. Available:
https://ae01.alicdn.com/kf/HTB108MyX2JNTKJjSspoq6A
TABLE II. Confusion matrix of test data set 6mpXai/BMP180-GY-68-GY68-3-3V-5V-BMP-180-
Temperature-Pressure-Sensor-Module-Barometric-IIC-
I2C.jpg
[11] Raspbian. [Online]. Available:
Confusion matrix Predicted: No Predicted: Yes
https://en.wikipedia.org/wiki/Raspbian
[12] Spyder (software). [Online]. Available:
https://en.wikipedia.org/wiki/Spyder_(software)
Actual: No 1491 56
[13] Python (programming language). [Online]. Available:
https://en.wikipedia.org/wiki/Python_(programming_langu
age)
Actual: Yes 166 122
174