Skip to content

Commit 2a68bec

Browse files
committed
Fix multivariate default n.best to scale with observations, not features
The default n.best in nns_m_reg used floor((1-dependence)*sqrt(ncol)), mirroring R's Multivariate_Regression.R:129 where n is shadowed by ncol(original.IVs). With sqrt(#features) <= 2.24 for typical widths, the default collapsed to n.best = 1 for any dependence above ~0.1, making order=None predictions identical to order="max" (pure 1-NN) on continuous multivariate data. Use sqrt(nrow) instead, consistent with the sqrt(n_obs) grid nns_stack already cross-validates over. Verified against a live patched R NNS 13.1 build on shared data: order=None now differs from order="max" identically in both languages (59/60 test rows bit-exact, remaining row is the out-of-support gradient-extension path). Full test suite passes; no recorded R-parity case is affected because all cached multivariate fixtures resolve to n.best = 1 under both formulas. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BPbZvtDw4h2XJo9w5hw57h
1 parent 1196e98 commit 2a68bec

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎src/nns/multivariate_regression.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def _resolve_n_best(
385385
if n_best is not None:
386386
return max(1, int(n_best))
387387
dependence = _copula_matrix(np.column_stack((x, y)))
388-
return max(1, math.floor((1.0 - dependence) * math.sqrt(x.shape[1])))
388+
return max(1, math.floor((1.0 - dependence) * math.sqrt(x.shape[0])))
389389

390390

391391
def _k_as_count(k: KValue, row_count: int) -> int:

0 commit comments

Comments
 (0)