Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Comments

ENH: prediction based on nearest model only or a custom bandwidth#52

Merged
martinfleis merged 3 commits intomainfrom
nearest
Jan 6, 2026
Merged

ENH: prediction based on nearest model only or a custom bandwidth#52
martinfleis merged 3 commits intomainfrom
nearest

Conversation

@martinfleis
Copy link
Member

xref #42

@codecov
Copy link

codecov bot commented Jan 6, 2026

Codecov Report

❌ Patch coverage is 94.64286% with 3 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@56023d4). Learn more about missing BASE report.

Files with missing lines Patch % Lines
gwlearn/base.py 94.64% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #52   +/-   ##
=======================================
  Coverage        ?   86.17%           
=======================================
  Files           ?        6           
  Lines           ?      752           
  Branches        ?        0           
=======================================
  Hits            ?      648           
  Misses          ?      104           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@martinfleis martinfleis marked this pull request as ready for review January 6, 2026 13:19
@martinfleis martinfleis requested a review from Copilot January 6, 2026 13:19
@martinfleis martinfleis mentioned this pull request Jan 6, 2026
3 tasks
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements prediction based on nearest local model as an alternative to the existing ensemble approach, addressing issue #42. The enhancement provides users with a faster prediction option when working with large bandwidths, while maintaining the option to use the more computationally expensive ensemble method.

Key changes:

  • Added a method parameter to predict() and predict_proba() methods with options "nearest" (default) or "ensemble"
  • Implemented _prepare_prediction_nearest() to find the nearest training location for prediction
  • Fixed indexing bug in _prepare_prediction_neighborhoods() to properly map spatial indices to model IDs

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 11 comments.

File Description
gwlearn/base.py Adds method parameter to prediction methods, implements nearest-neighbor prediction logic, refactors ensemble prediction into _predict_local_ensemble(), and fixes spatial index mapping bug
gwlearn/tests/test_base.py Parametrizes existing prediction tests to cover both "nearest" and "ensemble" methods, adjusts assertions to handle potential NA values from nearest method, and adds method-specific test cases for value validation
Comments suppressed due to low confidence (1)

gwlearn/tests/test_base.py:630

  • The test should differentiate between the "nearest" and "ensemble" methods, similar to how test_regressor_predict_comparison_with_focal_pred does. With the "nearest" method and predicting on training data, the predictions should exactly match the focal probabilities (proba_), not just be similar with tolerance. Consider adding a conditional check: for "nearest" use exact comparison, for "ensemble" use the current tolerance-based comparison.
    # Get predictions for the same data used for training
    predicted_proba = clf.predict_proba(X, geometry, method=method)

    # Compare with proba_ (should be very similar but not identical
    # because proba_ is calculated during training without using the focal point)
    pd.testing.assert_series_equal(
        predicted_proba.loc[2],
        clf.proba_.loc[2],
        check_exact=False,
        atol=0.05,  # Allow some tolerance because they're not identical
    )

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@martinfleis martinfleis changed the title ENH: prediction based on nearest model only ENH: prediction based on nearest model only or a custom bandwidth Jan 6, 2026
@martinfleis martinfleis merged commit 25533e1 into main Jan 6, 2026
14 checks passed
@martinfleis martinfleis deleted the nearest branch January 6, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant