Real estate price prediction (DVF)
Exploring and cleaning the DVF database of real estate transactions in France, then comparing regression models (k-nearest neighbours, Random Forest…) to predict a property's sale price.
- Python
- pandas
- NumPy
- scikit-learn
- Matplotlib
- Jupyter
The DVF database (Demandes de valeurs foncières) lists every real estate transaction made in France each year. Working from its residential part, the goal was to predict a property's sale price from its characteristics: department, floor area, number of rooms, land area and location.
Exploring and cleaning the data
The correlation table showed no satisfying link between the sale price and the other attributes, so the data had to be understood first.
- A price per square metre attribute brings out the outliers: above the 99th percentile (about €13,500 per m²), transactions skew the predictions.
- The Corsican departments 2A and 2B were recoded as numbers, checking that their statistics were kept.
- Missing values: a missing land area becomes 0, and rows without a floor area are dropped.
Visualising
Once the extreme values are set aside, a map of transactions coloured by sale price brings out the large cities and the coasts. Above all, it shows that properties close in location and size have similar prices.

Training and comparing models
That observation pointed the first model towards k-nearest neighbours. A shared test function repeats training over random splits and sets how many extreme values to remove: removing the top 10% of prices per m² gave the best results, with 5 to 10 neighbours.
The model predicts most properties well, but not the exceptionally expensive ones left out of training.

We then compared other scikit-learn models: linear regression, Lasso, ElasticNet, SGD (with and without scaling), Random Forest and Gradient Boosting. Most reach similar errors. The linear regressions are the fastest, Random Forest and Gradient Boosting the most accurate.