Optimize the parameter span for loess (or spar for smooth.spline)
0
0
Entering edit mode
wenbostar • 0
@wenbostar-7275
Last seen 7.1 years ago
Hong Kong

Hi,

Does anyone know well about the parameter optimization for loess or smooth.spline?

In function loess or smooth.spline, the parameter span (or spar for smooth.spline) is very important for the fitting. I have tried to use the following method to optimize the parameter spar for smooth.spline: 

tuneSpline = function(x,y,span.vals=seq(0.1,1,by=0.05),fold=10){

    mae <- numeric(length(span.vals))

    fun.fit <- function(x,y,span) {smooth.spline(x = x,y = ,spar = span)}

    fun.predict <- function(fit,x0) {predict(fit,x0)$y}

    

    ii = 0

    for(span in span.vals){

        ii <- ii+1

        y.cv <- crossval(x,y,fun.fit,fun.predict,span=span,ngroup = fold)$cv.fit

        fltr <- !is.nay.cv)

        save(fltr,y.cv,y,file="tmp.rda")

        mae[ii] <- mean(abs(y[fltr]-y.cv[fltr]))

        

    }

    span <- span.vals[which.min(mae)]

    return(span)

}

require(graphics)

attach(cars)

tuneSpline(speed,dist,fold = length(dist))

## return 0.1

But the optimized spar by this method is always 0.1 (the minimum value in span.vals). 

It's weird and I think the result may not be right.

Can anyone help me about this issue?

 

Best regards!

Bo

 

 

 

loess smooth.spline • 1.3k views
ADD COMMENT

Login before adding your answer.

Traffic: 699 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6