Building an Explainable Used-Car Price Estimator
Used-car pricing is rarely just prediction; it is negotiation under uncertainty. Rather than treating that uncertainty as noise, the approach here makes it operational: it explains why an estimate lands where it does, separates market-driven effects from condition-driven discounts, and scales from sparse-data scenarios to data-rich markets through median blending. The output becomes easier to trust because it is auditable and decomposable: each adjustment is visible, and the band explicitly communicates confidence. That translates into less manual reasoning, fewer surprises, and a more consistent pricing process.
Two listings can share the same brand, model and year, yet still differ by thousands in price because of mileage, local demand, trim or package differences, accident history, and even cosmetic body panel repairs. Most calculators either behave like a black box or rely on brittle rules that do not translate well across different combinations.
This project aims to build a deterministic, explainable price estimator: one that produces a single estimate and exposes the key drivers behind it, without pretending there is a single “true” price.
Why price estimation is hard
A realistic estimator needs to handle three constraints at once:
- Base market behavior (depreciation with age, fuel premium, demand by city, mileage expectations)
- Local reality (trim/package premiums, accident record impact, body panel condition)
- Uncertainty (how wide the market range should be when risk factors are high)
That’s why the estimator is designed as a layered pipeline rather than a one-shot prediction.
The Solution
At a high level, the estimator works like this:
- Parametric baseline (deterministic)
- Market anchoring by blending with the database median when enough comparable rows exist
- Optional package/trim adjustment
- Discounts from accident records (e.g. TRAMER in Turkey) + body panel condition
- A smart price band (low / estimated / high) that expands when risk increases
The pipeline intentionally keeps each step explicit: baseline → DB median blend → package effect → panel discount → vehicle history/accident discount → final estimate.
The Architecture
The system can be summarized with a simple flow:
Inputs (Streamlit) → Catalog + Postgres → Baseline → DB Median Anchoring → Adjustments → Output (Estimate + Range + Breakdown)
Figure — End-to-end estimation flow: deterministic baseline → market anchoring → risk/condition adjustments → final band.
Technical Deep Dive
1) Parametric baseline (deterministic)
The baseline model is intentionally deterministic. It starts from a “new price” anchor in the catalog, then applies:
- Fuel premium (e.g., hybrid/electric uplift)
- Transmission/drivetrain multipliers (automatic and AWD/4WD)
- Depreciation curve (stronger first-year drop, then follow-up decay)
- Mileage adjustment based on expected km/year by body type, capped to avoid extreme outputs
- City and color adjustments (light demand signal + minor color premium)
This yields a stable “base estimate” that behaves consistently across repeated runs.
2) Market anchoring via DB median (adaptive blending)
Pure parametric models can drift away from real market conditions. To reduce this drift, the system queries the database for a median price of similar listings (within tolerance windows for year and horsepower).
If the median exists, the estimator blends the baseline and the market anchor:
- weight grows with the number of matching rows
- capped so the baseline still matters
This supports a gradual transition: sparse-data cases remain stable, high-coverage cases become more market-driven.
3) Package / trim adjustments (optional, TR-market aware)
Trim/package is a huge pricing factor, but it’s also inconsistent in real listings. Instead of hardcoding everything, package knowledge is stored as a separate table and retrieved for the selected brand/model/year.
If a package is selected, both:
- a percentage adjustment, and
- an absolute price adjustment in TRY
can be applied before continuing down the pipeline.
4) Damage modeling: Accident record + body panels
4.1 Accident record discount (TRAMER)
Accident record discount is shaped by:
- age sensitivity (newer cars penalized more)
- damage bands (small/medium/large record levels)
- a cap ratio (premium brands allow a slightly higher cap; SUVs slightly lower)
This keeps the adjustment realistic: large accident record amounts matter but cannot collapse the estimate beyond a reasonable ceiling.
4.2 Body panel condition (interactive diagram)
A key UX feature is the clickable body panel selector:
- a top-view car diagram
- polygons for each part (hood, doors, bumpers, etc.)
- hit-testing (point-in-polygon) so a click selects the correct panel even when it falls between panels
- per-panel penalties for “painted” vs “replaced”
The final panel discount is computed by summing each marked panel’s penalty, scaled by premium brand factor, age factor, and a mild body factor.
The final estimate then applies both discounts:
final_est = blended − tramer_discount − panel_condition_discount
5) A “smart” price band (uncertainty that reacts to risk)
Instead of returning a single point, the system generates a low / high band that expands when uncertainty rises.
Risk is derived from:
- accident record magnitude vs price
- panel “non-original” ratio
- mileage deviation from expected km
- age
That risk is mapped into asymmetric bounds, usually widening the downside more than the upside when risk is high.
Data model and seeding
For the “market anchoring” step to be reliable, the estimator needs more than a set of formulas—it needs a well-structured and consistent data layer. The data side is designed around two goals:
Finding comparable listings fast (to compute a robust median / statistics)
Managing trim/package knowledge as a separate source of truth (optional, but a strong signal)
Database schema: two core tables
1) Vehicles — Market listings / observations
This table stores marketplace listings as “observations” the estimator can anchor to. Median computation and the comparable match count (db_n) come from here.
Typical fields fall into these groups:
- Identity & timestamps: id, created_at, updated_at
- Vehicle identity: brand, model, year, hp, fuel, transmission, drivetrain
- Location & listing attributes: city, color
- Usage: km
- Price: price (TRY)
- Risk signals: TRAMER accident record amount
- Extensibility: extras (e.g., JSONB) → a future-proof place for options/features
The intent is simple: the minimum fields required for anchoring stay stable, while the schema can evolve without breaking the pipeline.
2) Trim/package table
Trim and package differences can shift used-car prices materially, but in real listings this information is messy and inconsistent. Instead of hardcoding it into the model, trims are stored in a dedicated table:
- brand, model, year → binding keys
- trim_name (package name)
- adj_pct → percentage effect
- adj_abs_try → absolute price effect in TRY
This keeps package effects scalable: as coverage grows, only the table changes—the pipeline stays the same.
Why median? Why not average?
Used-car prices include outliers all the time: “urgent sale,” incorrect entry, extreme trims, dealer markups, etc. That’s why median is a more robust anchor than mean:
- Mean: quickly distorted by outliers
- Median: stays closer to the “typical market” level
Comparable listing logic
The query is intentionally tolerant rather than looking for exact duplicates:
- a small window for year
- a small range for horsepower
- fixed identity fields like brand/model
The goal is to find enough matches to compute a stable median. As match count increases, the DB weight grows; when matches are scarce, the baseline remains dominant.
What this project optimizes for
- Explainability: the breakdown (base, accident damage adjustment, panel adjustment, range) is shown next to the estimate
- Graceful degradation: if DB median is missing, the pipeline falls back to the parametric baseline without failing
- Determinism: repeated inputs should produce consistent outputs
In conclusion, this work aims to replace a black-box used-car price guess with a transparent, step-by-step pipeline: a deterministic baseline is aligned to the market via database median blending, then refined with trim/package effects and risk-driven discounts from vehicle history and body condition. The result is not only a single estimate, but a clear breakdown of the main drivers and a sensible price band that widens as uncertainty increases.
Written by Ahmet Melih Cerit for DataSpecta AI Labs
