yobx.sklearn.neighbors.kneighbors#
- yobx.sklearn.neighbors.kneighbors.sklearn_knn_classifier(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: KNeighborsClassifier, X: str, name: str = 'knn_clf') str | Tuple[str, str][source]#
Converts a
sklearn.neighbors.KNeighborsClassifierinto ONNX.The converter supports all metrics implemented by
_compute_pairwise_distances(). The effective metric (and any extra parameters such as the Minkowski exponentp) are read fromestimator.effective_metric_andestimator.effective_metric_params_.Supported metrics:
"sqeuclidean","euclidean","cosine","manhattan"(aliases:"cityblock","l1"),"chebyshev","minkowski". The"euclidean"and"sqeuclidean"metrics usecom.microsoft.CDistwhen that domain is registered; all other metrics use the standard-ONNX path.Full graph structure (standard-ONNX path):
X (N, F) │ └─── pairwise distances ────────────────────────────────────► dists (N, M) │ +----------------------+ │ TopK(k, axis=1, largest=0) ──► indices (N, k) │ Gather(training_labels_encoded) ──────► neighbor_labels (N, k) │ Reshape(-1) → OneHot(n_classes) → Reshape(N, k, n_classes) ──► │ ReduceSum(axis=1) ──► votes (N, n_classes) │ ArgMax(axis=1) → Gather(classes_) ──► labels (N,) │ Div(votes, ReduceSum(votes, axis=1)) ──► probabilities (N, n_classes)- Parameters:
g – graph builder
sts – shapes defined by scikit-learn
outputs – desired output names;
outputs[0]receives the predicted labels andoutputs[1](if present) receives the class probabilitiesestimator – a fitted
KNeighborsClassifierX – input tensor name
name – prefix names for the added nodes
- Returns:
predicted label tensor (and optionally probability tensor as second output)
- yobx.sklearn.neighbors.kneighbors.sklearn_knn_regressor(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: KNeighborsRegressor, X: str, name: str = 'knn_reg') str[source]#
Converts a
sklearn.neighbors.KNeighborsRegressorinto ONNX.The converter supports all metrics implemented by
_compute_pairwise_distances(). The effective metric (and any extra parameters such as the Minkowski exponentp) are read fromestimator.effective_metric_andestimator.effective_metric_params_.Supported metrics:
"sqeuclidean","euclidean","cosine","manhattan"(aliases:"cityblock","l1"),"chebyshev","minkowski". The"euclidean"and"sqeuclidean"metrics usecom.microsoft.CDistwhen that domain is registered; all other metrics use the standard-ONNX path.- Parameters:
g – graph builder
sts – shapes defined by scikit-learn
outputs – desired output names
estimator – a fitted
KNeighborsRegressorX – input tensor name
name – prefix names for the added nodes
- Returns:
predicted value tensor