How to implement RMSE loss function #553
-
Thank you for this awesome library!! I have been playing around with PySR for some time. I was trying to create a custom loss function to apply RMSE as the loss but couldn't find how to anywhere in the documentation. is there any way to apply RSME with PySR ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Thanks! And welcome to the forums :) Anything which can’t be expressed as a sum of per-row losses you should write a custom loss function for. Here’s RMSE as an example: loss_function = """
function f(tree, dataset::Dataset{T,L}, options) where {T,L}
ypred, completed = eval_tree_array(tree, dataset.X, options)
if !completed
return L(Inf)
end
y = dataset.y
return sqrt(sum(i -> (ypred[i] - y[i])^2, eachindex(y)))
end
"""
model = PySRRegressor(loss_function=loss_function) |
Beta Was this translation helpful? Give feedback.
-
Now I really want to experiment with PySR. In the past I've used Eureqa and found it amazing. But more recently I've been using a home-grown optimizer for modeling time-series data. I discovered that a loss function built on a Dynamic Time Warping metric is very helpful to guard against over-fitting, see my blog post https://geoenergymath.com/2024/03/08/dynamic-time-warping. Now, thinking back to how Eureqa often took a while to close in on a potential solution, a DTW metric as loss function may be very useful in an exploratory mode. It wouldn't be difficult to prototype as a custom loss function with a configurable window size. See this 2024 paper as well: https://arxiv.org/pdf/2401.10359.pdf |
Beta Was this translation helpful? Give feedback.
Thanks! And welcome to the forums :)
Anything which can’t be expressed as a sum of per-row losses you should write a custom loss function for. Here’s RMSE as an example: