I know there are plenty of similar questions but I need to solve the problem specifically with Bernstein polynomials
I tried something like this:
library(pracma)
train <- rnorm(100)
test <- rnorm(50)
eCDF <- ecdf(train)
# squeeze eCDF support between 0 and 1
Fy <- function(y){
b <- max(train)
a <- min(train)
eCDF((b-a)*y+a)
}
m <- min(test)
M <- max(test)
# squeeze points between 0 and 1
x_to_y <- function(x) return ((x-m)/(M-m))
# polynomial order
k = 10
x <- x_to_y(test)
# bernstein Args: function to be approximated, order, points to estimates
y <- bernstein(Fy,k, x)
plot(x, y)
At this point I get just points. It's not very clear to me... I thought Bernstein method should do some function smoothing but How?
I tried
lo <- loess(y~x)
plot(x,y)
lines(predict(lo), col='red', lwd=2)
but: 1. It doesn't work 2. It's kind of nonsense
Thank you for any help