I built a web app that estimates house prices. You type in details about a house like its location, age, and number of rooms and a machine learning model calculates a price based on historical data.
I ran into two main bugs that stopped the app from making predictions. Here is what happened and how I fixed the code.
- The Webpage Crash The Problem: As soon as I started the server and opened the website, it crashed completely.
The Cause:
The code for the webpage was designed to remember what you typed into the form so your numbers wouldn't disappear after you clicked "Predict." However, when you load the page for the very first time, you haven't typed anything yet. Because that data was missing, the webpage panicked and broke.
The Fix:
I updated the backend code to hand the webpage a blank slate (an empty set of data) when it first loads. This gave it what it needed to load normally without crashing.
- The Data Mismatch The Problem: Once the webpage was loading properly, I tried to predict a price. It failed again, throwing errors about a "shape mismatch."
The Cause:
Before the machine learning model can predict a price, the input numbers have to be scaled down by a mathematical tool. When I trained this model, that tool was built to handle exactly 10 numerical inputs. But my app was trying to hand it 15 inputs all at once, including text-based choices like "Ocean Proximity." It didn't know how to handle the text, so it threw an error.
The Fix:
I split the background process into two steps. First, the code separates the 10 numbers and scales them properly. Then, it takes the text choice (like whether the house is near the ocean), translates it into a format the computer understands, and attaches it back to the numbers. This gave the model the exact 15-piece format it was expecting.
Wrapping Up
I also added a safety net to the code so that if an error like this happens again, it displays a clean message on the webpage instead of crashing the whole server. Once the predictions were calculating correctly, I saved the changes and pushed the updated code to my GitHub repository (https://github.com/nikitagpt05/House-Price-Prediction). The app is back up and running.
Top comments (0)