Skip to main content

Days on Lot

Predicts how long a vehicle will sit on the lot before selling. The model and its predictions are in one Dagster group, and the evaluation is in the reporting group:

  • <oem>/days_on_lot_model — trained sklearn Pipeline, refit per partition (MLModelComponent).
  • <oem>/reporting/days_on_lot_model_evaluation — the model's goodness of fit, bias and calibration per group, on its test set and on its train set and test set together (MLModelComponent with an evaluation block). See Evaluation.
  • <oem>/days_on_lot_predictions — per-vehicle scored output (car_id, predicted_days_on_lot, _partition_date) (ModelInferenceComponent).

Both components share the same feature assembly logic from ai_dagster.ml, so training and inference see identical inputs.

Training (MLModelComponent)​

Joins consolidated inventory + reference tables + named inventory-statistics tables into one feature matrix, then fits the configured estimator. KPI columns from each StatsInputSpec are prefixed with {name}__ and referenced from feature_columns via source: <name>.

type: ai_dagster.components.MLModelComponent
attributes:
oem: mb
name: days_on_lot_model
start_date: "2025-01-01"
group: days_on_lot
task_type: regression
model_type: xgboost
label_column: days_on_lot
joins:
- asset: mb/dealers/neighborhoods
join_on: [dealer_id]
fields: [neighborhood]
stats_lookback_days: 365
stats_inputs:
- name: stats_by_dealer_neighborhood
asset: mb/inventory_stats/dealer_neighborhood
join_on: [dealer_id, neighborhood]
feature_columns:
- { column: days_supply_90D, source: stats_by_dealer_neighborhood }
- { column: avg_days_on_lot_90D, source: stats_by_dealer_neighborhood }
- { column: neighborhood, source: dealers }
evaluation:
split:
type: sold_date
test_days: 30
min_group_size: 20
groupings:
- key: neighborhood
group_by: [neighborhood]
hyperparameters:
n_estimators: 15
max_depth: 14
learning_rate: 0.5
FieldDescription
groupDagster UI group — share with the inference component so model + predictions cluster together
model_typelinear, xgboost, or random_forest (ModelType StrEnum)
task_typeregression or classification
label_columnPrediction target column
feature_columnsPer-column (column, source) pairs — source is inventory, dealers, models, or a stats_inputs name
stats_inputsStatistics tables joined as features. Non-key columns get {name}__ prefix. Each entry sets join_date: arrival or sale
stats_lookback_daysPast partitions of stats to load. > 0 enables point-in-time joins (set to max vehicle age)
arrival_date_floorOptional. Drops vehicles that arrived on or before this date, such as vehicles backfilled before the inventory feed started
include_modelsJoin consolidated/models in as a feature source, enabling source: models entries in feature_columns. ModelInferenceComponent must set the same value
evaluation.splitRequired in an evaluation block. How the labeled vehicles are split into a train set and a test set. type: sold_date requires test_days: the labeled vehicles sold in that many days before the partition date form the test set. type: random holds out test_fraction of the labeled vehicles, 0.2 by default. A hash of inventory_id with seed selects them
evaluation.min_group_sizeRequired in an evaluation block. Groups with fewer vehicles than this in the test set or the scored set are left out of that set's metrics
evaluation.groupings{key, group_by} entries, as in InventoryStatisticsComponent. The keys all and predicted_decile are reserved
evaluation.min_r2Defaults to 0.4; null turns it off. The model_evaluation check fails when the test R² is below it
evaluation.max_abs_group_biasDefaults to 10, in units of the label (days for this model); null turns it off. The model_evaluation check fails when the absolute bias of the all group or a configured group is above it

inventory always reads <oem>/<market>/consolidated/inventory — not configurable.

Point-in-time stats joins​

When stats_lookback_days > 0, each vehicle is joined to the stats row with the latest _partition_date on or before a reference date that the stats input's join_date selects:

  • arrival: the vehicle's arrival_date. Future market state does not leak into training data.
  • sale: the vehicle's inferred_sold_date, or the partition date for an unsold vehicle. This gives the market conditions at the time of sale, as the legacy BMW model does.

The training asset drops labeled rows with a null arrival_date. It also drops them when an evaluation block is set, because the train/test split needs arrival_date. The training_data_quality asset check reports the dropped rows.

ModelInferenceComponent takes the same stats_lookback_days and joins point-in-time the same way, so a vehicle scored at inference sees the stats it would have seen in training.

Lifecycle features​

days_since_first_arrival and days_since_successor_arrival are computed when feature_columns lists either of them. They need model_code, model_year and arrival_date on the assembled frame, from inventory, joins or the models input, and the component raises if one is missing. The first arrival of a model year approximates its start of production, and the first arrival of the next model year approximates its end of production. Both first arrivals are taken over all inventory, before arrival_date_floor is applied.

Output asset​

The training asset is one row per partition with the pickled Pipeline, feature column metadata, the R² on its training rows, and the test set's start date and row count:

model_type, task_type, label_column, feature_columns_json,
categorical_mappings_json, training_row_count, train_r2,
test_start_date, test_row_count, serialized_model, _partition_date

Without an evaluation block, the model trains on every labeled vehicle. test_start_date and test_row_count are then null.

Evaluation​

The sold_date split puts the labeled vehicles sold on or after test_start_date, which is test_days before the partition date, in the test set. A vehicle's sold date is arrival_date + days_on_lot. The model trains on the vehicles sold earlier, the train set. The model asset writes the same model that the evaluation scores, so the model that inference loads does not learn from the most recent test_days of sales.

The split is by sold date because among recent arrivals only the fast sellers have sold. A test set of recent arrivals would score the model on fast sellers alone.

The random split holds out a fixed fraction of the labeled vehicles, so its test set covers the same period as the train set. Its test R² is therefore not comparable with a sold_date test R². Its test set changes little from one partition to the next.

The reporting/<name>_evaluation asset scores the model on two sets of labeled vehicles, which the split column names. It writes one row per partition, split value, grouping, group value and metric:

grouping, group_value, metric, value, n, split, _partition_date
ColumnDescription
groupingall, a configured grouping key, or predicted_decile
group_valueThe group's column values joined with |. A null value is written as __null__. The value is all for the all grouping and 1 to 10 for predicted_decile
metricr2, mae, rmse, median_ae, bias or mean_predicted
valueThe metric value. r2 is null for a group whose actual values are all equal
nThe group's vehicle count in the set
splittest: the test set. scored: the train set and the test set together. Null in rows written before the column existed, which are test rows

bias is the mean of predicted − actual, so a negative bias means the model under-predicts. abnormal_days_on_lot in Take Rates is days_on_lot - predicted_days_on_lot, which has the opposite sign to bias. The take-rate diffs compare an attribute's mean abnormal days on lot with its group's mean, so a bias that is constant within a take-rate group cancels. A bias that varies within the group, such as across the range of predictions or between the model codes of a base model, does not.

mean_predicted is the mean prediction. The mean actual value is mean_predicted - bias. The standard deviation of the errors is sqrt(rmse² - bias²).

The test rows show how well the model predicts vehicles it did not train on. The scored rows cover the vehicles that abnormal_days_on_lot averages over. Inference scores the train vehicles with the same model, which was trained on them, so most of their errors are in-sample errors. With a random split, the difference between the test and scored metrics measures overfitting. With a sold_date split, it measures overfitting together with any change in the data over the last test_days.

predicted_decile ranks the test set and the scored set by predicted value. Its rows show the calibration across the range of predictions, which compares mean_predicted with the mean actual value in each decile. Tied predictions share a decile. The error standard deviation per decile shows whether the errors grow with the predicted days on lot.

The all grouping's test metrics are also in the evaluation asset's materialization metadata, which the Dagster UI plots over partitions.

model_evaluation check​

model_evaluation is a WARN-severity check on the evaluation asset's test rows. It fails when:

  • the test set has fewer than min_group_size rows, in which case no test rows are written;
  • min_r2 is set and the test R² is below it, or is undefined because every actual value is equal;
  • the absolute bias of the all group or of a configured group is above max_abs_group_bias. The predicted_decile groups are left out, because they group vehicles by the model's own prediction rather than by a group that take rates average over.

Its metadata lists the ten groups with the largest absolute bias, from the same groups the bias threshold checks. The model asset is written regardless of the check result, so an empty test set never blocks predictions or take rates.

An evaluation block needs:

  • task_type: regression, the only task type with a metric set;
  • label_column: days_on_lot with a sold_date split, because the split reads the sold date from the label.

A component with an evaluation block fails at load when it does not meet one of these requirements.

Inference (ModelInferenceComponent)​

Loads the latest pickled Pipeline from the training asset, assembles the same feature matrix using the same joins and stats_inputs as training, scores every active vehicle, and writes (car_id, predicted_<label>, _partition_date).

type: ai_dagster.components.ModelInferenceComponent
attributes:
oem: mb
name: days_on_lot_predictions
start_date: "2025-01-01"
group: days_on_lot
model_asset: mb/days_on_lot_model
joins:
- asset: mb/dealers/neighborhoods
join_on: [dealer_id]
fields: [neighborhood]
stats_inputs:
- name: stats_by_dealer_neighborhood
asset: mb/inventory_stats/dealer_neighborhood
join_on: [dealer_id, neighborhood]

joins and stats_inputs must mirror the training config exactly — the model expects the same feature columns. feature_columns and label_column are read from the model artifact, so they don't need repeating.

Downstream usage​

The predicted_days_on_lot column flows back into Take Rates via a joins entry, where derived_fields compute abnormal_days_on_lot = days_on_lot - predicted_days_on_lot. Take-rate aggregations then surface attributes whose vehicles consistently sell faster or slower than the model predicts.