Neural networks for regression - a comprehensive overview - Part 7

In this final post, we will briefly focus on how neural networks can be used in a simple real-world scenario: predicting the price of a house in the real estate market.

Important

When we refer to a real-world example, we don't mean that we will be working with a real dataset, but rather that we will demonstrate how to systematically approach a real problem. In fact, our current dataset will consist of only 20 records, making it quite small.

We will consider a scenario where we want to predict the price of a house based on three features: its surface area, the number of rooms, and the number of bathrooms.

surface area (m²)number of roomsnumber of bathroomsprice (€)
12042687
9841610
7631367
13263850
10051560
11052710
9831520
10042640
10542650
8631510
8831580
168831000
14862920
9442600
13463910
15272820
12262740
8231500
11262690
14463870

Normalizing data

In our earlier examples, the feature values were all within the $[-1,1]$ interval. However, in our current case, the values can vary significantly, such as the surface area ranging from 50 to 200. To address this, it's good practice to normalize the data so that all features lie within the same range, improving the performance and stability of the neural network.
The following code will normalize the input data, ensuring all values are scaled to the same range before feeding them into the neural network for training or prediction.

 1 public void Normalize()
 2 {
 3     foreach (var feature in Features)
 4     {
 5         var inputs = Records.Select(t => t.Data[feature]);
 6         var min = inputs.Min(); var max = inputs.Max();
 7         var diff = max - min; var sum = max + min;
 8         
 9         for (int i = 0; i < inputs.Count(); i++)
10         {
11             Records[i].Data[feature] =  (2 / diff) * inputs.ElementAt(i) - sum / diff; // Normalize to range (-1, 1)
12         }
13     }
14 }

Making predictions

Our objective is to predict a house's price based on its surface area, the number of rooms, and the number of bathrooms. To achieve this, we must first train the neural network.
Afterward, we can test the model with any values we choose. An example is provided below.

The results obtained are quite consistent with the initial dataset.

Information

It is important to note that our dataset is too small to be truly representative, and it's entirely possible that some predictions may be inaccurate.

Final thoughts

In this series, we explored how neural networks can be effectively applied to regression problems, enabling accurate predictions of output values. Neural networks are particularly powerful in capturing non-linear relationships between data, making them a popular choice for solving complex scenarios.

If you wish to delve deeper into this topic, acquire the following books, which encompass all the concepts emphasized in this series and delve into more advanced ones.

Deep Learning (Goodfellow, Bengio, Courville

Deep Learning: Foundations and Concepts (Bishop, Bishop)

Machine Learning: An Algorithmic Perspective (Marsland)

Do not hesitate to contact me should you require any further information.