yobx.sklearn.neighbors.radiusneighbors#

yobx.sklearn.neighbors.radiusneighbors.sklearn_radius_neighbors_classifier(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: RadiusNeighborsClassifier, X: str, name: str = 'rnn_clf') str | Tuple[str, str][source]#

Converts a sklearn.neighbors.RadiusNeighborsClassifier into ONNX.

Both weights='uniform' and weights='distance' are supported. Single-output and multi-output estimators are supported.

For weights='distance', each in-radius neighbour is weighted by 1 / max(distance, 1e-12). When a query point coincides with a training point (distance ≈ 0), that training point’s vote dominates.

For multi-output estimators (_y.shape[1] > 1), each output is predicted independently. Only the predicted labels are returned (probability output is not available in multi-output mode).

Supported metrics are the same as for yobx.sklearn.neighbors.kneighbors.sklearn_knn_classifier() (see yobx.sklearn.neighbors.kneighbors._compute_pairwise_distances()).

Parameters:
  • g – graph builder

  • sts – shapes defined by scikit-learn

  • outputs – desired output names; outputs[0] receives the predicted labels and outputs[1] (if present) receives the class probabilities (single-output mode only).

  • estimator – a fitted RadiusNeighborsClassifier

  • X – input tensor name

  • name – prefix for node names

Returns:

predicted label tensor (and optionally probability tensor for single-output estimators)

Raises:

NotImplementedError – if opset < 13

yobx.sklearn.neighbors.radiusneighbors.sklearn_radius_neighbors_regressor(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: RadiusNeighborsRegressor, X: str, name: str = 'rnn_reg') str[source]#

Converts a sklearn.neighbors.RadiusNeighborsRegressor into ONNX.

Both weights='uniform' and weights='distance' are supported. Single-output and multi-output estimators are supported.

For weights='distance', each in-radius neighbour is weighted by 1 / max(distance, 1e-12). When a query point coincides with a training point (distance ≈ 0), that training point’s weight dominates.

For multi-output estimators (_y.shape[1] > 1), the prediction is a (N, n_targets) tensor.

For query points with no neighbour within the radius the prediction is NaN (float division 0 / 0 for uniform, or 0 / 0 for distance weights), which mirrors the fact that sklearn raises ValueError for such points at runtime.

Supported metrics are the same as for yobx.sklearn.neighbors.kneighbors.sklearn_knn_regressor() (see yobx.sklearn.neighbors.kneighbors._compute_pairwise_distances()).

Parameters:
  • g – graph builder

  • sts – shapes defined by scikit-learn

  • outputs – desired output names

  • estimator – a fitted RadiusNeighborsRegressor

  • X – input tensor name

  • name – prefix for node names

Returns:

predicted value tensor — shape (N,) for single-output or (N, n_targets) for multi-output estimators

Raises:

NotImplementedError – if opset < 13