Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fk_regression... A faster implementation of univariate kernel regression #30

Open
Larsvanderlaan opened this issue Sep 16, 2023 · 0 comments

Comments

@Larsvanderlaan
Copy link

Larsvanderlaan commented Sep 16, 2023

In case this is of interest, I stumbled upon an implementation of kernel regression in one dimension that offers significant speed improvements and scalability compared to npreg (and this is an understatement). The package is called FKSUM (an interesting name choice), and you can find a link to it here.

Below is the SuperLearner wrapper I have been using. I used the Nadaraya-Watson implementation, but `fk_regression' also supports local linear regression, which may be a better option.

SL.fastkernel <- function (Y, X, newX, family = gaussian(), obsWeights = rep(1,
                                                                               length(Y)), rangeThresh = 1e-07, ...)
{

  X <- as.matrix(X)
  newX <- as.matrix(newX)
  if(ncol(X) > 1) {
    stop("Univariate X kernel smooths only.")
  }
  fit <- FKSUM::fk_regression(X, Y, type = 'NW')
  pred <- predict(fit, xtest = newX)

  fit <- list(object = fit)
  class(fit) <- "SL.fastkernel"
  out <- list(pred = pred, fit = fit)
  return(out)
}

predict.SL.fastkernel <- function (object, newdata, ...)
{

  pred <- predict(object, xtest = as.matrix(newdata))

  return(pred)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant