---
title: "RadiusNeighborsRegressor in JavaScript with @kanaries/ml"
description: "Predict numeric targets from all neighbors inside a radius using the RadiusNeighborsRegressor JavaScript and TypeScript implementation in @kanaries/ml."
canonical_url: "https://ml.kanaries.net/docs/apis/neighbors/radiusNeighborsRegressor"
markdown_url: "https://ml.kanaries.net/docs/apis/neighbors/radiusNeighborsRegressor.md"
---
# RadiusNeighborsRegressor in JavaScript

## Algorithm overview

RadiusNeighborsRegressor predicts continuous values from all training samples within a fixed radius. It can be more stable than K-neighbor regression when sample density varies across the feature space.

## JavaScript implementation

`@kanaries/ml` provides `Neighbors.RadiusNeighborsRegressor` for JavaScript applications with uniform or distance-weighted averaging.

## Interactive radius-neighbors regression playground

Change the radius to control which observations contribute at each x value. The live curve uses `Neighbors.RadiusNeighborsRegressor`; gaps show locations where the chosen radius finds no neighbors.

> The HTML version includes an interactive Radius-Neighbors Regression playground powered by @kanaries/ml. You can change the dataset, noise, and model controls; add observations; and inspect live predictions plus train and holdout metrics. The runnable guide and API reference continue below. [Open the HTML page](https://ml.kanaries.net/docs/apis/neighbors/radiusNeighborsRegressor).

## Quick start example

```ts
import { Neighbors } from '@kanaries/ml';

const reg = new Neighbors.RadiusNeighborsRegressor({ radius: 1.25, weights: 'distance' });
reg.fit([[0], [1], [4]], [0, 1, 4]);
const pred = reg.predict([[0.5], [10]]);
console.log(pred);
```

## Detailed API reference

```ts
new Neighbors.RadiusNeighborsRegressor(props?: {
  radius?: number;
  weights?: 'uniform' | 'distance';
  metric?: Distance.IDistanceType;
  p?: number;
})
```

Methods:

- `fit(trainX: number[][], trainY: number[]): void`
- `predict(testX: number[][]): number[]`

If no neighbors are found for a query sample, the prediction is `Number.NaN`.
