Skip to content

How to implement RMSE loss function #553

Answered by MilesCranmer
00houssam00 asked this question in Q&A
Discussion options

You must be logged in to vote

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)

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@00houssam00
Comment options

@gm89uk
Comment options

Answer selected by 00houssam00
Comment options

You must be logged in to vote
2 replies
@MilesCranmer
Comment options

@pukpr
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
PySR PySR-related discussion SymbolicRegression.jl SymbolicRegression.jl-related discussion
4 participants