0% found this document useful (0 votes)
46 views95 pages

A13 Miniproject

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 95

MACHINE LEARNING BASED RAINFALL

PREDICTION
A Mini Project thesis submitted to the JAWAHARLAL NEHRU
TECHNOLOGICAL UNIVERSITY in partial fulfillment of the
requirement for the award of the degree of

BACHELOR OF TECHNOLOGY

In

Computer Science & Engineering

Submitted by
BOPPA SREEJA (19D31A0520)
ALETI KAVYA (19D31A0502)
B. ARUN KUMAR (19D31A0516)

Under the guidance of


Mr. CH. SHEKHAR
ASST. PROFESSOR, Dept of CSE

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


INDUR INSTITUTE OF ENGINEERING & TECHNOLOGY

( Affiliated to J.N.T.U.H, Hyderabad )

Ponnala (Vil), Siddipet (Dist), Telangana State – 502 277.

Jan 2023

I
Date: / /2023

CERTIFICATE
This is to certify that the thesis “MACHINE LEARNING BASED RAINFALL
PREDICTION” being submitted by

BOPPA SREEJA (HT. NO. 19D31A0520)


ALETI KAVYA (HT. NO.19D31A0502)
B. ARUN KUMAR (HT. NO. 19D31A0516)

In partial fulfillment for the award of “BACHELOR OF TECHNOLOGY” in


the Department of “COMPUTER SCIENCE & ENGINEERING”.(B.Tech) to the
“JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY” is a record of
bonafide Mini Project Work carried out by them under our guidance and supervision.

The results embodied in this thesis have not been submitted to any other
University or Institute for the award of any degree or diploma.

PROJECT GUIDE HOD

Mr. CH. SHEKHAR Mr. RITESH THAKUR

Asst. Professor Assoc. Professor &

Dept. of CSE HOD Dept. of CSE

EXTERNAL EXAMINER

II
ACKNOWLEDGEMENT

We are thankful to Mr. CH. Shekhar, Asst, Prof., Project Guide, Dept. of
CSE who guided us a lot by her favorable suggestions to complete our project. She is
theresearch oriented personality with higher end technical exposure.

We are thankful to Mr. Ritesh Thakur, Prof & Head of the department,
CSE, Indur Institute Of Engineering & Technology, for extending his help in the
department academic activities in the course duration. He is the personality of
dynamic, enthusiastic in the academic activities.

We extend our thanks to Dr. V.P. Raju Principal, Indur Institute Of


Engineering & Technology, Siddipet for extending his help throughout the duration
of this project.

We sincerely acknowledge to all the lecturers of the Dept. of CSE for their
motivation during our B.Tech course.

We would like to say thanks to all of our friends for their timely help and
encouragement.

Boppa Sreeja (19D31A0520)


Aleti Kavya (19D31A0502)
B. Arun Kumar (19D31A0516)

III
DECLARATION

We here by declare that the project work entitled “MACHINE


LEARNING BASED PREDICTION” Submitted to the university, is a record
of original work done by us under the guidance of Mr. CH. Shekhar, Asst.
Prof., Project Guide, Dept of CSE, Indur Institute of Engineering &
Technology, Siddipet and this project work has not formed the basis for the
award of any degree or diploma associateship\fellowship and any other similar
titles if any.

Boppa Sreeja 19D31A0520


Aleti Kavya 19D31A0502
B. Arun Kumar 19D31A0516

IV
ABSTRACT

Rainfall prediction is the one of the important technique to predict the climatic
conditions in any country. This paper proposes a rainfall prediction model using
Multiple Linear Regression (MLR) for Indian dataset.

The data taken from 1901 to 2015 monthly wise. The input data is having
multiple meteorological parameters and to predict the rainfall in more precise.

The Mean Square Error (MSE), accuracy, correlation are the parameters used
to validate the proposed model. From the results, the proposed machine learning model
provides better results than the other algorithms in the literature.

It is demanding responsibility of meteorological department to predict the


frequency of rainfall with uncertainty. It is complicated to predict the rainfall accurately
with changing climatic conditions. It is challenging to forecast the rainfall for both
summer and rainy seasons.

V
CONTENTS

CHAPTER NO TITLE PAGE NO


1 INTRODUCTION 1

1.1 Literature Review 4

2 SYSTEM ANALYSIS 8
2.1 Existing System 8
2.1.1 Disadvantages of Existing System 8
2.2 Proposed System 9
2.2.1 Advantages of Proposed System 9
2.3 System Study 9
2.3.1 Feasibility Study
2.4 Project Specifications 10
2.4.1 Hardware Requirements 11
2.4.2 Software Requirements 11
2.5 Project Requirements 11
2.6 Software Environment 12
2.6.1 Python 12
2.6.2 Django 21

3 SYSTEM DESIGN 32

3.1 System Architecture 32


3.2 Data Flow Diagrams 33
3.3 UML Diagrams 35
3.3.1 Usecase Diagram 36
3.3.2 Class Diagram 37
3.3.3 Sequence Diagram 38
3.3.4 Activity Diagram 39

VI
4 IMPLEMENTATION 40
4.1 Modules 40
4.2 Input Design 42
4.3 Output Design 43
4.4 Source Code 44

5 RESULT 66

6 SYSTEM TESTING 77
6.1 Sample Test Cases 77
6.2 Unit Testing 79
6.3 Integration Testing 79
6.4 Functional Test 79
6.5 White Box Testing 80
6.6 Black Box Testing 80
6.7 Unit Testing 81
6.8 Integration Testing 81
6.9 Acceptance Testing 82

7 CONCLUSION 83

8 FUTURE IMPROVEMENT 84

9 REFERENCES 85

VII
LIST OF FIGURES

2.6.2 Django Architecture 21


2.6.3 Model View Template 22
3.1 System Architecture 32
3.2 Data Flow Diagram 34
3.3.1 Usecase Diagram 36
3.3.2 Class Diagram 37
3.3.3 Sequence Diagram 38
3.3.4 Activity Diagram 39
5.1 Home page 66
5.2 User Register Form 66
5.3 Admin Login 67
5.4 Admin Home Page 67
5.5 View Registered Users 68
5.6 Adding Data to Dataset 68
5.7 Admin View Data 69
5.8 User Login Page 69
5.9 User Home Page 70
5.10 Getting Weather Report 70
5.11 Report 71
5.12 Dataset Hist Graph 71
5.13 Monthly wise Correlated Graph 72
5.14 Correlated Graph 72
5.15 Statewise Graph 73
5.16 Statewise Graph 73
5.17 Confusion Matrix 74
5.18 Monthly wise Confusion Matrix 74
5.19 Preprocessed Data 75
5.20 Prediction Result 75
5.21 Epoch Running 76
5.22 MLR Result 76
VIII
LIST OF TABLES

6.1 Sample Test Cases 77

IX
CHAPTER 1
INTRODUCTION

Rainfall prediction is important in Indian civilization and it plays major role in


human life to a great extent. It is demanding responsibility of meteorological
department to predict the frequency of rainfall with uncertainty. It is complicated to
predict the rainfall accurately with changing climatic conditions. It is challenging to
forecast the rainfall for both summer and rainy seasons

Predicting rainfall is a major component and is essential for applications that


surround water resource planning and management. Over the years numerous attempts
have been made at capturing rainfall. One area where it is vital to predict the rainfall
amount accurately is within rainfall derivatives.

Rainfall derivatives fall under the umbrella concept of weather derivatives,


which are similar to regular derivatives defined as contracts between two or more
parties, whose value is dependent upon the underlying asset. In the case of weather
derivatives, the underlying asset is a weather type, such as temperature or rainfall.

Contracts based on the rainfall index are decisive for farmers and other users
whose income is directly or indirectly affected by the rain. A lack or too much rainfall
is capable of destroying a farmer’s crops and hence their income. Thus, rainfall
derivatives are a method for reducing the risk posed by adverse or uncertain whether
circumstances.

Moreover, they are a better alternative than insurance, because it can be hard to
prove that the rainfall has had an impact unless it is destructive, such as severe floodsor
drought. Similar contracts exist for other weather variables, such as temperature and
wind. Within the literature rainfall derivatives is split into two main parts. Firstly,
predicting the level of rainfall over a specified time and secondly, pricing the
derivatives based on different contract periods/length. The latter has its own unique
problem, as rainfall derivatives constitutes an incomplete mar-ket1.

This means the standard option pricing models such as the Black-Scholes model
are incapable of pricing rainfall derivatives, because of the violation of the assumptions
of the model; namely no arbitrage pricing.

1
Thus, a new pricing framework needs to be established. This paper focuses on
the first aspect of predicting the level of rainfall. Note that it is essential to have a model
that can accurately predict the level of rainfall, before pricing derivatives, because the
contracts are priced on the predicted accumulated rainfall over a period of time.

In order to predict the level of rainfall for rainfall derivatives, the statistical
approach of Markov-chain extended with rainfall prediction (MCRP) is used. Other
methods do exist, but this approach in particular is the most commonly used, and will
thus be acting as a benchmark for our proposed methodology. The use of these models
allows for the simulation of rainfall on a daily time scale, thus giving more flexibility
in the problem domain.

The reason why we are interested in daily amounts, rather than monthly or
annual amount models is because the models are a lot more flexible to changes.
Moreover, one is able to capture trends and more information from studying daily
values. Thus, increasing the accuracy of pricing, which is crucial because contracts are
priced ahead of time—sometimes this can be up to a year ahead. It is outside the scope
of this paper to cover rainfall derivatives in detail.

As already mentioned, the use of MCRP is the most prevalent approach, due to
its simplicity. The general approach of MCRP is often referred to as a ‘chain-dependent
process’, which splits the model into capturing first the occurrence pattern, and then the
rainfall intensities.

The occurrence pattern is produced by calculating the probability of what the


out come of today will be given what happened in the previous day(s).The process of
deciding upon what state to be in is performed by a Markov-chain, where state 0 is a
dry day and state 1 is a wet day. On the other hand, the intensities are produced by
generating random numbers from a distribution that fits the daily data. This step is only
calculated if we are in state 1, i.e. a wet day. Typically in the literature, the Gamma
and Mixed-Exponential distributions provide the best fit for rain data and are most
commonly used.

We refer the reader to for a complete description of the MCRP approach.


However, even though the MCRP approach is quite popular, it faces several drawbacks.
First of all, the model is very simplistic and is heavily reliant on past information being
reflective of the future. Additionally, the predicted amount is essentially the average

2
level of rainfall observed across the study period and does not take into account annual
deviations in weather patterns.

Due to the disadvantages highlighted above, we divert away from the use of
statistical approaches and in this paper we propose using a machine learning technique
called Genetic Programming (GP). Rainfall prediction has not been covered in great
detail within the machine learning literature and the applications are mainly focused on
the short term predictions i.e. up to a few hours.

Little literature exists for the daily predictions, e.g. used a feed-forward back-
propagation neural network for rainfall prediction in Sri Lanka, which was inspired by
the chain-dependent approach from statistics. To the best of our knowledge, the only
work that exists for daily predictions using Genetic Programming is. However, the GP
performed poorly by itself, although when assisted by wavelets the predictive accuracy
did improve.

However, there has been no previous work in using GP in the context of rainfall
weather derivatives. The goal of this paper is thus to explore whether GP is able to
outperform the usual approach adopted within the rainfall derivative literature, namely
MCRP.

GP is chosen for this paper over other machine learning techniques, because it
has the benefit of producing white box (interpretable, as opposed to black box) models,
which allows us to probe the models produced. Moreover, we can capture nonlinear
patterns in data without any assumptions regarding the data.

This should allow us to produce a model that can reflect the ever changing
process of rainfall. As a result, we could capture yearly deviations that the current
MCRP is unable to replicate. Additionally, we are able to produce a more general
model, which can be applied to a range of cities/climates, without having to build a new
model each time.

Hence, the main contribution of this paper is that we propose a new GP for the
problem of rainfall prediction, and compare its predictive performance against the
performance of the current state-of-the-art MCRP approach. This will be the first step
towards pricing rainfall derivatives using GP.

3
1.1 LITERATURE REVIEW
A literature review identifies, evaluates and synthesises the relevant literarute
within a particular field of research. It includes the existing research information of
different scholars as follows.

1.1.1 Elucidating The Role Of Topological Pattern Discovery And Support


Vector Machine In Generating Predictive Models For Indian Summer Monsoon
Rainfall
Authors: Manojit Chattopadhyay, Surajit Chattopadhyay
The present paper reports a study, where growing hierarchical self-organising
map (GHSOM) has been applied to achieve a visual cluster analysis to the Indian
rainfall dataset consisting of 142 years of Indian rainfall data so that the yearly rainfall
can be segregated into small groups to visualise the pattern of clustering behaviour of
yearly rainfall due to changes in monthly rainfall for each year.

Also, through support vector machine (SVM), it has been observed that
generation of clusters impacts positively on the prediction of the Indian summer
monsoon rainfall. Results have been presented through statistical and graphical
analyses. Behaviour of systems with many interdependent components that lead to
organized as well as irregular features is referred to as complexity.

In such systems the knowledge of the parts does not necessarily lead to the
predictable behaviour of the entire system Modelling complexity of atmospheric
phenomena and generating prediction schemes accordingly has long been an area of
major concentration for the meteorologists over the globeIn view of importance of the
estimation of the future projected precipitation and rainfall on short- and long-term
basis detrended fluctuation analysis has been implemented by Efstathiou and Varotsos
(2012) in rainfall time series to explore the intrinsic properties of their temporal
variability.

In another recent study, Chattopadhyay and Chattopadhyay (2013) explored the


association between solar activity and Indian summer monsoon rainfall through spectral
analysis after carrying out Box-Cox transformation. Association between SST and
ENSO over the tropics has been discussed in a recent study by Varotsos et al.(2014),
where they suggested that the warming in the sea surface temperature (SST)

4
since 1900, did not occur smoothly and slowly, but with two rapid shifts in 1925/1926
and 1987/1988, which are more obvious over the tropics and the northern midlatitudes.

1.1.2 A Rainfall Prediction Model using Artificial Neural Network

Authors: Kumar Abhishek, , Rajeev Ranjan, Sarthak Kumar


The multilayered artificial neural network with learning by back-propagation
algorithm configuration is the most common in use, due to of its ease in training. It is
estimated that over 80% of all the neural network projects in development use back-
propagation.

In back-propagation algorithm, there are two phases in its learning cycle, one
to propagate the input patterns through the network and other to adapt the output by
changing the weights in the network.

The back-propagation-feed forward neural network can be used in many


applications such as character recognition, weather and financial prediction, face
detection etc.

The paper implements one of these applications by building training and testing
data sets and finding the number of hidden neurons in these layers for the best
performance. In the present research, possibility of predicting average rainfall over
Udupi district of Karnataka has been analyzed through artificial neural network models.

In formulating artificial neural network based predictive models three layered


network has been constructed. The models under study are different in the number of
hidden neurons.

1.1.3 A Short-Term Rainfall Prediction Model using Multi-Task Convolutional


Neural Networks

Authors: Minghui Qiu, Peilin Zhao, Ke Zhang, Jun Huang, Xing Shi,
Xiaoguang Wang, Wei Chu
Precipitation prediction, such as short-term rainfall prediction, is a very
important problem in the field of meteorological service. In practice, most of recent
studies focus on leveraging radar data or satellite images to make predictions.
However, there is another scenario where a set of weather features are
collected by various sensors at multiple observation sites.

5
The observations of a site are sometimes incomplete but provide important
clues for weather prediction at nearby sites, which are not fully exploited in existing
work yet.
To solve this problem, we propose a multi-task convolutional neural network
model to automatically extract features from the time series measured at observation
sites and leverage the correlation between the multiple sites for weather prediction via
multi-tasking.
To the best of our knowledge, this is the first attempt to use multi-task
learning and deep learning techniques to predict short-term rainfall amount based on
multi-site features.
Specifically, we formulate the learning task as an end-to-end multi-site neural
network model which allows to leverage the learned knowledge from one site to other
correlated sites, and model the correlations between different sites.
Extensive experiments show that the learned site correlations are insightful
and the proposed model significantly outperforms a broad set of baseline models
including the European Centre for Medium-range Weather Forecasts system
(ECMWF).

1.1.4 Deep Learning Models for the Prediction of Rainfall


Authors: Aswin S, Geetha P and Vinayakumar R

Rainfall is one of the major source of freshwater for all the organism around the
world. Rainfall prediction model provides the information regarding various
climatological variables on the amount of rainfall. In recent days, Deep Learning
enabled the self-learning data labels which allows to create a data-driven model for a
time series dataset.

It allows to make the anomaly/change detection from the time series data and
also predicts the future event's data with respect to the events occurred in the past. This
paper deals with obtaining models of the rainfall precipitation by using Deep Learning
Architectures (LSTM and ConvNet) and determining the better architecture withRMSE
of LSTM as 2.55 and RMSE of ConvNet as 2.44 claiming that for any time series
dataset, Deep Learning models will be effective and efficient for the modellers.

6
1.1.5 The Research Of Rainfall Prediction Models Based On Matlab Neural
Network

Authors: Xianggen Gan, Lihong Chen, Dongbao Yang, Guang Liu

The continuously cloudy or rainy forecast is an important basis that is used to


make choice of wheat harvest time but multiple regression weather forecast models
hardly content the rate of required accuracy.

Matlab neural network toolbox is composed of a series of typical neural network


activation functions that make computing network output into calling activation
functions. BP artificial neural network that is based on Matlab platform and utilizes
error back propagation algorithm to revise network weight has dynamic frame
characteristics and is convenient for constructing network and programming.

After it has been trained by input forecast samples, network forecast model that
has three neural cells possesses very good generalization capability. After we contrast
fitting rate and accuracy rate of network model with ones of regression model, network
model has a distinct advantage over regression model.

7
CHAPTER 2
SYSTEM ANALYSIS

System analysis is conducted for the purpose of studying a system or its parts
in order to identify its objectives. It is a problem solving technique that improves the
system and ensures that all the components of the system work efficiently to
accomplish their purpose. Analysis specifies what the system should do.

2.1 EXISTING SYSTEM

In the Existing system used back propagation neural network for rainfall
prediction. This model used by Xianggen Gan and he was tested using the dataset from
1970 to 2000 which has 16 meteorological parameters. During network training the
target error is set as 0.01 and learning rate is set as 0.01.

This model implemented on mat lab neural network. Genetic Programming


(GP) and MCRP were compared on 21 different datasets of cities across Europe. Daily
rainfall data for 10 years were taken as training data and one year rainfall data were
taken as testing data.

2.1.1 DISADVANTAGES OF EXISTING SYSTEM

 The disadvantage of MCRP is that it predicts accurate only for annual rainfall
when compared with monthly rainfall prediction.
 The assumptions which are made by the multiple linear regression are: linear
relationship between the both the descriptive and independent variables, the
highly correlated variables are independent variables, yi is calculated randomly.
 Weather is extremely difficult to forecast correctly.
 It is expensive to monitor-so many variables from so many sources.
 The computers needed to perform the millions of calculations necessary are
expensive.
Algorithm: Markov-chain extended with rainfall prediction (MCRP), Genetic
Programming

8
2.2 PROPOSED SYSTEM

The proposed method is based on the multiple linear regression. The data for
the prediction is collected from the publically available sources and the 70 percentage
of the data is for training and the 30 percentage of the data is for testing. Multiple
regression is used to predict the values with the help of descriptive variables and is a
statistical method.

It is having a linear relationship between the descriptive variable and the output
values. The number of observation is indicated by n. The dependent variable is yi and
the descriptive variable is xi. β0 and β p are the constant y intercept and slop of
descriptive variable respectively.

2.2.1 ADVANTAGES OF PROPOSED SYSTEM

 The error free prediction provides better planning in the agriculture and other
industries.
 The linear relationship between the both the descriptive and independent
variables, the highly correlated variables are independent variables, yi is
calculated randomly and the mean and variance are 0 and σ.
 The ability to determine the relative influence of one or more predictor
variables to the criterion value.
 Ability to identify outliers or anomalies.

Algorithm: Multiple Linear Regression (MLR)

2.3 SYSTEM STUDY


2.3.1 FEASIBILITY STUDY

The feasibility of the project is analyzed in this phase and business


proposal is put forth with a very general plan for the project and some cost
estimates. During system analysis the feasibility study of the proposed system is to
be carried out. This is to ensure that the proposed system is not a burden to the
company.
Three key considerations involved in the feasibility analysis are,
 Economical feasibility
 Technical feasibility
 Social feasibility

9
1. ECONOMICAL FEASIBILITY

This study is carried out to check the economic impact that the system will have
on the organization. The amount of fund that the company can pour into the research
and development of the system is limited. The expenditures must be justified. Thus the
developed system as well within the budget and this was achieved because most of the
technologies used are freely available. Only the customized products had to be
purchased.

2. TECHNICAL FEASIBILITY

This study is carried out to check the technical feasibility, that is, the technical
requirements of the system. Any system developed must not have a high demand on the
available technical resources. This will lead to high demands on the available technical
resources. This will lead to high demands being placed on the client. The developed
system must have a modest requirement, as only minimal or null changes are required
for implementing this system.

3. SOCIAL FEASIBILITY

The aspect of study is to check the level of acceptance of the system by the user.
This includes the process of training the user to use the system efficiently. The user
must not feel threatened by the system, instead must accept it as a necessity.

The level of acceptance by the users solely depends on the methods that are
employed to educate the user about the system and to make him familiar with it. His
level of confidence must be raised so that he is also able to make some constructive
criticism, which is welcomed, as he is the final user of the system.

2.4 PROJECT SPECIFICATION

project specification is a simple but complete description of a software's


functionality and purpose. It contains descriptions of how the software will be used
from a user perspective and performance details. It lists goals, functionality, and any
other information that is required for the developers to successfully complete the
project.

10
2.4.1 HARDWARE REQUIREMENTS
System : Intel i3

Hard Disk : 1 TB.

Monitor : 14’ Colour Monitor.

Mouse : Optical Mouse.

Ram : 4GB.

2.4.2 SOFTWARE REQUIREMENTS

Operating system : Windows 10.

Coding Language : Python.

Front-End : Html. CSS

Designing : Html,css,javascript.

Data Base : SQLite.

2.5 PROJECT REQUIREMENTS

The project involved analyzing the design of few applications so as to make the
application more users friendly. To do so, it was really important to keep the
navigations from one screen to the other well ordered and at the same time reducing the
amount of typing the user needs to do. In order to make the application more accessible,
the browser version had to be chosen so that it is compatible with most of the browsers.

1. Functional Requirements

 Graphical User interface with the User.

2. Hardware Requirements

For developing the application the following are the Hardware Requirements:

 Processor: Intel i3
 RAM: 4 GB
Space on Hard Disk: minimum 1 TB

11
3. Software Requirements

For developing the application the following are the Software Requirements:

1. Python

2. Django

4. Operating Systems supported

1. Windows 10 64 bit OS

5. Technologies and Languages used to Develop

1. Python

6. Debugger and Emulator

 Any Browser (Particularly Chrome)

2.6 SOFTWARE ENVIRONMENT

The system environment includes the technologies , software, frameworks,


programming languages that are used in developing a model. In this proposed model,
python , Django and machine learning algorithms have been used.

2.6.1 Python

Python is a general-purpose interpreted, interactive, object-oriented, and high-


level programming language. An interpreted language, Python has a design philosophy
that emphasizes code readability (notably using whitespace indentation to delimit code
blocks rather than curly brackets or keywords), and a syntax that allows programmers
to express concepts in fewer lines of code than might be used in languages such
as C++or Java.

It provides constructs that enable clear programming on both small and large
scales. Python interpreters are available for many operating systems. CPython,the
reference implementation of Python, is open source software and has a community-
based development model, as do nearly all of its variant implementations. CPython is
managed by the non-profit Python Software Foundation. Python features a dynamic
type system and automatic memory management. It supports multiple programming

12
paradigms, including object-oriented, imperative, functional and procedural, and has a
large and comprehensive standard library.

Interactive Mode Programming

Invoking the interpreter without passing a script file as a parameter brings up


the following prompt −

$ python

Python 2.4.3 (#1, Nov 11 2010, 13:34:43)

[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>>

Type the following text at the Python prompt and press the Enter −

>>> print "Hello, Python!"

If you are running new version of Python, then you would need to use print statement
with parenthesis as in print ("Hello, Python!");. However in Python version 2.4.3, this
produces the following result −

Hello, Python!

Script Mode Programming

Invoking the interpreter with a script parameter begins execution of the script
and continues until the script is finished. When the script is finished, the interpreter is
no longer active.

Let us write a simple Python program in a script. Python files have extension .py. Type
the following source code in a test.py file −

Live Demo

print "Hello, Python!"

We assume that you have Python interpreter set in PATH variable. Now, try to run this
program as follows −

$ python test.py

13
This produces the following result −

Hello, Python!

Let us try another way to execute a Python script. Here is the modified test.py file −

Live Demo

#!/usr/bin/python

print "Hello, Python!"

We assume that you have Python interpreter available in /usr/bin directory. Now, try to
run this program as follows −

$ chmod +x test.py # This is to make file executable

$./test.py

This produces the following result −

Hello, Python!

Python Identifiers

A Python identifier is a name used to identify a variable, function, class, module


or other object. An identifier starts with a letter A to Z or a to z or an underscore (_)
followed by zero or more letters, underscores and digits (0 to 9).

Python does not allow punctuation characters such as @, $, and % within identifiers.
Python is a case sensitive programming language. Thus, Manpower and manpower are
two different identifiers in Python.

Here are naming conventions for Python identifiers −

Class names start with an uppercase letter. All other identifiers start with a lowercase
letter.

Starting an identifier with a single leading underscore indicates that the identifier is
private.

Starting an identifier with two leading underscores indicates a strongly private


identifier.

14
If the identifier also ends with two trailing underscores, the identifier is a language-
defined special name.

Reserved Words

The following list shows the Python keywords. These are reserved words and
you cannot use them as constant or variable or any other identifier names. All the
Python keywords contain lowercase letters only.

And Exec not

Assert Finally or

Break For pass

Class From print

continue Global raise

def If return

del Import try

elif in while

else is with

except lmbdayield

Lines and Indentation

Python provides no braces to indicate blocks of code for class and function
definitions or flow control. Blocks of code are denoted by line indentation, which is
rigidly enforced.
The number of spaces in the indentation is variable, but all statements within
the block must be indented the same amount. For example −

if True:
print "True"
else:
print "False"

15
However, the following block generates an error −

if True:
print "Answer"
print "True"
else:
print "Answer"
print "False"
Thus, in Python all the continuous lines indented with same number of spaces would
form a block. The following example has various statement blocks −

Note − Do not try to understand the logic at this point of time. Just make sure you
understood various blocks even if they are without braces.

#!/usr/bin/python

import sys

try:
# open file stream
file = open(file_name, "w")
except IOError:
print "There was an error writing to", file_name
sys.exit()
print "Enter '", file_finish,
print "' When finished"
while file_text != file_finish:
file_text = raw_input("Enter text: ")
if file_text == file_finish:
# close the file
file.close
break
file.write(file_text)
file.write("\n")

16
file.close()
file_name = raw_input("Enter filename: ")
if len(file_name) == 0:
print "Next time please enter something"
sys.exit()
try:
file = open(file_name, "r")
except IOError:
print "There was an error reading file"
sys.exit()
file_text = file.read()
file.close()
print file_text
Multi-Line Statements
Statements in Python typically end with a new line. Python does, however, allow the use
of the line continuation character (\) to denote that the line should continue. For example

total = item_one + \
item_two + \
item_three
Statements contained within the [], {}, or () brackets do not need to use the line
continuation character. For example −

days = ['Monday', 'Tuesday', 'Wednesday',


'Thursday', 'Friday']
Quotation in Python
Python accepts single ('), double (") and triple (''' or """) quotes to denote string literals,
as long as the same type of quote starts and ends the string.

The triple quotes are used to span the string across multiple lines. For example, all the
following are legal −

word = 'word'

17
sentence = "This is a sentence."
paragraph = """This is a paragraph. It is
made up of multiple lines and sentences."""
Comments in Python
A hash sign (#) that is not inside a string literal begins a comment. All characters after
the # and up to the end of the physical line are part of the comment and the Python
interpreter ignores them.

Live Demo
#!/usr/bin/python

# First comment
print "Hello, Python!" # second comment
This produces the following result −

Hello, Python!
You can type a comment on the same line after a statement or expression −

name = "Madisetti" # This is again comment


You can comment multiple lines as follows −

# This is a comment.
# This is a comment, too.
# This is a comment, too.
# I said that already.
Following triple-quoted string is also ignored by Python interpreter and can be used as a
multiline comments:
'''
This is a multiline
comment.
'''
Using Blank Lines
A line containing only whitespace, possibly with a comment, is known as a blank line
and Python totally ignores it.

18
In an interactive interpreter session, you must enter an empty physical line to terminate
a multiline statement.

Waiting for the User


The following line of the program displays the prompt, the statement saying “Press the
enter key to exit”, and waits for the user to take action −

#!/usr/bin/python

raw_input("\n\nPress the enter key to exit.")


Here, "\n\n" is used to create two new lines before displaying the actual line.
Once the user presses the key, the program ends. This is a nice trick to keep a console
window open until the user is done with an application.

Multiple Statements on a Single Line


The semicolon ( ; ) allows multiple statements on the single line given
that neither statement starts a new code block. Here is a sample snip using the semicolon.
import sys; x = 'foo'; sys.stdout.write(x + '\n')

Multiple Statement Groups as Suites


A group of individual statements, which make a single code block are called suites in
Python. Compound or complex statements, such as if, while, def, and class require a
header line and a suite.
Header lines begin the statement (with the keyword) and terminate with a colon
( : ) and are followed by one or more lines which make up the suite. For example −

if expression :
suite
elif expression :
suite
else :
suite

19
Command Line Arguments

Many programs can be run to provide you with some basic information about
how they should be run. Python enables you to do this with -h −

$ python -h
usage: python [option] ... [-c cmd | -m mod | file | -] [arg]

... Options and arguments (and corresponding environment variables):

-c cmd : program passed in as string (terminates option list)

-d : debug output from parser (also PYTHONDEBUG=x)

-E : ignore environment variables (such as PYTHONPATH)

-h : print this help message and exit

You can also program your script in such a way that it should accept various
options. Command Line Arguments is an advanced topic and should be studied a bit
later once you have gone through rest of the Python concepts.

Python Lists

The list is a most versatile datatype available in Python which can be written
asa list of comma-separated values (items) between square brackets. Important thing
about a list is that items in a list need not be of the same type.

list1 = ['physics', 'chemistry', 1997, 2000];

list2 = [1, 2, 3, 4, 5 ];

list3 = ["a", "b", "c", "d"]

A tuple is a sequence of immutable Python objects. Tuples are sequences, just


like lists. The differences between tuples and lists are, the tuples cannot be changed
unlike lists and tuples use parentheses, whereas lists use square brackets.

Creating a tuple is as simple as putting different comma-separated values. Optionally


you can put these comma-separated values between parentheses also.

For example −
tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5 );
tup3="a","b","c","d";
20
Properties of Dictionary Keys

Dictionary values have no restrictions. They can be any arbitrary Python object,
either standard objects or user-defined objects. However, same is not dict = {'Name':
'Zara', 'Age': 7, 'Name': 'Manni'}

print "dict['Name']: ", dict['Name']

true for the keys.

2.6.2 DJANGO

Django is a high-level Python Web framework that encourages rapid


development and clean, pragmatic design. Built by experienced developers, it takes care
of much of the hassle of Web development, so you can focus on writing your app
without needing to reinvent the wheel. It’s free and open source.

Django's primary goal is to ease the creation of complex, database-driven


websites. Django emphasizes reusability and "pluggability" of components, rapid
development, and the principle of don't repeat yourself. Python is used throughout, even
for settings files and data models.

Fig 2.6.2 Django architecture

21
Django also provides an optional administrative create, read, update and delete
interface that is generated dynamically through introspection and configured viaadmin
models

Fig 2.6.3 model view template

Create a Project

Whether you are on Windows or Linux, just get a terminal or a cmd prompt and
navigate to the place you want your project to be created, then use this code −

$ django-admin startproject myproject

This will create a "myproject" folder with the following structure −

myproject/

manage.py

myproject/

init .py

settings.py

urls.py

wsgi.py

22
The Project Structure

The “myproject” folder is just your project container, it actually contains two elements−

manage.py − This file is kind of your project local django-admin for interacting with
your project via command line (start the development server, sync db...). To get a full
list of command accessible via manage.py you can use the code −

$ python manage.py help

The “myproject” subfolder − This folder is the actual python package of your
project. It contains four files −

init .py − Just for python, treat this folder as package.

settings.py − As the name indicates, your project settings.

urls.py − All links of your project and the function to call. A kind of ToC of
your project.

wsgi.py − If you need to deploy your project over WSGI.

Setting Up Your Project

Your project is set up in the subfolder myproject/settings.py. Following are some


important options you might need to set −

DEBUG = True

This option lets you set if your project is in debug mode or not. Debug mode
lets you get more information about your project's error. Never set it to ‘True’ for a live
project. However, this has to be set to ‘True’ if you want the Django light server to
serve static files. Do it only in the development mode.

DATABASES = {

'default': {

'ENGINE': 'django.db.backends.sqlite3',

'NAME': 'database.sql',

'USER': '',

23
'PASSWORD': '',

'HOST': '',

'PORT': '',

Database is set in the ‘Database’ dictionary. The example above is for SQLite
engine. As stated earlier, Django also supports −

MySQL (django.db.backends.mysql)

PostGreSQL(django.db.backends.postgresql_psycopg2)

Oracle (django.db.backends.oracle) and NoSQL DB

MongoDB (django_mongodb_engine)

Before setting any new engine, make sure you have the correct db driver installed.

You can also set others options like: TIME_ZONE, LANGUAGE_CODE,


TEMPLATE…

Now that your project is created and configured make sure it's working −

$ python manage.py runserver

You will get something like the following on running the above code −

Validating models...

0 errors found

September 03, 2015 - 11:41:50

Django version 1.6.11, using settings 'myproject.settings'

Starting development server at http://127.0.0.1:8000/

Quit the server with CONTROL-C.

24
A project is a sum of many applications. Every application has an objective and
can be reused into another project, like the contact form on a website can be an
application, and can be reused for others. See it as a module of your project.

Create an Application

We assume you are in your project folder. In our main “myproject” folder, the
same folder then manage.py −

$ python manage.py startapp myapp

You just created myapp application and like project, Django create a “myapp”
folder with the application structure −

myapp/

init .py

admin.py

models.py

tests.py

views.py

init .py − Just to make sure python handles this folder as a package.

admin.py − This file helps you make the app modifiable in the admin interface.

models.py − This is where all the application models are stored.

tests.py − This is where your unit tests are.

views.py − This is where your application views are.

Get the Project to Know About Your Application

At this stage we have our "myapp" application, now we need to register it with
our Django project "myproject". To do so, update INSTALLED_APPS tuple in the
settings.py file of your project (add your app name) −

INSTALLED_APPS = (

'django.contrib.admin',

25
'django.contrib.auth',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.messages',

'django.contrib.staticfiles',

'myapp',

Creating forms in Django, is really similar to creating a model. Here again, we


just need to inherit from Django class and the class attributes will be the form fields.
Let's add a forms.py file in myapp folder to contain our app forms. We will create a
login form.

myapp/forms.py

#-*- coding: utf-8 -*-

from django import forms

class LoginForm(forms.Form):

user = forms.CharField(max_length = 100)

password = forms.CharField(widget = forms.PasswordInput())

As seen above, the field type can take "widget" argument for html rendering; in
our case, we want the password to be hidden, not displayed. Many others widget are
present in Django: DateInput for dates, CheckboxInput for checkboxes, etc.

Using Form in a View

There are two kinds of HTTP requests, GET and POST. In Django, the request
object passed as parameter to your view has an attribute called "method" where the type
of the request is set, and all data passed via POST can be accessed via the request.POST
dictionary.

Let's create a login view in our myapp/views.py −

#-*- coding: utf-8 -*-

26
from myapp.forms import LoginForm

def login(request):

username = "not logged in"

if request.method == "POST":

#Get the posted form

MyLoginForm = LoginForm(request.POST)

if MyLoginForm.is_valid():

username = MyLoginForm.cleaned_data['username']

else:

MyLoginForm = Loginform()

return render(request, 'loggedin.html', {"username" : username})

The view will display the result of the login form posted through the
loggedin.html. To test it, we will first need the login form template.

Let's call it login.html.

<html>

<body>

<form name = "form" action = "{% url "myapp.views.login" %}"

method = "POST" >{% csrf_token %}

<div style = "max-width:470px;">

<center>

<input type = "text" style = "margin-left:20%;"

placeholder = "Identifiant" name = "username" />

</center>

</div>

<br>

27
<div style = "max-width:470px;">

<center>

<input type = "password" style = "margin-left:20%;"

placeholder = "password" name = "password" />

</center>

</div>

<br>

<div style = "max-width:470px;">

<center>

<button style = "border:0px; background-color:#4285F4; margin-top:8%;

height:35px; width:80%;margin-left:19%;" type = "submit"

value = "Login" >

<strong>Login</strong>

</button>

</center>

</div>

</form>

</body>

</html>

The template will display a login form and post the result to our login view above. You
have probably noticed the tag in the template, which is just to prevent Cross-site
Request Forgery (CSRF) attack on your site.

{% csrf_token %}

Once we have the login template, we need the loggedin.html template that will be
rendered after form treatment.

28
<html>

<body>

You are : <strong>{{username}}</strong>

</body>

</html>

Now, we just need our pair of URLs to get started: myapp/urls.py

from django.conf.urls import patterns, url

from django.views.generic import TemplateView

urlpatterns = patterns('myapp.views',

url(r'^connection/',TemplateView.as_view(template_name = 'login.html')),

url(r'^login/', 'login', name = 'login'))

When accessing "/myapp/connection", we will get the following login.html template


rendered −

Setting Up Sessions

In Django, enabling session is done in your project settings.py, by adding some


lines to the MIDDLEWARE_CLASSES and the INSTALLED_APPS options. This
should be done while creating the project, but it's always good to know, so
MIDDLEWARE_CLASSES should have −

'django.contrib.sessions.middleware.SessionMiddleware'

And INSTALLED_APPS should have −

'django.contrib.sessions'

By default, Django saves session information in database (django_session table


or collection), but you can configure the engine to store information using other ways
like: in file or in cache.

When session is enabled, every request (first argument of any view in Django) has a
session (dict) attribute.

29
Let's create a simple sample to see how to create and save sessions. We have
built a simple login system before (see Django form processing chapter and Django
Cookies Handling chapter). Let us save the username in a cookie so, if not signed out,
when accessing our login page you won’t see the login form. Basically, let's make our
login system we used in Django Cookies handling more secure, by saving cookies
server side.

For this, first lets change our login view to save our username cookie server side −

def login(request):

username = 'not logged in'

if request.method == 'POST':

MyLoginForm = LoginForm(request.POST)

if MyLoginForm.is_valid():

username = MyLoginForm.cleaned_data['username']

request.session['username'] = username

else:

MyLoginForm = LoginForm()

return render(request, 'loggedin.html', {"username" : username}

Then let us create formView view for the login form, where we won’t display
the form if cookie is set −

def formView(request):

if request.session.has_key('username'):

username = request.session['username']

return render(request, 'loggedin.html', {"username" : username})

30
else:

return render(request, 'login.html', {})

Now let us change the url.py file to change the url so it pairs with our new view −

from django.conf.urls import patterns, url


from django.views.generic import TemplateView

urlpatterns = patterns('myapp.views',
url(r'^connection/','formView', name = 'loginform'),
url(r'^login/', 'login', name = 'login'))
When accessing /myapp/connection, you will get to see the following page

31
CHAPTER 3
SYSTEM DESIGN
Software design is a mechanism to transform user requirements into some
suitable form, which helps the programmer in software coding and implementation. It
deals with representing the client's requirement, as described in SRS document, into a
form, i.e., easily implementable using programming language.

3.1 SYSTEM ARCHITECTURE

Fig-3.1 System Architecture

32
3.2 DATA FLOW DIAGRAM
1. The DFD is also called as bubble chart. It is a simple graphical formalism that
can be used to represent a system in terms of input data to the system, various
processing carried out on this data, and the output data is generated by this
system.
2. The data flow diagram (DFD) is one of the most important modeling tools. It is
used to model the system components. These components are the system
process, the data used by the process, an external entity that interacts with the
system and the information flows in the system.
3. DFD shows how the information moves through the system and how it is
modified by a series of transformations. It is a graphical technique that depicts
information flow and the transformations that are applied as data moves from
input to output.
4. DFD is also known as bubble chart. A DFD may be used to represent a system
at any level of abstraction. DFD may be partitioned into levels that represent
increasing information flow and functional detail.

33
Fig-3.2 Data Flow Diagram

34
3.3 UML DIAGRAMS
 UML stands for Unified Modeling Language. UML is a standardized general-
purpose modeling language in the field of object-oriented software engineering. The
standard is managed, and was created by, the Object Management Group.
 The goal is for UML to become a common language for creating models of object
oriented computer software. In its current form UML is comprised of two major
components: a Meta-model and a notation. In the future, some form of method or
process may also be added to; or associated with, UML.
 The Unified Modeling Language is a standard language for specifying,
Visualization, Constructing and documenting the artifacts of software system, as
well as for business modeling and other non-software systems.
 The UML represents a collection of best engineering practices that have proven
successful in the modeling of large and complex systems.
 The UML is a very important part of developing objects oriented software and the
software development process. The UML uses mostly graphical notations to
express the design of software projects.

GOALS
The Primary goals in the design of the UML are as follows:
1. Provide users a ready-to-use, expressive visual modeling Language so that they
can develop and exchange meaningful models.
2. Provide extendibility and specialization mechanisms to extend the core
concepts.
3. Be independent of particular programming languages and development process.
4. Provide a formal basis for understanding the modeling language.
5. Encourage the growth of OO tools market.
6. Support higher level development concepts such as collaborations, frameworks,
patterns and components.
7. Integrate best practices.

35
3.3.1 USE CASE DIAGRAM
A use case diagram in the Unified Modeling Language (UML) is a type of
behavioral diagram defined by and created from a Use-case analysis. Its purpose is to
present a graphical overview of the functionality provided by a system in terms of
actors, their goals (represented as use cases), and any dependencies between those use
cases. The main purpose of a use case diagram is to show what system functions are
performed for which actor. Roles of the actors in the system can be depicted.

Users Admin

Fig-3.3.1 Use Case Diagram

36
3.3.2 CLASS DIAGRAM
In software engineering, a class diagram in the Unified Modeling Language
(UML) is a type of static structure diagram that describes the structure of a system by
showing the system's classes, their attributes, operations (or methods), and the
relationships among the classes. It explains which class contains information.

User Admin
+str username +str loginid
+str pswd +str pswd
+register() +activateusers()
+datapreprocess() +addData()
+getmse()

DataPreprocess
+pandas Datafrome MLR
+model DataModel
+pandas dataframe
+hist()
+mse()
+scatterplot()
+rmse()
+cleanedata()
+correlation()

Fig-3.3.2 Class Diagram

37
3.3.3 SEQUENCE DIAGRAM
A sequence diagram in Unified Modeling Language (UML) is a kind of
interaction diagram that shows how processes operate with one another and in what
order. It is a construct of a Message Sequence Chart. Sequence diagrams are
sometimes called event diagrams, event scenarios, and timing diagrams.

User Admin Data Preproces MLR

1 : Register()

2 : Activated()

3 : Start Pr eprocess()

4 : search by ci tyof weather()

5 : hist graph()

6 : ploted graph()

7 : confusion matrix()

8 : predections()

9 : mse()

10 : rmse()

11 : result displayed()

Fig-3.3.3 Sequence Diagram

38
3.3.4 ACTIVITY DIAGRAM
Activity diagrams are graphical representations of workflows of stepwise
activities and actions with support for choice, iteration and concurrency. In the Unified
Modeling Language, activity diagrams can be used to describe the business and
operational step-by-step workflows of components in a system. An activity diagram
shows the overall flow of control.

Fig-3.3.4 Activity Diagram

39
CHAPTER 4
IMPLEMENTATION
Implementation is a realization of a technical specification or algorithm as a
program, software component. The translated code may either be directly executed by
hardware, or serve as input to another interpreter or another compiler.

4.1 MODULES

 User
 Admin
 Data preprocess
 Multiple Linear Regression (MLR)

1. User:
The User can register the first. While registering he required a valid user email
and mobile for further communications. Once the user register then admin can activate
the customer. Once admin activated the customer then customer can login into our
system. After login he can search the weather report based on city.
For searching the weather report we use open weather map api. The rest
connection we are sending to the server and it will return the json data. The json data
we are parsing and required information converted into python dictionary sent to the
user side. Once it done then the user can perform the preprocess operations. The hist
diagram plot diagram are displayed based on the data.

2. Admin:
Admin can login with his credentials. Once he login he can activate the users.
The activated user only login in our applications. The admin can set the data set by
Indian metrological weather report. In this report the data has consider as monthly wise
and yearly quarterly wise.
The admin can add new data to the dataset. So this data user can perform the
testing process. The admin can view data based on paginations. The total paginations
will be displayed on the browser.

40
3. Data Preprocess:
The admin provided data has been stored in the sqlite database. To process our
methodology we need to perform data cleaning process. By using pandas data frame
we can fill the missing values with its mean type. Once data cleaned the hist diagram
will be displayed.
This hist diagram, is monthly wise will be displayed. Alter monthly wise bar
graph and quarter wise bar graph will be displayed. Then we are calculating the
confusion matrix of the selected model. Once its done the user can see the cleaned data
in the browser.

4. Multiple Linear Regression


The number of observation is indicated by n. The dependent variable is yi and
the descriptive variable is xi. β0 and βp are the constant y intercept and slop of
descriptive variable respectively. Model error is indicated by €. In the proposed model
multiple meteorological parameters are necessary to predict the rain fall, it is better to
use the multiple linear regression instead of simple linear regression. The assumptions
which are made by the multiple linear regression are:
linear relationship between the both the descriptive and independent variables,
the highly correlated variables are independent variables, yi is calculated randomly and
the mean and variance are 0 and σ. By using this formula

formula we can calculate the Mease Square Error ,


root meas square errors. Those result we displayed in the browsers.

41
4.2 INPUT DESIGN

The input design is the link between the information system and the user. It
comprises the developing specification and procedures for data preparation and those
steps are necessary to put transaction data in to a usable form for processing can be
achieved by inspecting the computer to read data from a written or printed document or
it can occur by having people keying the data directly into the system. The design of
input focuses on controlling the amount of input required, controlling the errors,
avoiding delay, avoiding extra steps and keeping the process simple. The input is
designed in such a way so that it provides security and ease of use with retaining the
privacy.

Input Design considered the following things:

 What data should be given as input?


 How the data should be arranged or coded?
 The dialog to guide the operating personnel in providing input.
 Methods for preparing input validations and steps to follow when error occur.

OBJECTIVES

1. Input Design is the process of converting a user-oriented description of

the input into a computer-based system. This design is important to avoid errors in the
data input process and show the correct direction to the management for getting correct
information from the computerized system.

2. It is achieved by creating user-friendly screens for the data entry to handle

large volume of data. The goal of designing input is to make data entry easier and to be
free from errors. The data entry screen is designed in such a way that all the data
manipulates can be performed. It also provides record viewing facilities.

3. When the data is entered it will check for its validity. Data can be entered

with the help of screens. Appropriate messages are provided as when needed so that the
user will not be in maize of instant. Thus the objective of input design is to create an
input layout that is easy to follow

42
4.3 OUTPUT DESIGN

A quality output is one, which meets the requirements of the end user and
presents the information clearly. In any system results of processing are communicated
to the users and to other system through outputs. In output design it is determined how
the information is to be displaced for immediate need and also the hard copy output. It
is the most important and direct source information to the user. Efficient and intelligent
output design improves the system’s relationship to help user decision-making.

1. Designing computer output should proceed in an organized, well thought out


manner; the right output must be developed while ensuring that each output element is
designed so that people will find the system can use easily and effectively. When
analysis design computer output, they should Identify the specific output that is needed
to meet the requirements.

2. Select methods for presenting information.

3. Create document, report, or other formats that contain information produced


by the system.

The output form of an information system should accomplish one or more of


the following objectives.

 Convey information about past activities, current status or projections of the


 Future.
 Signal important events, opportunities, problems, or warnings.
 Trigger an action.
 Confirm an action.

43
4.4 SOURCE CODE

GeneratePltGraph.py

import matplotlib.pyplot as plt


import seaborn as sns; sns.set()
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_absolute_error
from sklearn.preprocessing import StandardScaler
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
from sklearn import metrics
import os
import matplotlib
matplotlib.use('TKAgg')
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath( file )))
def plot_graphs(groundtruth, prediction, title):
N=9
ind = np.arange(N) # the x locations for the groups
width = 0.27 # the width of the bars
fig = plt.figure()
fig.suptitle(title, fontsize=12)
ax = fig.add_subplot(111)
rects1 = ax.bar(ind, groundtruth, width, color='r')
rects2 = ax.bar(ind + width, prediction, width, color='g')
ax.set_ylabel("Amount of rainfall")
ax.set_xticks(ind + width)
ax.set_xticklabels(('APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'))
ax.legend((rects1[0], rects2[0]), ('Ground truth', 'Prediction'))

# autolabel(rects1)
for rect in rects1:
h = rect.get_height()
ax.text(rect.get_x() + rect.get_width() / 2., 1.05 * h, '%d' % int(h),
ha='center', va='bottom')

44
for rect in rects2:
h = rect.get_height()
ax.text(rect.get_x() + rect.get_width() / 2., 1.05 * h, '%d' % int(h),
ha='center', va='bottom')
# autolabel(rects2)
# os.path.join(BASE_DIR, 'assets/templates')
plt.savefig(os.path.join(BASE_DIR, 'assets/static/graphs/') + title + "." + 'png')
plt.show()
plt.close()

class GeneratePltGraph:
def preProcessGraphs(self,data):
data = data.fillna(data.mean())
data.info()
print(data.head())
print(data.describe())
# plt.savefig('models_accuracy.png') #for Saving pic
# plt.savefig('figure1.png',data.hist(figsize=(24, 24)))
data.hist(figsize=(24, 24));
#plt.savefig('hist.png')
data.groupby("YEAR").sum()['ANNUAL'].plot(figsize=(12, 8));
data[['YEAR', 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP',
'OCT', 'NOV', 'DEC']].groupby(
"YEAR").sum().plot(figsize=(13, 8));
data[['YEAR', 'JanToFeb', 'MarToMay', 'JunToSep',
'OctToDec']].groupby("YEAR").sum().plot(figsize=(13, 8));
data[['SUBDIVISION', 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG',
'SEP', 'OCT', 'NOV',
'DEC']].groupby("SUBDIVISION").mean().plot.barh(stacked=True,
figsize=(13, 8));
data[['SUBDIVISION', 'JanToFeb', 'MarToMay', 'JunToSep',
'OctToDec']].groupby("SUBDIVISION").sum().plot.barh(
stacked=True, figsize=(16, 8));
plt.figure(figsize=(11, 4))

45
sns.heatmap(data[['JanToFeb', 'MarToMay', 'JunToSep', 'OctToDec',
'ANNUAL']].corr(), annot=True)
plt.show()
plt.figure(figsize=(11, 4))
sns.heatmap(
data[['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT',
'NOV', 'DEC', 'ANNUAL']].corr(),
annot=True)
plt.show()
plt.close()
def genMlrCodes(self,data):
# seperation of training and testing data
division_data = np.asarray(
data[['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT',
'NOV', 'DEC']])
X = None;
y = None
for i in range(division_data.shape[1] - 3):
if X is None:
X = division_data[:, i:i + 3]
y = division_data[:, i + 3]
else:
X = np.concatenate((X, division_data[:, i:i + 3]), axis=0)
y = np.concatenate((y, division_data[:, i + 3]), axis=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1,
random_state=42)
# test 2010
temp = data[['SUBDIVISION', 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL',
'AUG', 'SEP', 'OCT', 'NOV', 'DEC']].loc[data['YEAR'] == 2010]
data_2010 = np.asarray(temp[['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL',
'AUG', 'SEP', 'OCT', 'NOV',
'DEC']].loc[temp['SUBDIVISION'] == 'TELANGANA'])
X_year_2010 = None;
y_year_2010 = None

46
for i in range(data_2010.shape[1] - 3):
if X_year_2010 is None:
X_year_2010 = data_2010[:, i:i + 3]
y_year_2010 = data_2010[:, i + 3]
else:
X_year_2010 = np.concatenate((X_year_2010, data_2010[:, i:i + 3]),
axis=0)
y_year_2010 = np.concatenate((y_year_2010, data_2010[:, i + 3]), axis=0)
# test 2005
temp = data[['SUBDIVISION', 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL',
'AUG', 'SEP', 'OCT', 'NOV', 'DEC']].loc[data['YEAR'] == 2005]
data_2005 = np.asarray(temp[['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL',
'AUG', 'SEP', 'OCT', 'NOV',
'DEC']].loc[temp['SUBDIVISION'] == 'TELANGANA'])
X_year_2005 = None;
y_year_2005 = None
for i in range(data_2005.shape[1] - 3):
if X_year_2005 is None:
X_year_2005 = data_2005[:, i:i + 3]
y_year_2005 = data_2005[:, i + 3]
else:
X_year_2005 = np.concatenate((X_year_2005, data_2005[:, i:i + 3]),
axis=0)
y_year_2005 = np.concatenate((y_year_2005, data_2005[:, i + 3]), axis=0)
# terst 2015
temp = data[['SUBDIVISION', 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL',
'AUG', 'SEP', 'OCT', 'NOV', 'DEC']].loc[data['YEAR'] == 2015]
data_2015 = np.asarray(temp[['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL',
'AUG', 'SEP', 'OCT', 'NOV',
'DEC']].loc[temp['SUBDIVISION'] == 'TELANGANA'])
X_year_2015 = None;
y_year_2015 = None
for i in range(data_2015.shape[1] - 3):
if X_year_2015 is None:

47
X_year_2015 = data_2015[:, i:i + 3]
y_year_2015 = data_2015[:, i + 3]
else:
X_year_2015 = np.concatenate((X_year_2015, data_2015[:, i:i + 3]),
axis=0)
y_year_2015 = np.concatenate((y_year_2015, data_2015[:, i + 3]), axis=0)
from sklearn import linear_model
# linear model
reg = linear_model.ElasticNet(alpha=0.5)
reg.fit(X_train, y_train)
y_pred = reg.predict(X_test)
print(mean_absolute_error(y_test, y_pred))
y_year_pred_2005 = reg.predict(X_year_2005)
# 2010
y_year_pred_2010 = reg.predict(X_year_2010)
y_year_pred_2015 = reg.predict(X_year_2015)
print("MEAN 2005")
print(np.mean(y_year_2005), np.mean(y_year_pred_2005))
print("Standard deviation 2005")
print(np.sqrt(np.var(y_year_2005)), np.sqrt(np.var(y_year_pred_2005)))
print("MEAN 2010")
print(np.mean(y_year_2010), np.mean(y_year_pred_2010))
print("Standard deviation 2010")
print(np.sqrt(np.var(y_year_2010)), np.sqrt(np.var(y_year_pred_2010)))
print("MEAN 2015")
print(np.mean(y_year_2015), np.mean(y_year_pred_2015))
print("Standard deviation 2015")
print(np.sqrt(np.var(y_year_2015)), np.sqrt(np.var(y_year_pred_2015)))
plot_graphs(y_year_2005, y_year_pred_2005, "Year-2005")
plot_graphs(y_year_2010, y_year_pred_2010, "Year-2010")
plot_graphs(y_year_2015, y_year_pred_2015, "Year-2015")
plt.close()
def testMltMSE(self,data):
rsltdict = {}

48
X = data['JAN'].values
y = data['DEC'].values
X = X.reshape(-1, 1)
y = y.reshape(-1, 1)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1,
random_state=42)
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train)
y_pred = regressor.predict(X_test)
# print('Predection result ',y_pred)
# print('Test ',X_test)
mse = metrics.mean_squared_error(y_test, y_pred)
rmse = np.sqrt(mse)
lrcorr = regressor.coef_
lcoe = sum(lrcorr) / len(lrcorr)
rsltdict.update({'lgmse': mse, 'lgrmse': rmse, 'lgcorr': lcoe})
accuracy = metrics.accuracy_score(y_test.round(), y_pred.round(),
normalize=False)
# print('LR accuracy ', accuracy)
# print(mse, "==", rmse)
division_data = np.asarray(data[['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
'JUL',
'AUG', 'SEP', 'OCT', 'NOV', 'DEC']])
X = None;
y = None
for i in range(division_data.shape[1] - 3):
if X is None:
X = division_data[:, i:i + 3]
y = division_data[:, i + 3]
else:
X = np.concatenate((X, division_data[:, i:i + 3]), axis=0)
y = np.concatenate((y, division_data[:, i + 3]), axis=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1,

49
random_state=42)
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train)
y_pred = regressor.predict(X_test)
# print('Predection result ',y_pred)
# print('Test ',X_test)
mse = metrics.mean_squared_error(y_test, y_pred)
rmse = np.sqrt(mse)
mlrco = regressor.coef_
mlrcorre = sum(mlrco) / len(mlrco)
# accuracy = metrics.accuracy_score(y_test.round(),
y_pred.round(),normalize=False)
# print('MLR accuracy ',accuracy)
print(mse, "==", rmse)
# plt.scatter(x=y_test, y=y_pred, c="red")
# plt.show()
rsltdict.update({'mlrmse': mse, 'mlrrmse': rmse, 'mlrcorr': lcoe})

####QPF CODE
from keras.models import Model
from keras.layers import Dense, Input, Conv1D, Flatten
# NN model
inputs = Input(shape=(3, 1))
x = Conv1D(64, 2, padding='same', activation='elu')(inputs)
x = Conv1D(128, 2, padding='same', activation='elu')(x)
x = Flatten()(x)
x = Dense(128, activation='elu')(x)
x = Dense(64, activation='elu')(x)
x = Dense(32, activation='elu')(x)
x = Dense(1, activation='linear')(x)
model = Model(inputs=[inputs], outputs=[x])
model.compile(loss='mean_squared_error', optimizer='adamax', metrics=['mae'])
model.summary()

50
model.fit(x=np.expand_dims(X_train, axis=2), y=y_train, batch_size=64,
epochs=10, verbose=1,
validation_split=0.1,
shuffle=True)
y_pred = model.predict(np.expand_dims(X_test, axis=2))
qmse = metrics.mean_squared_error(y_test, y_pred)
qrmse = np.sqrt(qmse)
print('Qmse = ', qmse, " QRmse=", qrmse)
qcorr = qmse / qrmse
rsltdict.update({'qpfmse': qmse, 'qpfrmse': qrmse, 'qpfcorr': qcorr})
# accuracy = metrics.accuracy_score(y_test.round(),
y_pred.round(),normalize=False)
# print('QPF accuracy ',accuracy)
plt.close()
return rsltdict

users side views.py

import math
from django.shortcuts import render,HttpResponse
from sklearn.model_selection import train_test_split
from .forms import UserRegistrationForm
import requests
from django.contrib import messages
from .forms import UserRegistrationForm
from .models import RainFallUserRegistrationModel,IndiaRainFallDataModel
import io,csv
from django_pandas.io import read_frame
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
from sklearn.preprocessing import StandardScaler
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
from sklearn import metrics

51
import os
from .GenGraphCode import GeneratePltGraph
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath( file )))
# Create your views here.
def UserLogin(request):
return render(request,'UserLogin.html',{})
def UserRegister(request):
form = UserRegistrationForm()
return render(request,'UserRegisterForm.html',{'form':form})
def GetWeatherInfo(request):
if request.method == 'POST':
city = request.POST.get('cityname')
accesKey = '9c5781db8bb4ee7c96f7dee77728e353'
url =
'http://api.openweathermap.org/data/2.5/weather?q={}&units=imperial&appid=9c578
1db8bb4ee7c96f7dee77728e353'
#city = 'Las Vegas'
city_weather = requests.get( url.format(city)).json() # request the API data and
convert the JSON to Python data types
print("Weather info ",city_weather)
weather = {
'city': city,
'temperature': city_weather['main']['temp'],
'description': city_weather['weather'][0]['description'],
'icon': city_weather['weather'][0]['icon'],
#'message':city_weather['message']
}
context = {'weather': weather}
return render(request, 'weatherinfo.html', context)
def UserRegisterAction(request):
if request.method == 'POST':
form = UserRegistrationForm(request.POST)
if form.is_valid():
print('Data is Valid')

52
form.save()
messages.success(request, 'You have been successfully registered')
# return HttpResponseRedirect('./CustLogin')
form = UserRegistrationForm()
return render(request, 'UserRegisterForm.html', {'form': form})
else:
print("Invalid form")
else:
form = UserRegistrationForm()
return render(request, 'UserRegisterForm.html', {'form': form})
def UserLoginCheck(request):
if request.method == "POST":
loginid = request.POST.get('loginid')
pswd = request.POST.get('pswd')
print("Login ID = ", loginid, ' Password = ', pswd)
try:
check = RainFallUserRegistrationModel.objects.get(loginid=loginid,
password=pswd)
status = check.status
print('Status is = ', status)
if status == "activated":
request.session['id'] = check.id
request.session['loggeduser'] = check.name
request.session['loginid'] = loginid
request.session['email'] = check.email
print("User id At", check.id, status)
return render(request, 'users/UserHomePage.html', {})
else:
messages.success(request, 'Your Account Not at activated')
return render(request, 'UserLogin.html')
# return render(request, 'user/userpage.html',{})
except Exception as e:
print('Exception is ', str(e))
pass

53
messages.success(request, 'Invalid Login id and password')
return render(request, 'UserLogin.html', {})
def GetWeatherInfo(request):
if request.method == 'POST':
city = request.POST.get('cityname')
accesKey = '9c5781db8bb4ee7c96f7dee77728e353'
url =
'http://api.openweathermap.org/data/2.5/weather?q={}&units=imperial&appid=9c578
1db8bb4ee7c96f7dee77728e353'
city_weather = requests.get( url.format(city)).json() # request the API data and
convert the JSON to Python data types
print("Weather info ",city_weather)
code = city_weather['cod']
if code==200:
print('Data valid')
else:
messages.success(request, 'Data Not Found')
return render(request, 'users/GetWeatherInfo.html', {})
print('Status code ',code)
weather = {
'city': city,
'temperature': city_weather['main']['temp'],
'description': city_weather['weather'][0]['description'],
'icon': city_weather['weather'][0]['icon'],
#'message':city_weather['message']
}
context = {'weather': weather}
return render(request, 'users/GetWeatherInfo.html', context)
def SearchByCity(request):
return render(request,'users/SearchByCity.html',{})
def UserUploadData(request):
return render(request,'users/uploaddata.html',{})
def UploadCSVToDataBase(request):

54
# declaring template
template = "users/UserHomePage.html"
data = IndiaRainFallDataModel.objects.all()
# prompt is a context variable that can have different values depending on their
context
prompt = {
'order': 'Order of the CSV should be name, email, address, phone, profile',
'profiles': data
}
# GET request returns the value of the data with the specified key.
if request.method == "GET":
return render(request, template, prompt)
csv_file = request.FILES['file']
# let's check if it is a csv file
if not csv_file.name.endswith('.csv'):
messages.error(request, 'THIS IS NOT A CSV FILE')
data_set = csv_file.read().decode('UTF-8')
# setup a stream which is when we loop through each line we are able to handle a
data in a stream
io_string = io.StringIO(data_set)
next(io_string)
for column in csv.reader(io_string, delimiter=',', quotechar="|"):
_, created = IndiaRainFallDataModel.objects.update_or_create(
SUBDIVISION=column[0],
YEAR=column[1],
JAN=column[2],
FEB=column[3],
MAR=column[4],
APR=column[5],
MAY=column[6],
JUN=column[7],
JUL=column[8],
AUG=column[9],

55
SEP=column[10],
OCT=column[11],
NOV=column[12],
DEC=column[13],
ANNUAL=column[14],
JanToFeb=column[15],
MarToMay=column[16],
JunToSep=column[17],
OctToDec=column[18]
)
context = {}
return render(request, 'users/UserHomePage.html', context)
def UserDataPreProcess(request):
qs = IndiaRainFallDataModel.objects.all()
data = read_frame(qs)
g = GeneratePltGraph()
g.preProcessGraphs(data)
return render(request,'users/PreProcessedData.html',{'data':qs})
def UserMLRCode(request):
qs = IndiaRainFallDataModel.objects.all()
data = read_frame(qs)
gf = GeneratePltGraph()
gf.genMlrCodes(data)
return render(request,'users/UsersMachineLearningGraphs.html',{})
def TestMlR(request):
qs = IndiaRainFallDataModel.objects.all()
data = read_frame(qs)
gh = GeneratePltGraph()
rsltdict = gh.testMltMSE(data)
return render(request,"users/MlrTestResult.html",rsltdict)

56
user side models.py

from django.db import models


# Create your models here.
class RainFallUserRegistrationModel(models.Model):
name = models.CharField(max_length=100)
loginid = models.CharField(unique=True,max_length=100)
password = models.CharField(max_length=100)
mobile = models.CharField(max_length=100)
email = models.CharField(max_length=100)
locality = models.CharField(max_length=100)
address = models.CharField(max_length=1000)
city = models.CharField(max_length=100)
state = models.CharField(max_length=100)
status = models.CharField(max_length=100)
def str (self):
return self.loginid
class Meta:
db_table='RainFallUsers'
class IndiaRainFallDataModel(models.Model):
SUBDIVISION = models.CharField(max_length=100)
YEAR = models.IntegerField()
JAN = models.FloatField(default=0.0);
FEB = models.FloatField(default=0.0);
MAR = models.FloatField(default=0.0);
APR = models.FloatField(default=0.0);
MAY = models.FloatField(default=0.0);
JUN = models.FloatField(default=0.0);
JUL = models.FloatField(default=0.0);
AUG = models.FloatField(default=0.0);
SEP = models.FloatField(default=0.0);
OCT = models.FloatField(default=0.0);
NOV = models.FloatField(default=0.0);
DEC = models.FloatField(default=0.0);

57
ANNUAL = models.FloatField(default=0.0);
JanToFeb = models.FloatField(default=0.0);
MarToMay = models.FloatField(default=0.0);
JunToSep = models.FloatField(default=0.0);
OctToDec = models.FloatField(default=0.0);
def str (self):
return self.SUBDIVISION
class Meta:
db_table = 'IndianRainfall'

user side forms.py

from django import forms


from .models import RainFallUserRegistrationModel
class UserRegistrationForm(forms.ModelForm):
name = forms.CharField(widget=forms.TextInput(attrs={'pattern':'[a-zA-Z]+'}),
required=True,max_length=100)
loginid = forms.CharField(widget=forms.TextInput(attrs={'pattern':'[a-zA-Z]+'}),
required=True,max_length=100)
password =
forms.CharField(widget=forms.PasswordInput(attrs={'pattern':'(?=.*\d)(?=.*[a-
z])(?=.*[A-Z]).{8,}','title':'Must contain at least one number and one uppercase and
lowercase letter, and at least 8 or more characters'}), required=True,max_length=100)
mobile = forms.CharField(widget=forms.TextInput(attrs={'pattern':'[56789][0-
9]{9}'}), required=True,max_length=100)
email = forms.CharField(widget=forms.TextInput(attrs={'pattern':'[a-z0-9._%+-
]+@[a-z0-9.-]+\.[a-z]{2,}$'}), required=True,max_length=100)
locality = forms.CharField(widget=forms.TextInput(),
required=True,max_length=100)
address = forms.CharField(widget=forms.Textarea(attrs={'rows':4, 'cols': 22}),
required=True,max_length=250)
city = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control' ,
'autocomplete': 'off','pattern':'[A-Za-z ]+', 'title':'Enter Characters Only '}),
required=True,max_length=100)
state = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control' ,

58
'autocomplete': 'off','pattern':'[A-Za-z ]+', 'title':'Enter Characters Only '}),
required=True,max_length=100)
status = forms.CharField(widget=forms.HiddenInput(), initial='waiting'
,max_length=100)
class Meta():
model = RainFallUserRegistrationModel
fields=' all '

admin side views.py

from django.shortcuts import render,HttpResponse


from django.contrib import messages
# Create your views here.
from users.models import RainFallUserRegistrationModel,IndiaRainFallDataModel
from .forms import IndiaRainFallDataForm
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
def AdminLogin(request):
return render(request,'AdminLogin.html',{})
def AdminLoginCheck(request):
if request.method == 'POST':
usrid = request.POST.get('loginname')
pswd = request.POST.get('pswd')
print("User ID is = ", usrid)
if usrid == 'admin' and pswd == 'admin':
return render(request, 'admins/AdminHome.html')
else:
messages.success(request, 'Please Check Your Login Details')
return render(request, 'AdminLogin.html', {})
def AdminViewUsers(request):
data = RainFallUserRegistrationModel.objects.all()
return render(request,'admins/AdminViewUsers.html',{'data':data})
def AdminActivaUsers(request):
if request.method == 'GET':
id = request.GET.get('uid')
status = 'activated'

59
print("PID = ", id, status)
RainFallUserRegistrationModel.objects.filter(id=id).update(status=status)
data = RainFallUserRegistrationModel.objects.all()
return render(request,'admins/AdminViewUsers.html',{'data':data})
def AdminAddData(request):
if request.method == 'POST':
form = IndiaRainFallDataForm(request.POST)
if form.is_valid():
print('Data is Valid')
form.save()
messages.success(request, 'Data Added Successfull')
form = IndiaRainFallDataForm()
return render(request, 'admins/AddRainFallData.html', {'form': form})
else:
print("Invalid form")
else:
form = IndiaRainFallDataForm()
return render(request, 'admins/AddRainFallData.html', {'form': form})
def AdminViewData(request):
data_list = IndiaRainFallDataModel.objects.all()
page = request.GET.get('page', 1)
paginator = Paginator(data_list, 60)
try:
users = paginator.page(page)
except PageNotAnInteger:
users = paginator.page(1)
except EmptyPage:
users = paginator.page(paginator.num_pages)
return render(request, 'admins/AdminViewWeather.html', {'users': users})

60
base.html

{%load static%}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-
scale=1.0,maximum-scale=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></scr
ipt>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<title>Compass Starter by India, Rian</title>
<link href="http://fonts.googleapis.com/css?family=Roboto:300,400,700|"
rel="stylesheet" type="text/css">
<link href="{%static 'fonts/font-awesome.min.css'%}" rel="stylesheet"
type="text/css">
<link rel="stylesheet" href="{%static 'style.css'%}">
</head>
<body>
<div class="site-content">
<div class="site-header">
<div class="container">
<a href="index.html" class="branding">
<img src="{%static 'images/logo.png'%}" alt="" class="logo">
<div class="logo-type">

61
<h1 class="site-title">Rainfall Prediction</h1>
<small class="site-description">Machine Learning based</small>
</div>
</a>

<!-- Default snippet for navigation -->


<div class="main-navigation">
<button type="button" class="menu-toggle"><i class="fa fa-
bars"></i></button>
<ul class="menu">
<li class="menu-item"><a href="{%url 'index'%}">Home</a></li>
<li class="menu-item"><a href="{%url 'UserLogin'%}">Users</a></li>
<li class="menu-item"><a href="{%url
'AdminLogin'%}">Admins</a></li>
<li class="menu-item"><a href="{%url
'UserRegister'%}">Register</a></li>
</ul>
</div>
<div class="mobile-navigation"></div>
</div>
</div> <!-- .site-header -->
<div class="hero" data-bg-image="{%static 'images/banner1.png'%}">
<div class="container">
{%block contents%}
{%endblock%}
</div>
</div>
<footer class="site-footer">
<div class="container">
<div class="row">
<div class="col-md-8">
</div>
<div class="col-md-3 col-md-offset-1">
</div>

62
</div>
<p class="colophon">Copyright 2020 Alex Corporation. Designed by Alex.
All rights reserved</p>
</div>
</footer> <!-- .site-footer -->
</div>
<script src="{%static 'js/jquery-1.11.1.min.js'%}"></script>
<script src="{%static 'js/plugins.js'%}"></script>
<script src="{%static 'js/app.js'%}"></script>
</body>
</html>
userregisterform.html

{%extends 'base.html'%}
{%block contents %}
<center>
<p>
<form method="POST" action="{%url 'UserRegisterAction'%}" >
{% csrf_token %}
<h2>User Register Form</h2>
<table>
<tr><td>Customer Name</td><td>{{form.name}}</td></tr>
<tr><td>Login ID</td><td>{{form.loginid}}</td></tr>
<tr><td>Password</td><td>{{form.password}}</td></tr>
<tr><td>Mobile</td><td>{{form.mobile}}</td></tr>
<tr><td>email</td><td>{{form.email}}</td></tr>
<tr><td>Locality</td><td>{{form.locality}}</td></tr>
<tr><td>Address</td><td>{{form.address}}</td></tr>
<tr><td>City</td><td>{{form.city}}</td></tr>
<tr><td>State</td><td>{{form.state}}</td></tr>
<tr><td></td><td>{{form.status}}</td></tr>
<tr><td><button class="btn btn-primary my-2 my-sm-0" type="submit"
style = "margin-left:20%;">Register</button></td></tr>
{% if messages %}

63
{% for message in messages %}
<font color='GREEN'> {{ message }}</font>
{% endfor %}
{% endif %}
</table>
</form>
</p>
</center>
{%endblock%}

Urls.py

"""RainfallPredection URL Configuration


The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from RainfallPredection import views as mainView
from users import views as usr
from admins import views as admns
urlpatterns = [
path('admin/', admin.site.urls),
path('', mainView.index, name='index'),
path('Logout/',mainView.Logout,name='Logout'),

64
### User Side all urs
path('UserLogin/',usr.UserLogin,name='UserLogin'),
path('UserRegister/',usr.UserRegister,name='UserRegister'),
path('GetWeatherInfo/',usr.GetWeatherInfo,name='GetWeatherInfo'),
path('UserRegisterAction/',usr.UserRegisterAction,name='UserRegisterAction'),
path('UserLoginCheck/',usr.UserLoginCheck, name='UserLoginCheck'),
path('GetWeatherInfo/',usr.GetWeatherInfo, name='GetWeatherInfo'),
path('SearchByCity/',usr.SearchByCity, name='SearchByCity'),
path('UserUploadData/',usr.UserUploadData,name='UserUploadData'),
path('UploadCSVToDataBase/', usr.UploadCSVToDataBase,
name='UploadCSVToDataBase'),
path('UserDataPreProcess/',usr.UserDataPreProcess, name='UserDataPreProcess'),
path('UserMLRCode/',usr.UserMLRCode,name='UserMLRCode'),
path('TestMlR/',usr.TestMlR, name='TestMlR'),

### Admins side urls


path('AdminLogin/',admns.AdminLogin,name='AdminLogin'),
path('AdminLoginCheck/',admns.AdminLoginCheck,name='AdminLoginCheck'),
path('AdminViewUsers/', admns.AdminViewUsers, name='AdminViewUsers'),
path('AdminActivaUsers/',admns.AdminActivaUsers,name='AdminActivaUsers'),
path('AdminAddData/',admns.AdminAddData,name='AdminAddData'),
path('AdminViewData/',admns.AdminViewData,name='AdminViewData'),
]

65
CHAPTER 5
RESULTS
The information that they get from users is called input, and the information
that they give to users is called output. The input and output is the result of the
proposed model.

INPUT AND OUTPUT SCREENS

Fig-5.1 Home Page

Fig-5.2 User Register Form


66
Fig-5.3 Admin Login

Fig-5.4 Admin Home Page

67
Fig-5.5 View Registered Users

Fig-5.6 Adding Data To Dataset

68
Fig-5.7 Admin View Data

Fig-5.8 User Login Page

69
Fig-5.9 User Home Page

Fig-5.10 Getting Current Weather Report

70
Fig-5.11 Report

Fig-5.12 Dataset Hist Graph

71
Fig-5.13 Monthly Wise Correlated Graph

Fig-5.14 correlated Graph

72
Fig-5.15 State wise Graph

Fig-5.16 State wise Graph

73
Fig-5.17 Confusion Matrix

Fig-5.18 Monthly Wise Confusion Matrix

74
Fig-5.19 Preprocessed Data

Fig-5.20 Prediction Result

75
Fig-5.21 Epoch Running

Fig-5.22 MLR Result

76
CHAPTER 6
SYSTEM TESTING
The purpose of testing is to discover errors. Testing is the process of trying to
discover every conceivable fault or weakness in a work product. It provides a way to
check the functionality of components, sub assemblies, assemblies and/or a finished
product.

It is the process of exercising software with the intent of ensuring that the
Software system meets its requirements and user expectations and does not fail in an
unacceptable manner. There are various types of test. Each test type addresses a specific
testing requirement.

6.1 SAMPLE TEST CASES

Excepted Remarks(IF
S.no Test Case Result
Result Fails)

If already user
If User
1. User Register Pass email exist then
registration
it fails.
successfully.
If User name
and password is Un Register
2. User Login correct then it Pass Users will not
will getting logged in.
valid page.
According to
India
metrological
A new record
Admin Add repository the
3. will added to Pass
the Data data must be
our dataset.
float fields
otherwise its
failed.

77
The data will
be in int or float
format,
Data will be
4. Data Cleaning otherwise
cleaned.
Pass algorithm will
not work..
If data not
Hist diagram
cleaned or NA
5. Hist digram generated bsed Pass
then it give you
on months
an error

Admin dd Data added to


Data will be
6. extra records Pass test data for
consider for
for testing model.
testing purpose.
Means
square error Data is consider
7. Calculate MSE Pass
calculated and for testing.
displayed
Root Mean RootMeans Root
8. Square Error Square Pass Meansquare
calculation calculated calculated
Admin can
login with his
Invalid login
login
9. Admin login Pass details will not
credential. If
allowed here
success he get
his home page

Admin can If user id not


Admin can
activate the Pass found then it
10. activate the
register users won’t login.
register user id

Table 6.1- Sample Test Cases

78
TYPES OF TESTS

There are various types of test. Each test type addresses a specific testing
requirement, as discussed below.

6.2 UNIT TESTING

Unit testing involves the design of test cases that validate that the internal
program logic is functioning properly, and that program inputs produce valid outputs.
All decision branches and internal code flow should be validated. It is the testing of
individual software units of the application .it is done after the completion of an
individual unit before integration.

This is a structural testing, that relies on knowledge of its construction and is


invasive. Unit tests perform basic tests at component level and test a specific business
process, application, and/or system configuration. Unit tests ensure that each unique
path of a business process performs accurately to the documented specifications and
contains clearly defined inputs and expected results.

6.3 INTEGRATION TESTING

Integration tests are designed to test integrated software components to


determine if they actually run as one program. Testing is event driven and is more
concerned with the basic outcome of screens or fields. Integration tests demonstrate that
although the components were individually satisfaction, as shown by successfullyunit
testing, the combination of components is correct and consistent. Integration testing is
specifically aimed at exposing the problems that arise from the combination of
components.

6.4 FUNCTIONAL TEST

Functional tests provide systematic demonstrations that functions tested are


available as specified by the business and technical requirements, system
documentation, and user manuals.

Functional testing is centered on the following items:

Valid Input : identified classes of valid input must be accepted.

Invalid Input : identified classes of invalid input must be rejected.

79
Functions : identified functions must be exercised.

Output : identified classes of application outputs must be exercised.

Systems/Procedures : interfacing systems or procedures must be invoked.

Organization and preparation of functional tests is focused on requirements, key


functions, or special test cases. In addition, systematic coverage pertaining to identify
Business process flows; data fields, predefined processes, and successive processes
must be considered for testing. Before functional testing is complete, additional tests
are identified and the effective value of current tests is determined.

 System Test

System testing ensures that the entire integrated software system meets
requirements. It tests a configuration to ensure known and predictable results. An
example of system testing is the configuration oriented system integration test. System
testing is based on process descriptions and flows, emphasizing pre-driven process links
and integration points.

6.5 WHITE BOX TESTING

White Box Testing is a testing in which in which the software tester has
knowledge of the inner workings, structure and language of the software, or at least its
purpose. It is purpose. It is used to test areas that cannot be reached from a black box
level.

6.6 BLACK BOX TESTING

Black Box Testing is testing the software without any knowledge of the inner
workings, structure or language of the module being tested. Black box tests, as most
other kinds of tests, must be written from a definitive source document, such as
specification or requirements document, such as specification or requirements
document. It is a testing in which the software under test is treated, as a black box .you
cannot “see” into it. The test provides inputs and responds to outputs without
considering how the software works.

80
6.7 UNIT TESTING

Unit testing is usually conducted as part of a combined code and unit test phase
of the software lifecycle, although it is not uncommon for coding and unit testing to be
conducted as two distinct phases.

Test strategy and approach

Field testing will be performed manually and functional tests will be written
in detail.

Test objectives

 All field entries must work properly.


 Pages must be activated from the identified link.
 The entry screen, messages and responses must not be delayed.
Features to be tested

 Verify that the entries are of the correct format


 No duplicate entries should be allowed
 All links should take the user to the correct page.

6.8 INTEGRATION TESTING


Software integration testing is the incremental integration testing of two or more
integrated software components on a single platform to produce failures caused by
interface defects.

The task of the integration test is to check that components or software applications,
e.g. components in a software system or – one step up – software applications at the
company level – interact without error.

Test Results: All the test cases mentioned above passed successfully. No defects
encountered.

81
6.9 ACCEPTANCE TESTING
User Acceptance Testing is a critical phase of any project and requires
significant participation by the end user. It also ensures that the system meets the
functional requirements.

Test Results: All the test cases mentioned above passed successfully. No defects
encountered.

82
CHAPTER 7

CONCLUSION

Rain fall prediction plays the major role in agriculture production. The growth
of the agricultural products is based on the rainfall amount.
So it is necessary to predict the rainfall of a season to assist farmers in
agriculture. The proposed method predicts the rainfall for the Indian dataset using
multiple linear regression and provides improved results in terms of accuracy, MSE and
correlation.

83
CHAPTER 8

FUTURE IMPROVEMENT
As rainfall is dependent on the various parameters it is also required to study
how other meteorological parameters affect the Rainfall prediction.
We can also perform the same exercise on monthly data using various
parameters to forecast next month rainfall. A study can also be done using more
observations for particular region or area, and design this kind of model on big data
framework so that computation can be faster with higher accuracy.

84
CHAPTER 9
REFERENCES

1. Manojit Chattopadhyay, Surajit Chattopadhyay, “Elucidating the role of topological


pattern discovery and support vector machine in generating predictive models for Indian
summer monsoon rainfall”, Theoretical and Applied Climatology, pp. 1-12, July2015,
DOI: 10.1007/s00704-015-1544-5

2. Kumar Abhishek, Abhay Kumar, Rajeev Ranjan, Sarthak Kumar,” A Rainfall


Prediction Model using Artificial Neural Network”, 2012 IEEE Control and System
Graduate Research Colloquium (ICSGRC 2012), pp. 82-87, 2012.

3. Minghui Qiu, Peilin Zhao, Ke Zhang, Jun Huang, Xing Shi, Xiaoguang Wang, Wei
Chu, “A Short-Term Rainfall Prediction Model using Multi-Task Convolutional Neural
Networks”, IEEE International Conference on Data Mining, pp. 395-400, 2017, DOI
10.1109/ICDM.2017.49.

4. Aswin S, Geetha P and Vinayakumar R, “Deep Learning Models for the Prediction
of Rainfall”, International Conference on Communication and Signal Processing, April
3-5, 2018, India, pp. 0657-0661.

5. Xianggen Gan, Lihong Chen, Dongbao Yang, Guang Liu, “The Research Of
Rainfall Prediction Models Based On Matlab Neural Network”, Proceedings of IEEE
CCIS2011, pp. 45- 48.

6. Sam Cramer, Michael Kampouridis, Alex A. Freitas and Antonis Alexandridis,


“Predicting Rainfall in the Context of Rainfall Derivatives Using Genetic
Programming”, 2015 IEEE Symposium Series on Computational Intelligence, pp. 711
– 718.

85
7. Mohini P. Darji, Vipul K. Dabhi, Harshadkumar B.Prajapati, “Rainfall Forecasting
Using Neural Network: A Survey”, 2015 International Conference on Advances in
Computer Engineering and Applications (ICACEA) IMS Engineering College,
Ghaziabad, India, pp.706 – 713

8. Sandeep Kumar Mohapatra, Anamika Upadhyay, Channabasava Gola, “Rainfall


Prediction based on 100 years of Meterological Data”,2017 International Conference
on Computing and Communication Technologies for smart Nation, pp.162 – 166.

9. Sankhadeep Chatterjee, Bimal Datta, Soumya Sen, Nilanjan Dey, “Rainfall


Prediction using Hybrid Neural Network Approach”, 2018 2nd International
Conference on Recent Advances in Signal Processing, Telecommunications &
Computing (SigTelCom), pp. 67 – 72.

10. Mr. Sunil Navadia, Mr. Pintukumar Yadav, Mr. Jobin Thomas, Ms. Shakila
Shaikh, “Weather Prediction: A novel approach for measuring and analyzing weather
data”, International conference on I-SMAC (IoT in Social, Mobile, Analytics and
Cloud) (I-SMAC 2017), pp. 414 - 417

86

You might also like