hessband.selectors.analytic_newton(X: ndarray, y: ndarray, kernel: str, predict_fn: Callable[[ndarray, ndarray, ndarray, float, str], ndarray], h_init: float, h_min: float = 0.001, folds: int = 5, tol: float = 0.001, max_iter: int = 10) float[source]

Analytic Newton method for LOOCV risk minimization.

Returns the bandwidth without performing CV evaluations in the loop.

Parameters:
  • X – Input values.

  • y – Target values.

  • kernel – Kernel to use.

  • predict_fn – Prediction function.

  • h_init – Initial bandwidth.

  • h_min – Minimum bandwidth.

  • folds – Number of folds for cross-validation.

  • tol – Tolerance for convergence.

  • max_iter – Maximum number of iterations.

Returns:

The optimal bandwidth.

hessband.selectors.bayes_opt_bandwidth(X: ndarray, y: ndarray, kernel: str, predict_fn: Callable[[ndarray, ndarray, ndarray, float, str], ndarray], a: float, b: float, folds: int = 5, init_points: int = 5, n_iter: int = 10) float[source]

Bayesian optimization for bandwidth selection.

Parameters:
  • X – Input values.

  • y – Target values.

  • kernel – Kernel to use.

  • predict_fn – Prediction function.

  • a – Lower bound of the search interval.

  • b – Upper bound of the search interval.

  • folds – Number of folds for cross-validation.

  • init_points – Number of initial points for Bayesian optimization.

  • n_iter – Number of iterations for Bayesian optimization.

Returns:

The optimal bandwidth.

hessband.selectors.golden_section(X: ndarray, y: ndarray, kernel: str, predict_fn: Callable[[ndarray, ndarray, ndarray, float, str], ndarray], a: float, b: float, folds: int = 5, tol: float = 0.001, max_iter: int = 20) float[source]

Golden-section search for bandwidth selection.

Parameters:
  • X – Input values.

  • y – Target values.

  • kernel – Kernel to use.

  • predict_fn – Prediction function.

  • a – Lower bound of the search interval.

  • b – Upper bound of the search interval.

  • folds – Number of folds for cross-validation.

  • tol – Tolerance for convergence.

  • max_iter – Maximum number of iterations.

Returns:

The optimal bandwidth.

hessband.selectors.grid_search_cv(X: ndarray, y: ndarray, kernel: str, predict_fn: Callable[[ndarray, ndarray, ndarray, float, str], ndarray], h_grid: ndarray, folds: int = 5) float[source]

Performs grid search for bandwidth selection.

Parameters:
  • X – Input values.

  • y – Target values.

  • kernel – Kernel to use.

  • predict_fn – Prediction function.

  • h_grid – Grid of bandwidths to search over.

  • folds – Number of folds for cross-validation.

Returns:

The best bandwidth found.

hessband.selectors.newton_fd(X: ndarray, y: ndarray, kernel: str, predict_fn: Callable[[ndarray, ndarray, ndarray, float, str], ndarray], h_init: float, h_min: float = 0.001, folds: int = 5, tol: float = 0.001, max_iter: int = 10, eps: float = 0.0001) float[source]

Finite-difference Newton method for bandwidth selection.

Parameters:
  • X – Input values.

  • y – Target values.

  • kernel – Kernel to use.

  • predict_fn – Prediction function.

  • h_init – Initial bandwidth.

  • h_min – Minimum bandwidth.

  • folds – Number of folds for cross-validation.

  • tol – Tolerance for convergence.

  • max_iter – Maximum number of iterations.

  • eps – Epsilon for finite differences.

Returns:

The optimal bandwidth.

hessband.selectors.nw_predict(X_train: ndarray, y_train: ndarray, X_test: ndarray, h: float, kernel: str = 'gaussian') ndarray[source]

Computes Nadaraya-Watson predictions.

Parameters:
  • X_train – Training input values.

  • y_train – Training target values.

  • X_test – Test input values.

  • h – Bandwidth.

  • kernel – Kernel to use (‘gaussian’ or ‘epanechnikov’).

Returns:

The predicted values for X_test.

hessband.selectors.plug_in_bandwidth(X: ndarray) float[source]

Computes a plug-in bandwidth.

Uses Silverman’s rule of thumb.

Parameters:

X – Input values.

Returns:

The plug-in bandwidth.

hessband.selectors.select_nw_bandwidth(X: ndarray, y: ndarray, kernel: str = 'gaussian', method: str = 'analytic', folds: int = 5, h_bounds: tuple[float, float] = (0.01, 1.0), grid_size: int = 30, init_bandwidth: float | None = None) float[source]

Selects the optimal bandwidth for Nadaraya-Watson regression.

This function provides a unified interface for various bandwidth selection methods for Nadaraya-Watson kernel regression. The analytic method uses gradients and Hessians of the cross-validation risk for efficient optimization.

Parameters:
  • X – Input values (univariate predictor variable).

  • y – Target values (response variable).

  • kernel – Kernel function to use for regression (‘gaussian’ or ‘epanechnikov’).

  • method – Bandwidth selection method.

  • folds – Number of folds for cross-validation (ignored for ‘plugin’ method).

  • h_bounds – (min_bandwidth, max_bandwidth) search bounds.

  • grid_size – Number of grid points for ‘grid’ method.

  • init_bandwidth – Initial bandwidth for Newton-based methods. If None, uses plug-in rule.

Returns:

The optimal bandwidth that minimizes cross-validation risk.