LSTM Neural Community-based Home Lease Prediction


Lengthy Brief Time period Reminiscence (LSTM) is a sort of deep studying system that anticipates property leases. By leveraging its distinctive structure and reminiscence retention capabilities, LSTM affords an revolutionary strategy to know the home lease prediction patterns with extraordinary precision.

Rental markets are influenced by various components, and LSTM’s potential to seize and bear in mind long-term dependencies permits the modeling of complicated relationships and the extraction of significant patterns from historic rental knowledge. Furthermore, LSTM networks can adapt to altering market tendencies, making them appropriate for capturing evolving rental patterns and fluctuations. Continuous coaching with new knowledge ensures the mannequin’s relevancy and accuracy in dynamic rental markets, making LSTM a strong device for producing correct predictions and offering priceless insights to each tenants and landlords.

Now, let’s make the prediction by way of the steps within the article.

Studying Aims

  1. Make correct estimates of home rental costs which are helpful for each tenants and landlords.
  2. Acquire insights into market tendencies and patterns to determine components that affect home rental costs.
  3. Present priceless data to assist decision-making processes for tenants and landlords.
  4. Assist overcome the knowledge asymmetry between tenants and landlords to facilitate truthful and knowledgeable rental transactions.

Primarily based on these objectives, we’ll use the LSTM Neural Community to develop a mannequin that may estimate the home rental worth prediction precisely primarily based on variety of bed room, dimension of the home, space sort, location, furnishing standing, and variety of rest room. This text will information you on predicting home rental worth utilizing LSTM.

This text was printed as part of the Information Science Blogathon.

Step 1: Import Library

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.specific as px
import plotly.graph_objects as go
from sklearn.model_selection import train_test_split
from keras.fashions import Sequential
from keras.layers import Dense, LSTM

An evidence of the usage of a number of libraries that might be used within the prediction job this time has been defined in a earlier article, Meals Supply Time Prediction with LSTM. Subsequently, on this article, we don’t want to debate it anymore.

Step 2: Learn the Information

To construct a home rental prediction system, we want a dataset that incorporates the components that have an effect on the rental worth of a residential property. I discovered a dataset on Kaggle that’s good for this job. For comfort, I put the dataset on GitHub.

knowledge = pd.read_csv(url)
Dataset Overview I

On this dataset, we get details about the options contained in it as follows:

  1. BHK: Variety of Bedrooms, Corridor, and Kitchen
  2. Lease: Lease of the homes, residences, and flats.
  3. Dimension: Dimension of the Homes, Flats, and Flats in Sq. Toes.
  4. Flooring: Homes/Flats/Flats located by which Flooring and Complete Variety of Flooring (Instance: Floor out of two, 3 out of 5, and many others.).
  5. Space Kind: The scale of the homes, residences, or flats is calculated on both the tremendous space, carpet space, or construct space.
  6. Space Locality: Locality of the Homes, Flats, or Flats.
  7. Metropolis: Metropolis the place the homes, residences, and flats are positioned.
  8. Furnishing Standing: The furnishing standing of the homes, residences, or flats is both furnished, semi-furnished, or unfurnished.
  9. Tenant Most well-liked: Kind of Tenant Most well-liked by the Proprietor or Agent.
  10. Loos: Variety of Loos.
  11. Level of Contact: Whom do you have to contact for extra data relating to the homes, residences, or flats.

Step 3: Home Lease Evaluation

Earlier than doing the evaluation, we have to test whether or not the dataset we’ve got incorporates a null worth or not as a result of it would have an effect on the effectiveness of the constructed mannequin.

 Data Checking
Information Checking

Descriptive Statistics

Let’s have a look at the descriptive statistics of the information now. We will achieve a greater grasp of the information and uncover doable considerations through the use of it. This knowledge can be utilized to make choices on find out how to course of it.

 Data Description
Information Description

To make it simpler for us to learn the rental worth knowledge, we use code like the next:

print(f"Imply Lease: {knowledge.Lease.imply()}")
print(f"Median Lease: {knowledge.Lease.median()}")
print(f"Highest Lease: {knowledge.Lease.max()}")
print(f"Lowest Lease: {knowledge.Lease.min()}")
 Simple Data Description
Easy Information Description

We will achieve a greater grasp of the lease costs within the dataset by analyzing these metrics. This knowledge could also be used to make rental choices, reminiscent of how a lot to spend on lease or what sort of home to lease.

Rental Costs in Totally different Cities

Now let’s have a look at the rental costs in numerous cities in keeping with the variety of bedrooms, halls and kitchens.

determine =, x=knowledge["City"], 
                y = knowledge["Rent"], 
                shade = knowledge["BHK"],
            title="Lease in Totally different Cities In line with BHK")
 rent in Bangalore BHK (3)
lease in Bangalore BHK (3)
 rent in Mumbai BHK (3)
lease in Mumbai BHK (3)

As we will see, in Bangalore, the very best rental worth for a home with a BHK 3 is 3.5 million. In distinction to Mumbai, with a BHK of three, the worth of housing rents is decrease by round 55 thousand.

Now let’s have a look at rented homes in varied cities in keeping with the kind of space.

determine =, x=knowledge["City"], 
                y = knowledge["Rent"], 
                shade = knowledge["Area Type"],
            title="Lease in Totally different Cities In line with Space Kind")
 rent in Kolkata Carpet Area
lease in Kolkata Carpet Space
 rent in Delhi Carpet Area
lease in Delhi Carpet Space

Now let’s have a look at the worth of renting homes in numerous cities in keeping with the standing of the furnishings.

determine =, x=knowledge["City"], 
                y = knowledge["Rent"], 
                shade = knowledge["Furnishing Status"],
            title="Lease in Totally different Cities In line with Furnishing Standing")
 rent in Chennai unfurnished
lease in Chennai unfurnished
 rent in Hyderabad unfurnished
lease in Hyderabad unfurnished

Now let’s have a look at rented homes in numerous cities in keeping with the scale of the home.

determine =, x=knowledge["City"], 
                y = knowledge["Rent"], 
                shade = knowledge["Size"],
            title="Lease in Totally different Cities In line with Dimension")
 rent based on house size in Chennai
lease primarily based on home dimension in Chennai
 rent based on house size in Mumbai
lease primarily based on home dimension in Mumbai

Let’s now have a look at the variety of homes accessible for lease in numerous cities by knowledge set.

cities = knowledge["City"].value_counts()
label = cities.index
counts = cities.values
colours = ['gold','lightgreen']

fig = go.Determine(knowledge=[go.Pie(labels=label, values=counts, hole=0.5)])
fig.update_layout(title_text="Variety of Homes Accessible for Lease")
fig.update_traces(hoverinfo='label+p.c', textinfo='worth', textfont_size=30,
                  marker=dict(colours=colours, line=dict(shade="black", width=3)))
 Number of Available Rent House
Variety of Accessible Lease Home

Probably the most rental housing is offered in Mumbai, with round 972 items, and the least in Kolkata, with 524 items. Allow us to now study the amount of dwellings accessible for several types of tenants.

tenant = knowledge["Tenant Preferred"].value_counts()
label = tenant.index
counts = tenant.values
colours = ['gold','lightgreen']

fig = go.Determine(knowledge=[go.Pie(labels=label, values=counts, hole=0.5)])
fig.update_layout(title_text="Desire of Tenant in India")
fig.update_traces(hoverinfo='label+p.c', textinfo='worth', textfont_size=30,
                  marker=dict(colours=colours, line=dict(shade="black", width=3)))
 Available Rent House based On Tenant
Accessible Lease Home primarily based On Tenant

Step 4: Construct an LSTM Mannequin and Make Predictions

Earlier than we create a studying mannequin, we have to convert all categorical options to numeric options first.

knowledge["Area Type"] = knowledge["Area Type"].map({"Tremendous Space": 1, 
                                           "Carpet Space": 2, 
                                           "Constructed Space": 3})
knowledge["City"] = knowledge["City"].map({"Mumbai": 4000, "Chennai": 6000, 
                                 "Bangalore": 5600, "Hyderabad": 5000, 
                                 "Delhi": 1100, "Kolkata": 7000})
knowledge["Furnishing Status"] = knowledge["Furnishing Status"].map({"Unfurnished": 0, 
                                                           "Semi-Furnished": 1, 
                                                           "Furnished": 2})
knowledge["Tenant Preferred"] = knowledge["Tenant Preferred"].map({"Bachelors/Household": 2, 
                                                         "Bachelors": 1, 
                                                         "Household": 3})
 Data Overview II
Information Overview II

Now we’ll break up the information into coaching and take a look at units.

#splitting knowledge
x = np.array(knowledge[["BHK", "Size", "Area Type", "City", 
                   "Furnishing Status", "Tenant Preferred", 
y = np.array(knowledge[["Rent"]])

xtrain, xtest, ytrain, ytest = train_test_split(x, y, 

Now, we have to prepare an LSTM neural community to foretell the lease home worth.

We’ll construct a mannequin that includes LSTM layers in a sequential neural community, aiming to take advantage of dependencies and temporal patterns in rental worth knowledge. The LSTM layer permits the mannequin to study from the sequential properties of information, seize long-term dependencies, and retailer data over time. Then we create the enter knowledge form parameter to have the form (xtrain.form[1], 1), the place xtrain is the coaching knowledge. This implies the mannequin takes an enter sequence with size xtrain.form [1] and a single function dimension.

The following project is return_sequences=true; the primary LSTM layer ensures that subsequent layers obtain all hidden state sequences, facilitating elevated studying. The variety of items or cells we set at 128 and 64 in every LSTM layer is sufficient to affect the flexibility of the mannequin to seize complicated patterns, with the mandatory stability between complexity and computational sources. The dense layer after the LSTM layer processes the extracted data is 25 items, and the ultimate dense layer with one unit outputs the expected lease.

mannequin = Sequential()
mannequin.add(LSTM(128, return_sequences=True, 
               input_shape= (xtrain.form[1], 1)))
mannequin.add(LSTM(64, return_sequences=False))
 Model Summary
Mannequin Abstract

Now let’s prepare the beforehand created mannequin.

mannequin.compile(optimizer="adam", loss="mean_squared_error")
mannequin.match(xtrain, ytrain, batch_size=1, epochs=10)
 Model Fitting
Mannequin Becoming

Lastly, let’s take a look at the mannequin’s efficiency for predicting the lease home worth given seven enter parameters (BHK, dimension, space sort, metropolis pin code, furnishing standing, tenant sort, and variety of rest room).

print("Enter Home Particulars to Predict Lease")
print("BHK = Bedrooms, Corridor, and Kitchenn")
a = int(enter("Variety of BHK (1 -- 6): "))
b = int(enter("Dimension of the Home (10 -- 8000): "))
c = int(enter("Space Kind (Tremendous Space = 1, Carpet Space = 2, Constructed Space = 3): "))
print("npincode = Mumbai: 4000, Chennai: 6000, Bangalore : 5600") 
print("pincode = Hyderabad: 5000, Delhi: 1100, Kolkata: 7000n")
d = int(enter("Pin Code of the Metropolis: "))
e = int(enter("Furnishing Standing of the Home: "))
f = int(enter("Tenant Kind (Bachelors = 1, Bachelors/Household = 2, Solely Household = 3): "))
g = int(enter("Variety of bogs (1 -- 10): "))
options = np.array([[a, b, c, d, e, f, g]])
print("Predicted Home Value = ", mannequin.predict(options))
 Prediction Result
Prediction Consequence

The output of the prediction is proven as “Predicted Home Value = [[52324.74]],” which signifies that the mannequin has estimated that the lease home worth is roughly 52,3324.74 rupees.


This text begins by checking if there are clean values within the dataset and analyzing the information with descriptive statistics. Then have a look at the connection between options and worth variables earlier than predicting the vary of home rental costs utilizing the LSTM. In brief, we’ve got mentioned the next:

  • LSTM neural networks supply a strong and efficient strategy for predicting rental housing costs.
  • By leveraging historic rental knowledge, LSTM fashions can seize complicated patterns and dependencies within the housing market.
  • LSTM fashions present correct predictions of rental costs, enabling tenants and landlords to make knowledgeable choices.
  • Steady monitoring and retraining of LSTM fashions utilizing up-to-date knowledge is essential to sustaining their predictive efficiency in dynamic rental markets.

General, this text gives a complete information to predicting rental housing costs with an LSTM neural community utilizing Python. If in case you have any questions or feedback, please go away them beneath. The whole code may be seen right here.

The media proven on this article shouldn’t be owned by Analytics Vidhya and is used on the Creator’s discretion.

Related Articles


Please enter your comment!
Please enter your name here

Latest Articles