PySR
PySR copied to clipboard
Сorrelation as a loss function
Is there any way to use Pearson or Spearman correlation as a loss function?
Not by default - these are the available losses: https://astroautomata.com/SymbolicRegression.jl/dev/losses/. As well as any loss function that can be written as a sum over per-element losses, like loss="myloss(x, y) = abs(x - y)" - so long as it is non-negative.
To add a more complex loss like a correlation-based loss, you can tweak this function (in Julia - but it's quite similar to Python): https://github.com/MilesCranmer/SymbolicRegression.jl/blob/7b4fecf9e136eb7b3acf29d0669e00e772efff56/src/LossFunctions.jl#L45-L49 to compare prediction with dataset.y. Both of these are Julia vectors.
Then, give your path to the local copy of SymbolicRegression.jl to the julia_project parameter in PySRRegressor.
Cheers, Miles
#276 fixes this and allows you to do this.