knn – k-nearest-neighbours regression.#
Back to family axis | Back to L4 | Browse all options
Operational op under axis
family, sub-layerL4_A_model_selection, layerl4. Standalone callable:mf.functions.knn_fit.
Function signature#
mf.functions.knn_fit(
X: np.ndarray | pd.DataFrame,
y: np.ndarray | pd.Series,
) -> KNNFitResult
Parameters#
name |
type |
default |
constraint |
description |
|---|---|---|---|---|
|
`np.ndarray |
pd.DataFrame` |
— |
— |
|
`np.ndarray |
pd.Series` |
— |
— |
Returns#
KNNFitResult — frozen dataclass with fit results.
Attribute |
Type |
Description |
|---|---|---|
|
|
Neighbour count k requested. |
|
|
Actual k used (clipped to training set size). |
|
|
Number of input features. |
|
|
Predictions for new data X, shape (n_samples,). |
|
|
Table: neighbour counts and feature count. |
Behavior#
Memorises training data; predicts via nearest-neighbour averaging. Cheap, non-parametric.
When to use
Non-parametric baselines; sensitivity studies.
In recipe context#
Set params.family = "knn" in the relevant layer to activate this op within a recipe:
# Layer L4 recipe fragment
params:
family: knn
References#
macroforecast design Part 2, L4: ‘forecasting model is the layer where every authoring iteration ends – pick family, tune, repeat.’
Cover & Hart (1967) ‘Nearest neighbor pattern classification’, IEEE Trans. on Information Theory 13(1).