A real estate agency wants to develop a system that helps predict house prices based on the
size of the house and the number of bedrooms. They have collected a small dataset of recent
sales and want to apply the K-Nearest Neighbors (KNN) algorithm to estimate prices for new
homes. The dataset includes house size, number of bedrooms, and the house price.
House Size (sq ft) Bedrooms Price ($1000s)
1500 3 300
1700 3 350
2000 4 400
2100 4 410
2500 4 450
Question:
Predict the price of a house that is 1800 sq ft with 3 bedrooms using the
KNN algorithm with k=3.
Solution:
Step 1: Understand the Data
The dataset contains two features:
House Size (Input Feature 1)
Bedrooms (Input Feature 2)
The target is the House Price.
Step 2: Choose the KNN Parameters
Number of neighbors k=3
Step 3: Calculate the Distance
Step 4: Calculate Distances
Step 5: Identify Neighbors
Select the 3 nearest neighbors based on the smallest distances:
House 2 (d = 100)
House 3 (d ≈ 200.002)
House 1 (d = 300)
Step 6: Predict the Price
Conclusion:
The predicted price for the new house (1800 sq ft, 3 bedrooms) using KNN with k=3 is
$350,000. KNN effectively uses the nearest neighbor's known prices to estimate the pricing
for an unseen house by leveraging both house size and number of bedrooms.