Clustering, Neighbors & NB
RadiusNeighborsRegressor
Radius-based nearest neighbors regressor supporting 1D and multi-output 2D targets with uniform or distance weighting.
Overview & Backend Support
RadiusNeighborsRegressor predicts continuous target values by averaging (uniformly or weighted by inverse distance) the targets of all training samples within a fixed radius of each query point. It supports both 1D targets (n_samples,) and multi-output 2D targets (n_samples, n_outputs). Queries with no neighbors inside radius receive NaN.
- Backend primitives:
N3(pairwise_l2_sq) across CPU (Rayon), CUDA,wgpu, and Google TPU for Euclidean / Minkowski (p=2) queries;"manhattan"/"l1","chebyshev","cosine", and general Minkowskipare also supported. - Incremental learning (
partial_fit): Not supported. - Persistence: Supports binary
.ditserialization viasave(path),RadiusNeighborsRegressor.load(path, device=...),ochreml.save(), andochreml.load().
Import & Signature
from ochreml.neighbors import RadiusNeighborsRegressor
# or lazily from top-level:
from ochreml import RadiusNeighborsRegressor
RadiusNeighborsRegressor(
radius: float = 1.0,
*,
weights: str = "uniform",
metric: str = "minkowski",
p: float = 2.0,
device: str | None = None,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
radius | float | 1.0 | Maximum distance threshold for neighbor inclusion in regression and radius_neighbors queries. |
weights | {"uniform", "distance"} | "uniform" | Weight function used when averaging neighbor targets. |
metric | {"minkowski", "euclidean", "l2", "manhattan", "l1", "chebyshev", "cosine"} | "minkowski" | Distance metric used for neighbor search. |
p | float | 2.0 | Power parameter for the Minkowski metric. |
device | str | None | None | Target compute device ("auto", "cpu", "cuda:0", "wgpu", "tpu:0"). Defaults to ochreml.get_default_device(). |
Attributes
| Attribute | Type | Description |
|---|---|---|
n_features_in_ | int | None | Number of features seen during fit. |
n_samples_fit_ | int | None | Number of indexed training samples. |
device_ | str | None | Resolved hardware device string used by the underlying Rust model. |
Methods
| Method | Signature | Description |
|---|---|---|
fit | fit(X, y) -> RadiusNeighborsRegressor | Index training features X and targets y ((n_samples,) or (n_samples, n_outputs)). |
predict | predict(X) -> ndarray | Predict target values of shape (n_queries,) or (n_queries, n_outputs). Queries with no neighbors within radius return NaN. |
score | score(X, y) -> float | Return the coefficient of determination (R^2) on (X, y). |
radius_neighbors | radius_neighbors(X=None, radius=None, return_distance=True, sort_results=False) | Return (distances, indices) or indices as object arrays of per-query 1D arrays. If X is None, queries the training set excluding each point itself. |
save | save(path: str) -> None | Save the fitted regressor to a binary .dit file. |
load | RadiusNeighborsRegressor.load(path: str, device: str | None = None) -> RadiusNeighborsRegressor | Load a fitted regressor from a binary .dit file. |
to | to(device: str) -> RadiusNeighborsRegressor | Move estimator compute target to another hardware device. |
Example
import numpy as np
from ochreml.neighbors import RadiusNeighborsRegressor
X = np.array([[0.0], [0.5], [1.0], [2.0]], dtype=np.float64)
y = np.array([0.0, 0.25, 1.0, 4.0], dtype=np.float64)
reg = RadiusNeighborsRegressor(radius=0.75, weights="distance")
reg.fit(X, y)
X_test = np.array([[0.25], [1.2], [5.0]], dtype=np.float64)
print("Predictions (last is NaN):", reg.predict(X_test))