Back to Section 2

Predicting workspace price tiers

Gradient boosting, out-of-fold target encoding, and a macro-F1-tuned blend

Section 2 of the ML Projects Course

The task

  • Each row is a bookable workspace listing.
  • Predict price_tier, an ordered class from 1 to 4.
  • 279,746 training rows, 114,538 test rows, 58 features.
  • Metric: macro F1.

Macro F1 weights every tier equally

Bar chart of listings per tier.
  • Tiers: 66,889 / 81,530 / 60,839 / 70,488.
  • Largest class is 1.34 times the smallest.
  • A weak tier can't hide behind a strong one.

Explore: signal and structure

Four panels of feature relationships with the tier.

Missing values carry meaning

Missing percentage by column.
  • Borough: structurally missing in 11 of 16 metros.
  • Reviews: missing when there are no reviews.
  • Median fill plus an indicator keeps the signal.

Geography: 16 metros

Mean tier by metro, and listings of one metro coloured by tier.

Preprocess without leaking

  • Fit every learned step on training data only.
  • Clean: 1,116 duplicates dropped, 62 invalid terms capped at 1,125 days.
  • Linear baseline: macro F1 0.358 to 0.682 with preprocessing.

Features that moved the score

  • IDs become counts: 34% of test listings have unseen operators.
  • 145 facility flags: +0.004.
  • Geometry of the coordinates: rotations, distances, k-means.
  • Base 0.7303 to 0.7503 on the holdout.

Out-of-fold target encoding

Smoothed tier share per group, m = 20, computed from the other four folds.

Training and holdout macro F1 for in-sample and out-of-fold target encoding.

Residual encoding leads the importance chart

Feature importance by gain.

Models: from default to boosting

Holdout macro F1 for several models.
  • Regularized LightGBM categoricals: +0.0105.
  • Ordinal LightGBM: 0.7417. CatBoost: 0.7444. XGBoost: 0.7140.

Boosting, one round at a time

Validate with stratified 5-fold CV

Confusion matrices of the fold-0 blend.
  • Only 6.7% of errors are off by two tiers or more.
  • Tier 3 is weakest: F1 0.629.

Blend, then weight the classes

StageCV macro F1
Multiclass LightGBM0.7520
Ordinal LightGBM0.7547
Blend0.7559
Blend with class weights0.7577

Class weights [1, 0.98, 1.15, 0.852]. Honest gain: about +0.001.

Score progression

Holdout macro F1 across development setups.

Lessons learned

  • Handle high-cardinality IDs with care.
  • Judge changes against noise (about 0.002).
  • Blend models that make different errors.
  • Unseen operators score about 0.03 lower.

Return to the section overview