openavmkit.outliers
Explaining outliers: the sales a model valued furthest from their price, and why.
The analysis behind pipeline.identify_outliers, as functions that return data rather than print it, so a notebook
or an app can show it:
- :func:
fit_comp_modelsand :func:find_comps: a sale's comparable sales, by layered comps. A tree of sales split on the variables (price, and price per building or land area), the sale traced down it to the smallest group of sales like it. Each comp tree is fitted once per model group, on every sale; a sale's comps leave the sale itself out, and the trace stops where at leastmin_compsother sales are left. - :func:
compare_fields: how a sale is unlike the others, field by field: against its comps, and where it sits among the group's sales. - :func:
error_patterns: what a model's misses have in common: for each field, the share of the model's error that lines up with it, kept only when it beats chance (shuffled errors). - :func:
error_clustering: whether the errors are more alike between neighbours than chance (Moran's I).
The error of a sale is log(value / price): 0 when valued at its price, below 0 when valued low.
CompModels
dataclass
CompModels(features, unit, price_field, price=None, impr=None, land=None)
A model group's comp trees: on price, on price per building area (improved sales) and on price per land area (vacant sales); any can be None where there are too few sales to fit it.
Comps
dataclass
Comps(basis, keys, conditions=list(), depth=0, full_depth=0, per_area=None, says=None)
A sale's comparable sales: the sales of the deepest part of its comp tree with at least min_comps others.
compare_fields
compare_fields(subject, df_group, comp_keys, fields, numeric=None)
Each field: the sale's value, its comps' (median of a number, most common category), where it sits among the group's sales (a number: its percentile; a category: the share with its value), and whether it stands out: among the group's extremes (under the 5th or over the 95th percentile, a category under 5%), or unlike its comps (more than the group's middle half apart; a category its comps mostly don't share). Standing out first.
Source code in openavmkit/outliers.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 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 401 402 403 404 405 406 407 408 | |
error_clustering
error_clustering(df_group, ratio_field='ratio', k=8, shuffles=199, alpha=0.05, seed=0)
Whether the errors are more alike between neighbours than chance: Moran's I over each sale's k nearest
(latitude, longitude), and whether it beats shuffles shuffles. (None, None) without places for 30 sales.
Source code in openavmkit/outliers.py
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 | |
error_patterns
error_patterns(df_group, fields, ratio_field='ratio', numeric=None, outliers=None, min_bucket=10, shuffles=300, min_share=0.02, alpha=0.05, seed=0)
What a model's misses have in common. Over every sale of the group (not only the outliers: chosen for being
wrong, they'd mislead), each field's buckets and the share of the error's spread between them (0 when the model's
mistakes are random with respect to the field). Kept when it's min_share or more and beats shuffles
shuffles of the errors (fewer than alpha as high); ranked. Each with the bucket that pulls hardest, its sales,
the outliers among them (outliers: a mask), the model's average error on them and on the rest (-0.18: valued
18% low), and goes_with: a field ranked above whose bucket is mostly the same sales (Jaccard 0.5 or more).
Source code in openavmkit/outliers.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | |
find_comps
find_comps(models, df_sales, subject, min_comps=5)
A sale's comps: traced down its comp tree (per building area if improved, per land area if vacant, else on
price), the sale itself left out, to the deepest node with at least min_comps other sales of df_sales (the
group's, as fitted on). None when there's no tree for it.
Source code in openavmkit/outliers.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
fit_comp_models
fit_comp_models(df_sales, features, unit, price_field='sale_price_time_adj')
Fit a model group's comp trees on its sales (each with vacant_sale, the price and the features): price on
every sale, price per finished area on the improved ones, price per land area on the vacant ones.
Source code in openavmkit/outliers.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
summarize_conditions
summarize_conditions(conditions)
A comp path's conditions merged per field, in the order fields first come up: the tightest bounds of a number
(at_most, over), a category's value (is) or the values it isn't (is_not). What the comps share, in
as few words as the path allows.
Source code in openavmkit/outliers.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |