Custom loss function
Custom loss function
Loading saved threads...
Matt · External communityPost link
External question — Data Science Stack Exchange
Author: Matt
Original post: https://datascience.stackexchange.com/questions/75139
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Is it possible to apply a custom loss function in a regression model (or any other algorithm for predicting continuous variable) ? I'm working on a stock market prediction model and I need to maximize the following loss function: if [predicted] < [actual] then [predicted] else [-actual]. Would that be possible ?
Thanks
Quote
Report
Robert de Graaf · External communityPost link
External answer — Data Science Stack Exchange
Author: Robert de Graaf
Original post: https://datascience.stackexchange.com/a/75146
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
The concept of a loss function comes from decision theory. Although there are some 'classic' loss functions the point is to be subjective, in the sense of being flexible enough to represent any particular problem conctext. So in that sense, yes, loss functions can be customised.
One of the main ways this has been achieved is via Bayesian regression, as the output of Bayesian regression is a probability distribution which can then the input for a loss function. This blog post shows the mechanics in a simple way (texts for Bayesian statistics and decision are often non-accessible), and also gives some examples of somewhat 'custom' loss functions in 'Examples: Part 3'. ->
http://www.statsathome.com/2017/10/12/bayesian-decision-theory-made-ridiculously-simple/
Quote
Report
10xAI · External communityPost link
External answer — Data Science Stack Exchange
Author: 10xAI
Original post: https://datascience.stackexchange.com/a/75152
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Loss function
For most optimization algorithms, it is desirable to have a loss function that is globally continuous and differentiable.
Two very commonly used loss functions are the squared loss and absolute loss. However, the absolute loss has the disadvantage that it is not differentiable at 0. The squared loss has the disadvantage that it has the tendency to be dominated by outliers
In your case
- You must convert your need into a function with the above property.
In addition to above point, another point to check -
You current loss function will not follow the correlation i.e.
"Lesser Loss => Good prediction"
.
e.g.
y_pred = 500, 1000, 2000 and y_pred = 499, 999, 1999
.
Prediction is accurate still your loss will be very high i.e.
499, 999, 1999
Quote
Report
Post Reply
Checking account access…