openavmkit.utilities.modeling
Model class definitions.
Defines the model classes used by :mod:openavmkit.modeling to train and
predict property values. Includes:
- Tree-based wrappers —
XGBoostModel,LightGBMModel,CatBoostModel - Linear models —
MRAModel,MultiMRAModel - Geographic models —
GWRModel,LocalAreaModel,SpatialLagModel - Baselines —
GarbageModel,AverageModel,NaiveAreaModel,PassThroughModel,GroundTruthModel
Plus helpers (greedy_forward_loocv, TreeBasedCategoricalData)
shared across model fitting routines.
When adding a new model, subclass here and follow the existing pattern;
register the prediction wrapper in :mod:openavmkit.model_runner and the
params/contribs writer in :mod:openavmkit.modeling.
AverageModel
AverageModel(type, sales_chase)
An intentionally bad predictive model, to use as a sort of control. Produces predictions equal to the average of observed sale prices.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
str
|
The type of average to use |
sales_chase |
float
|
Simulates sales chasing. If 0.0, no sales chasing will occur. For any other value, predictions against sold
parcels will chase (copy) the observed sale price, with a bit of random noise equal to the value of
|
Initialize an AverageModel
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
str
|
The type of average to use |
required |
sales_chase
|
float
|
Simulates sales chasing. If 0.0, no sales chasing will occur. For any other value, predictions against sold
parcels will chase (copy) the observed sale price, with a bit of random noise equal to the value of
|
required |
Source code in openavmkit/utilities/modeling.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
CatBoostModel
CatBoostModel(regressor, cat_data)
CatBoost Model
Attributes:
| Name | Type | Description |
|---|---|---|
regressor |
CatBRegressor
|
The trained CatBoost CatBRegressor model |
cat_data |
TreeBasedCategoricalData
|
|
Source code in openavmkit/utilities/modeling.py
482 483 484 | |
GWRModel
GWRModel(coords_train, X_train, y_train, gwr_bw)
Geographic Weighted Regression Model
Attributes:
| Name | Type | Description |
|---|---|---|
coords_train |
list[tuple[float, float]]
|
list of geospatial coordinates corresponding to each observation in the training set |
X_train |
ndarray
|
2D array of independent variables' values from the training set |
y_train |
ndarray
|
1D array of dependent variable's values from the training set |
gwr_bw |
float
|
Bandwidth for GWR calculation |
df_params_test |
DataFrame
|
Coefficients for the test set |
df_params_sales |
DataFrame
|
Coefficients for the sales set |
df_params_universe |
DataFrame
|
Coefficients for the universe set |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords_train
|
list[tuple[float, float]]
|
list of geospatial coordinates corresponding to each observation in the training set |
required |
X_train
|
ndarray
|
2D array of independent variables' values from the training set |
required |
y_train
|
ndarray
|
1D array of dependent variable's values from the training set |
required |
gwr_bw
|
float
|
Bandwidth for GWR calculation |
required |
Source code in openavmkit/utilities/modeling.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
GarbageModel
GarbageModel(min_value, max_value, sales_chase, normal)
An intentionally bad predictive model, to use as a sort of control. Produces random predictions.
Attributes:
| Name | Type | Description |
|---|---|---|
min_value |
float
|
The minimum value of to "predict" |
max_value |
float
|
The maximum value of to "predict" |
sales_chase |
float
|
Simulates sales chasing. If 0.0, no sales chasing will occur. For any other value, predictions against sold
parcels will chase (copy) the observed sale price, with a bit of random noise equal to the value of
|
normal |
bool
|
If True, the randomly generated predictions follow a normal distribution based on the observed sale price's standard deviation. If False, randomly generated predictions follow a uniform distribution between min and max. |
Initialize a GarbageModel
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_value
|
float
|
The minimum value of to "predict" |
required |
max_value
|
float
|
The maximum value of to "predict" |
required |
sales_chase
|
float
|
Simulates sales chasing. If 0.0, no sales chasing will occur. For any other value, predictions against sold
parcels will chase (copy) the observed sale price, with a bit of random noise equal to the value of
|
required |
normal
|
bool
|
If True, the randomly generated predictions follow a normal distribution based on the observed sale price's standard deviation. If False, randomly generated predictions follow a uniform distribution between min and max. |
required |
Source code in openavmkit/utilities/modeling.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
GroundTruthModel
GroundTruthModel(observed_field, ground_truth_field)
Mostly only used in Synthetic models, where you want to compare against simulation ground_truth instead of
observed sale price, which you can never do in real life.
Attributes:
| Name | Type | Description |
|---|---|---|
observed_field |
str
|
The field that represents observed sale prices |
ground_truth_field |
str
|
The field that represents platonic ground truth |
Initialize a GroundTruthModel object
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observed_field
|
str
|
The field that represents observed sale prices |
required |
ground_truth_field
|
str
|
The field that represents platonic ground truth |
required |
Source code in openavmkit/utilities/modeling.py
242 243 244 245 246 247 248 249 250 251 252 253 | |
LayeredCompModel
LayeredCompModel(model)
Layered Comp Model
A bagging ensemble version of the LayeredCompModel algorithm that reduces variance and automatically optimizes the weight_falloff for each tree in the ensemble.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
LayeredCompModel
|
The trained LayeredCompModel from the layeredcompmodel package |
Initialize a LayeredCompModel
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
LayeredCompModel
|
The trained LayeredCompModel instance |
required |
Source code in openavmkit/utilities/modeling.py
518 519 520 521 522 523 524 525 526 | |
LightGBMModel
LightGBMModel(booster, cat_data)
LightGBM Model
Attributes:
| Name | Type | Description |
|---|---|---|
booster |
Booster
|
The trained LightGBM Booster model |
cat_data |
TreeBasedCategoricalData
|
|
Source code in openavmkit/utilities/modeling.py
454 455 456 | |
LocalAreaModel
LocalAreaModel(loc_map, location_fields, overall_per_impr_area, overall_per_land_area, sales_chase)
Produces predictions equal to the localized average price/area of land or building, multiplied by the observed size of the parcel's land or building, depending on whether it's vacant or improved.
Unlike NaiveAreaModel, this model is sensitive to location, based on user-specified locations, and might
actually result in decent predictions.
Attributes:
| Name | Type | Description |
|---|---|---|
loc_map |
dict[str : tuple[DataFrame, DataFrame]
|
A dictionary that maps location field names to localized per-area values. The dictionary itself is keyed by the names of the location fields themselves (e.g. "neighborhood", "market_region", "census_tract", etc.) or whatever the user specifies. Each entry is a tuple containing two DataFrames:
Each DataFrame is keyed by the unique values for the given location. (e.g. "River heights", "Meadowbrook",
etc., if the location field in question is "neighborhood") The other field in each DataFrame will be
|
location_fields |
list
|
List of location fields used (e.g. "neighborhood", "market_region", "census_tract", etc.) |
overall_per_impr_area |
float
|
Fallback value per improved square foot, to use for parcels of unspecified location. Based on the overall average value for the dataset. |
overall_per_land_area |
float
|
Fallback value per land square foot, to use for parcels of unspecified location. Based on the overall average value for the dataset. |
sales_chase |
float
|
Simulates sales chasing. If 0.0, no sales chasing will occur. For any other value, predictions against sold
parcels will chase (copy) the observed sale price, with a bit of random noise equal to the value of
|
Initialize a LocalAreaModel
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loc_map
|
dict[str : tuple[DataFrame, DataFrame]
|
A dictionary that maps location field names to localized per-area values. The dictionary itself is keyed by the names of the location fields themselves (e.g. "neighborhood", "market_region", "census_tract", etc.) or whatever the user specifies. Each entry is a tuple containing two DataFrames:
Each DataFrame is keyed by the unique values for the given location. (e.g. "River heights", "Meadowbrook",
etc., if the location field in question is "neighborhood") The other field in each DataFrame will be
|
required |
location_fields
|
list
|
List of location fields used (e.g. "neighborhood", "market_region", "census_tract", etc.) |
required |
overall_per_impr_area
|
float
|
Fallback value per improved square foot, to use for parcels of unspecified location. Based on the overall average value for the dataset. |
required |
overall_per_land_area
|
float
|
Fallback value per land square foot, to use for parcels of unspecified location. Based on the overall average value for the dataset. |
required |
sales_chase
|
float
|
Simulates sales chasing. If 0.0, no sales chasing will occur. For any other value, predictions against sold
parcels will chase (copy) the observed sale price, with a bit of random noise equal to the value of
|
required |
Source code in openavmkit/utilities/modeling.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
MRAModel
MRAModel(fitted_model, intercept, log=False)
Multiple Regression Analysis Model
Plain 'ol (multiple) linear regression
Attributes:
| Name | Type | Description |
|---|---|---|
fitted_model |
RegressionResults
|
Fitted model from running the regression |
intercept |
bool
|
Whether the model was fit with an intercept or not. |
log |
bool
|
Whether the model was fit on a log-transformed target. When True, predictions are
produced in log space and exponentiated back to price space by |
Source code in openavmkit/utilities/modeling.py
544 545 546 547 | |
MultiMRAModel
MultiMRAModel(coef_map, global_coef, feature_names, intercept, location_fields, log=False)
Multi-MRA (hierarchical local OLS) model.
For each location field (e.g. "block", "neighborhood", ...), and for each distinct value of that field, we fit a separate OLS regression using the same set of independent variables.
We store: - A global OLS coefficient vector (fallback when no local model applies) - A mapping from (location_field, location_value) -> coefficient vector - The feature_names (column order) used for all regressions - Whether an intercept was used - The location_fields (ordered most specific -> least specific)
Attributes:
| Name | Type | Description |
|---|---|---|
coef_map |
dict[str, dict[Any, ndarray]]
|
Mapping from location field name to a dict mapping location value -> coefficient vector (aligned with feature_names). |
global_coef |
ndarray
|
Coefficient vector for the global OLS regression. |
feature_names |
list[str]
|
Ordered list of feature names used for all regressions. |
intercept |
bool
|
Whether an intercept column was used. |
location_fields |
list[str]
|
Location fields in order from most specific to least specific. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coef_map
|
dict[str, dict[Any, ndarray]]
|
Mapping from location field name to a dict mapping location value -> coefficient vector (aligned with feature_names). |
required |
global_coef
|
ndarray
|
Coefficient vector for the global OLS regression. |
required |
feature_names
|
list[str]
|
Ordered list of feature names used for all regressions. |
required |
intercept
|
bool
|
Whether an intercept column was used. |
required |
location_fields
|
list[str]
|
Location fields in order from most specific to least specific. |
required |
log
|
bool
|
Whether the regressions were fit on a log-transformed target. When True,
predictions are produced in log space and exponentiated back by |
False
|
Source code in openavmkit/utilities/modeling.py
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
NGBoostModel
NGBoostModel(regressor, cat_data)
NGBoost Model (probabilistic gradient boosting)
NGBoost predicts a full probability distribution per row, so it surfaces a
per-parcel predictive standard deviation in addition to a point estimate.
Its base learner is a numeric-only sklearn tree, so categoricals are encoded
via cat_data rather than passed natively.
Attributes:
| Name | Type | Description |
|---|---|---|
regressor |
NGBRegressor
|
The trained NGBoost NGBRegressor model |
cat_data |
TreeBasedCategoricalData
|
Categorical metadata used to build the numeric matrix NGBoost requires |
Source code in openavmkit/utilities/modeling.py
502 503 504 | |
NaiveAreaModel
NaiveAreaModel(dep_per_built_area, dep_per_land_area, sales_chase)
An intentionally bad predictive model, to use as a sort of control. Produces predictions equal to the prevailing average price/area of land or building, multiplied by the observed size of the parcel's land or building, depending on whether it's vacant or improved.
Attributes:
| Name | Type | Description |
|---|---|---|
dep_per_built_area |
float
|
Dependent variable value divided by improved square footage |
dep_per_land_area |
float
|
Dependent variable value divided by land square footage |
sales_chase |
float
|
Simulates sales chasing. If 0.0, no sales chasing will occur. For any other value, predictions against sold
parcels will chase (copy) the observed sale price, with a bit of random noise equal to the value of
|
Initialize a NaiveAreaModel
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dep_per_built_area
|
float
|
Dependent variable value divided by improved square footage |
required |
dep_per_land_area
|
float
|
Dependent variable value divided by land square footage |
required |
sales_chase
|
float
|
Simulates sales chasing. If 0.0, no sales chasing will occur. For any other value, predictions against sold
parcels will chase (copy) the observed sale price, with a bit of random noise equal to the value of
|
required |
Source code in openavmkit/utilities/modeling.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
PassThroughModel
PassThroughModel(field, engine)
Mostly used for representing existing valuations to compare against, such as the Assessor's values
Attributes:
| Name | Type | Description |
|---|---|---|
field |
str
|
The field that holds the values you want to pass through as predictions |
Initialize a PassThroughModel
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
The field that holds the values you want to pass through as predictions |
required |
engine
|
str
|
The model engine ("assessor" or "pass_through") |
required |
Source code in openavmkit/utilities/modeling.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
SpatialLagModel
SpatialLagModel(per_area)
Use a spatial lag field as your prediction
Attributes:
| Name | Type | Description |
|---|---|---|
per_area |
bool
|
If True, normalize by area unit. If False, use the direct value of the spatial lag field. |
Initialize a SpatialLagModel
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
per_area
|
bool
|
If True, normalize by square foot. If False, use the direct value of the spatial lag field. |
required |
Source code in openavmkit/utilities/modeling.py
265 266 267 268 269 270 271 272 273 | |
TreeBasedCategoricalData
dataclass
TreeBasedCategoricalData(feature_names, categorical_cols, category_levels, bool_cols)
Stores categorical metadata needed to reproduce LightGBM-compatible categorical encodings and generate numeric matrices for SHAP.
apply
apply(X, *, fill_missing_cat=False, missing_token='__MISSING__')
Reapply categorical + boolean structure to a dataframe. Unknown categories become NaN (categorical missing) unless fill_missing_cat=True.
Source code in openavmkit/utilities/modeling.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |
from_training_data
classmethod
from_training_data(X_train, categorical_cols)
Build metadata from training data AFTER categoricals have been converted to pandas 'category' dtype.
Source code in openavmkit/utilities/modeling.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
to_numeric_matrix
to_numeric_matrix(X)
Convert dataframe to a numeric matrix compatible with SHAP. Categoricals -> integer codes, unknowns/missing -> np.nan.
Source code in openavmkit/utilities/modeling.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
XGBoostModel
XGBoostModel(regressor, cat_data)
XGBoost Model
Attributes:
| Name | Type | Description |
|---|---|---|
regressor |
XGBRegressor
|
The trained XGBoost XGBRegressor model |
cat_data |
TreeBasedCategoricalData
|
|
Source code in openavmkit/utilities/modeling.py
468 469 470 | |
greedy_forward_loocv
greedy_forward_loocv(X, y, *, k_max=None, min_gain=0.002, standardize=True, prescreen_k=15)
Greedy forward selection maximizing LOOCV R² (fast). Auto-detects intercept handling: - If X contains a 'const' column, treats it as intercept (always included, not selectable, not standardized). - Otherwise, adds an intercept internally (as before).
Assumes X, y are numeric, aligned, and NaN-free.
Source code in openavmkit/utilities/modeling.py
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 | |