Skip to main content

Simple Neural Network model to perform binary classification.


1. Introduction 

            AI has become increasingly important in various aspects of our lives and across different field of industries. Specially in decision making it helps to reduce cost, time and use of resources in an effective way.
        prediction of rain is important in decision making of our  day today life as well as in some other sectors like agriculture,material production and public services. For that problem we developing a  neural network which produce results in the form of binary classification as ''Yes'' or ''No''.
        For that we selected kaggle dataset as the data sources which contains 10 years of daily weather observation from many location across Australia.

Git hub link to execute binary classification in your own way  (source code) : https://github.com/sivasoruby/binary_classification_neuralnetwork

2. Data preparation 

Dataset
The dataset includes observations of the climate in Australia of a period of 10 years and how the rainfall varies depending on other climate changes.
Input Variables:
  • Date : date of observation
  • Location : region within Australia
  • MinTemp : Minimum temperature in teh day in degree Celsius
  • MaxTemp : Maximum temperature in teh day in degree Celsius
  • Rainfall : The amount of rainfall recorded for the day in mm
  • Evaporation : The so-called Class A pan evaporation (mm) in the 24 hours to 9am
  • Sunshine : The number of hours of bright sunshine in the day.
  • WindGustDir : The direction of the strongest wind gust in the 24 hours to midnight
  • WindGustSpeed : The speed (km/h) of the strongest wind gust in the 24 hours to midnight
  • WinDir9am : Direction of the wind at 9am
  • WinDir3pm : Direction of the wind at 3pm
  • WindSpeed9am : Wind speed (km/hr) averaged over 10 minutes prior to 9am
  • WindSpeed3pm : Wind speed (km/hr) averaged over 10 minutes prior to 3pm
  • Humidity9am : Humidity (percent) at 9am
  • Humidity3pm : Humidity (percent) at 3pm
  • Pressure9am : Atmospheric pressure (hpa) reduced to mean sea level at 9am
  • Pressure3pm : Atmospheric pressure (hpa) reduced to mean sea level at 3pm
  • Cloud9am : Fraction of sky obscured by cloud at 9am. This is measured in "oktas", which are a unit of eigths. It records how many
  • Cloud3pm : Fraction of sky obscured by cloud at 3pm. This is measured in "oktas", which are a unit of eigths. It records how many
  • Temp9am : Temperature (degrees C) at 3pm
  • Temp3pm : Temperature (degrees C) at 9am
  • RainToday : Boolean: 1 if precipitation (mm) in the 24 hours to 9am exceeds 1mm, otherwise 0
  • There are a total of 145460 observations.

  I) Import the libraries

This is how we import libraries in python using import keyword. NumPy is the fundamental package for scientific computing with Python. Pandas is for data manipulation and analysis. Warning messages are typically issued in situations where it is useful to alert the user of some condition in a program, where that condition (normally) doesn’t warrant raising an exception and terminating the program. Other libraries are import according to the requirements.

II) Import the data set
First we need to import the kaggle dataset in to our google colab environment. For that we need to follow following procedures.
Step 1: Install the kaggle
Step 2: Upload the kaggle.json file
Step 3: Create a kaggle folder.
Step 4: Copy the kaggle.json to folder created.
Step 5: permission for the json to action.
Step 6: Including particular dataset in to our colab
Step 7: Extract the zip file.
Step 8: Read csv in to data frame using pandas library.





III) Data Frame importation and information

Before any processing, we must first obtain information about the data we are going to use. We need to know how the data is distributed, what type of data it is, if we have any missing values. Understand what information these data give us.





   IV) Check out the Missing Values


What we want to predict here is the RainTomorrow column.

Together with the information on the other columns, we want to know if it will rain the day after a given day.

3. Data Pre-processing 

I) Handle missing values in data preprocessing
The concept of missing values is important to understand in order to successfully manage data.


II) See the categorical values


III) Splitting the dataset in to training and test data

4. Model Design 

5. Hyper parameter selection

 We selects binary cross entropy, as the loss function adam as the optimizer without any learning rate.


6. Overview of the Implementation platform 

To train our model we need a platform which need to be satisfy hardware requirements of training model in order to get the expected results with our model design and hyper parameters. For that we need GPU work stations specially in training the network. But its not possible to have such GPU stations with our local machines. So that we choose google colab environment which provide all hardware requirements with GPU to train our model with our expectations.


Whenever we execute each segment according to the requirements hardware allocation will change. Specially when model execution time and  training time need of  GPU was very high.

7. Training 

Training happened by changing the activation function and number of neurons in each layer and its accuracy measured as shown below. For further clarification all cases mentioned in the source code too.

8. Optimizing the hyper parameters 

9. Final Optimized Model 

10. Test Results 

Even if the accuracy gives us important information, it is not enough on its own to validate the model used. For that we analyzed using f1 score and confusion matrix.

f1 score and cm matrix for final optimized model


Cross validation with KFold


Cross- validation is a method for testing the performance of a machine learning predictive model. We will retrain our model several times. In this case  10 times, and for each training we will change the data and the test data.

11. Discussion 

On the whole, for the prediction of rain we created a neural network model. For that we chosen kaggle to get dataset. When chosen our model design and hyper parameter,  we select model and hyper parameter in an assumption or past implementation and  make them to optimized by hyper parameter tuning help of experimental results. finally select optimized model with optimizing hyper parameters. 

After that we check our accuracy with f1 score and confusion matrix. Further we used K- fold validation for testing our performance.

12.References

https://www.kaggle.com/datasets/jsphyg/weather-dataset-rattle-package?resource=download

https://hackernoon.com/what-steps-should-one-take-while-doing-data-preprocessing-502c993e1caa

https://www.kaggle.com/code/simonbeylat/nn-with-keras-99-accuracy#Conclusion-on-model-and-possible-evolution

https://www.youtube.com/watch?v=57N1g8k2Hwc




Comments