This project investigates what drives residential property prices in Denmark. Using a dataset of 100,000 transactions spanning over 30 years, I built and compared multiple machine learning models — from a simple linear regression baseline to an ensemble Gradient Boosting regressor and a Random Forest classifier — to predict and segment property prices based on physical, geographic, and macroeconomic features.
Dataset Summary
Source: Kaggle – danish-residential-housing-prices-1992-2024 by martinfrederiksen
Reason: 'house_id' and 'address': High-cardinality unique identifiers with no predictive signal, including them would cause overfitting. 'sales_type': no meaningful correlation with purchase_price after inspection.
Missing Values
The columns 'city' (11 rows),'dk_ann_infl_rate%'(77 rows), and 'yield_on_mortgage_credit_bonds%' (77 rows).
All dropped since they represent less than 0.3% of the dataset.
Outlier Detection
House type:
image
Action: Outliers were identified but retained.
Reason: - At first, I thought Townhouses were outliers. But after a deeper look, I found over 10,000 observations (about 10% of the data). This is a significant group in the Danish market, so I decided to keep it. This will help the model learn the specific pricing patterns for this type of property.
year build:
image
Action: Outliers were identified but retained.
Reason: Denmark know as one of the oldest country in the world. Therefore i kept only house that built from the 1600 and above to get enough data to understnad the target value.
purchase price+ sqm price:
image
image
Action: Outliers were identified but retained
Reason: understand that i don't have extremely values- keeping the outliers as is.
change between offer and purchase:
image
Action: Outliers were identified but retained.
Reason: Bargaining in real estate is one of the well-known tools in this regard. Therefore, the price of the property can rise or fall accordingly. Therefore, I will remove all the houses that were sold for 30 percent more/less - Extreme changes usually indicate data errors or non-market transactions (e.g., family transfers).
sqm + number of room:
image
image
Action:utliers were identified but retained.
Reason: understand that i don't have extremely values- keeping the outliers as is.
region:
image
Action: Outliers were identified but retained.
Reason: At first, I thought Fyn & islands were outliers. But after a deeper look, I found over 9000 observations (about 9% of the data). This is a significant group in the Danish market, so I decided to keep it. This will help the model learn the specific pricing patterns for this type of region.
interest rate + dk_ann_infl_rate:
image
Action:Outliers were identified but retained.
Reason: can have intresting connection to my target value- therefore, not removing them.
2. visualizations
-Distribution of Log-Transformed Purchase Prices:
image
The graph shows a normal distribution of purchase prices, which is highly concentrated around the value of 14.2—representing approximately 1.47 million DKK.
-Impact of Property Size on Purchase Prices:
-
image
A clear positive relationship exists between square meters and purchase price — larger properties command higher prices consistently across all house types.
-Average Square Meter Price by House Type:
image
-Apartments are the most expensive per square meter-Their average price per sqm is the highest among all property types, approaching 30,000 Danish Krone (DKK).
-Correlation matrix for numerical features:
image
-sqm and sqm_price are strongly correlated with purchase_price. Macroeconomic variables (nom_interest_rate%, dk_ann_infl_rate%) show meaningful but non-linear relationships with prices, supporting the decision to retain them.
Research Questions:
Is there correlation between the year of Construction to its market value? Yes
-
image
-Properties built in the mid-17th century command a significant price premium — rare historic homes in central locations attract buyers willing to pay for heritage and style..
How significantly does the Region dictate pricing in Denmark? Yes
-
image
- The Zealand region (home to Copenhagen) is the most expensive by a clear margin. Its role as the country's business and cultural hub drives sustained price premiums.
Does the gap between the bid and the actual purchase decrease or increase when interest rates decrease? Yes — inversely
-
image
- When rates are low, sellers set optimistic asking prices, leading to more negotiation and larger gaps. When rates are high, sellers price more realistically from the start.
Do property prices vary significantly based on the quarter (Q1-Q4) in which they are sold? No!
-
image
-Sales are distributed evenly across quarters (23.7%–27.7%). The Danish market shows no meaningful seasonal pricing trend.
. Key Findings:
Size is the strongest single predictor — purchase price scales consistently with square meters
Apartments have the highest price per sqm — driven by central urban locations where land is scarce
Zealand (Copenhagen region) commands the highest average prices
17th-century properties outperform modern builds — historical scarcity creates a luxury premium
No meaningful seasonal effect on pricing across quarters
Modeling:
1. Regression Goal:
The regression task predicts the continuous purchase_price.
2. Feature Engineering:
Beyond the raw features, I created five categories of engineered variables to give the models more predictive signal-
property_age (Current year minus year_built)- Captures depreciation and heritage premium more directly than raw build year
sale_year + sale_month(Decomposed from transaction date)- Lets models learn temporal trends without treating date as a single opaque value.
sqm_per_room (sqm / no_rooms)- A way to measure spaciousness that isn't just about the total area.
real_interest_rate (Nominal rate minus inflation rate)- A more honest signal of actual borrowing cost than nominal rate alone.
cluster_id + cluster_distance - Used K-Means to group properties across geographic and structural features, allowing the model to learn neighborhood effects and localized price premiums that rigid boundaries like zip codes cannot capture.
image
3. Why Gradient Boosting Won?
Handles Non-Linearity- Captures "if large AND in Zealand, THEN very expensive" — complex interactions that a straight-line model misses entirely.
Uses Engineered Features-Cluster ID and property age were highly useful for tree-based splits, boosting performance beyond the raw feature set.
Outlier Resilience- Tree ensembles handle luxury outliers without distorting predictions for the majority of mid-market properties.
4. Regression-to-Classification:
Using quantile-based binning, purchase prices were divided into 3 balanced classes (~33% Each class) — ensuring no class imbalance issues during training:
Class 0- Low · < 975K DKK
Class 1- Mid · 975K–1.96M
Class 2-High · > 1.96M DKK
image
5. 3 Patterns from the Matrix
image
image
image
"Neighbor" mistakes dominate — models confuse Low↔Mid and Mid↔High, which makes real-world sense given blurry price boundaries.
Mid is hardest — middle-range properties share features with both cheap and expensive homes, creating inherent ambiguity.
High-value success — very few extreme errors (Low predicted as High). Luxury properties have distinctive-enough features to be reliably identified.
6. Additional info
Why False Negatives Matter? In this context, missing a truly high-value property (classifying it as lower tier) is more costly than a false alarm. A missed luxury property means lost investment opportunity or misallocated resources — a false positive only leads to a wasted evaluation, which is recoverable.
Random Forest Won Because-Ensemble of trees ignores noise, handles non-linear interactions, and uses cluster features effectively — things KNN and Logistic Regression cannot.
Final Accuracy: 61%. On a balanced 3-class problem, this is strong. A random classifier would score ~33%. The model adds substantial real-world signal.
Business Value-Even at 61%, the model reliably avoids the worst errors (luxury ≠ budget) — making it useful for portfolio segmentation and investment screening.
Overall:
Size Dominates- sqm is the single most predictive feature — a finding consistent across both regression and classification models.
Location is Critical-Region adds strong signal — particularly the Copenhagen/Zealand premium. Geography matters as much as size.
Macroeconomics Shape Behavior-Real interest rate captures true borrowing cost and shifts seller psychology — a more honest signal than the nominal rate alone.
Clustering Helped- K-Means market segmentation gave tree models a shortcut to recognise distinct buyer/property segments without explicit rules.
Trees Beat Lines- Non-linear ensemble methods significantly outperform linear regression for real estate — the market is full of interaction effects.
No Seasonality-Denmark's housing market is stable year-round. Quarter is not a useful pricing predictor — a counter-intuitive but well-supported finding.