Prerequisites: Linear regression
Rainfall Prediction is the application of science and technology to predict the amount of rainfall over a region. It is important to exactly determine the rainfall for effective use of water resources, crop productivity and pre-planning of water structures.
In this article, we will use Linear Regression to predict the amount of rainfall. Linear Regression tells us how many inches of rainfall we can expect.
The dataset is a public weather dataset from Austin, Texas available on Kaggle. The dataset can be found here.
Data comes in all forms, most of it being very messy and unstructured. They rarely come ready to use. Datasets, large and small, come with a variety of issues- invalid fields, missing and additional values, and values that are in forms different from the one we require. In order to bring it to workable or structured form, we need to “clean” our data, and make it ready to use. Some common cleaning includes parsing, converting to one-hot, removing unnecessary data, etc.
In our case, our data has some days where some factors weren’t recorded. And the rainfall in cm was marked as T if there was trace precipitation. Our algorithm requires numbers, so we can’t work with alphabets popping up in our data. so we need to clean the data before applying it on our model
Cleaning the data in Python:
Once the data is cleaned, it can be used as an input to our Linear regression model. Linear regression is a linear approach to form a relationship between a dependent variable and many independent explanatory variables. This is done by plotting a line that fits our scatter plot the best, ie, with the least errors. This gives value predictions, ie, how much, by substituting the independent values in the line equation.
We will use Scikit-learn’s linear regression model to train our dataset. Once the model is trained, we can give our own inputs for the various columns such as temperature, dew point, pressure, etc. to predict the weather based on these attributes.
The precipitation in inches for the input is: [[1.33868402]] The precipitation trend graph:
Precipitation vs selected attributes graph:
A day (in red) having precipitation of about 2 inches is tracked across multiple parameters (the same day is tracker across multiple features such as temperature, pressure, etc). The x-axis denotes the days and the y-axis denotes the magnitude of the feature such as temperature, pressure, etc. From the graph, it can be observed that rainfall can be expected to be high when the temperature is high and humidity is high.
- ML | Linear Regression
- Linear Regression Using Tensorflow
- Simple Linear-Regression using R
- Multiple Linear Regression using R
- Linear Regression using PyTorch
- Linear Regression (Python Implementation)
- Gradient Descent in Linear Regression
- ML | Locally weighted Linear Regression
- Univariate Linear Regression in Python
- ML | Multiple Linear Regression using Python
- ML | Normal Equation in Linear Regression
- Python | Linear Regression using sklearn
- Mathematical explanation for Linear Regression working
- Pyspark | Linear regression using Apache MLlib
- A Practical approach to Simple Linear Regression using R
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.