The problem
Pricing a flat is the first question every seller asks an agent, and the answer is often a guess from memory. A model gives a first figure in seconds, says how sure it is, and shows what pushes the number up or down.
Agents use it to quote faster and to qualify sellers; property portals use it to flag listings priced far from their neighbours.
The data
1,600 listings across 12 localities, from Nungambakkam and Besant Nagar to Porur and Tambaram. Each has its area, bedrooms, the building's age, the floor, the distance to the nearest metro station, and whether it has covered parking, a lift and a gated community.
I generated them. Each locality has a rough rate per square foot; age, floor, parking, the metro and the rest nudge it; random noise goes on top. The rules include a few quirks, such as a premium for new buildings and the metro mattering more in the suburbs, so the models have something to find. These are not market prices.
The split is fixed: 80% to train and 20% to test, picked at random with a seed, so the numbers repeat on every visit.
The model
Linear regression on log prices. Prices behave like a rate times an area, so working in logs turns those multiplications into sums that a linear model fits exactly. Each weight then reads as a percentage: what a year of age or a kilometre from the metro does to the price. That is what the bars under the estimate show.
A random forest of 60 decision trees, each grown on a resampled set of listings. It assumes no shape, so it can pick up local quirks such as the discount on very large flats in the suburbs. Its trees also disagree a little, which gives a range instead of a single number.
The forest gets one engineered feature: the locality's average rate per square foot, learnt from the training listings only, times the area. Trees find multiplying hard; handing them the product matters more than the choice of algorithm.
The pipeline
- 01Generate
1,600 sample listings from a fixed seed, the same on every visit.
- 02Split
80% to train; 20% held back to test.
- 03Encode
Localities become one-hot columns for the linear model and an average rate for the forest; area goes on a log scale.
- 04Train
Both models fit in about a tenth of a second, in your browser.
- 05Estimate
Your flat goes through both models; the forest's trees give the range.
- 06Explain
The linear weights become the percentage bars; comparable listings come from a simple similarity score.
Results
Measured when this page was built, with the same code the demo runs. The linear model wins here because the sample's prices really are a rate times an area; on real listings, with messier effects, the forest often closes the gap.
For a client
With a client's real listings I would start the same way, then add what moves prices in their market: the building, carpet against built-up area, facing, the view, the school catchment.
I would retrain as new listings arrive, track the error by locality, and flag the flats where the two models disagree, so a person checks the odd ones before a figure reaches a seller.
The model can run as a small API or, as here, inside the website itself: there is nothing heavy to host.
Stack
Privacy
Everything happens in your browser. The flat you describe is never sent anywhere: there is no server behind this page.
Limits
- The data is generated, so the accuracy here shows how well the models recover the rules I wrote, not how well they would price a real flat.
- Neither model knows anything outside its columns: a renovated kitchen, a noisy road or a difficult society.
- Outside the ranges in the sample (a 5,000 sq ft penthouse, say) both models are guessing.