PySR icon indicating copy to clipboard operation
PySR copied to clipboard

Сorrelation as a loss function

Open zachanton opened this issue 3 years ago • 1 comments
trafficstars

Is there any way to use Pearson or Spearman correlation as a loss function?

zachanton avatar Aug 30 '22 06:08 zachanton

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

MilesCranmer avatar Aug 30 '22 17:08 MilesCranmer

#276 fixes this and allows you to do this.

MilesCranmer avatar Mar 25 '23 02:03 MilesCranmer