# How to weight examples to minimize some feature/output?

I'm working on a Regression problem consisting on predict some continuous variable $$Y$$, as usual. The thing here is that there are two kinds of data examples: some that have a value of $$Y$$ a little larger than they should, and some that have it exactly right, so in the optimization task of the algorithm (min. the loss function) the magnitude of $$Y$$ should be considered, as not only is important to get as close to $$Y$$ as possible, but as low $$Y$$ is, the better.

For example, in a regular regression problem, in the case below the grey line would be our best possible model because the error is minimum for it, but for this case not only the error is important, the magnitude of the output matters too, so imagine that A point has a quite lower $$Y$$ than B, it will provoke the model to shift towards it, as seen in the red line, because it minimizes the error and the magnitude.

My question here is how this could be achieved? Is there any technique to weight the examples before learn to predict them, so receive more importance those with lower $$Y$$? Is it possible to add this magnitude to the loss function in order to try to minimize it too?

• This seems to say that the error distribution is asymmetrical, with a longer tail to higher values. If thst is so, maybe try with something like a skew-normal distribution for the errors, and then use maximum likelihood? Aug 26, 2022 at 18:37

Pretty cool question!

first I have to say that adding your pre-existing knowledge will change the results. So proceed with caution.

I would formulate the problem in one of the following ways:

Method 1 :

Perform regression as usual. Then calculate $\lambda(y_{pred}-y)$ and add it to each sample weight. $\lambda$ now becomes a hyperparameter you need to also find. now perform the regression with the updated weights.

as you've lowered the weight of the samples above the predicted curve and increased the weight of the samples below the predicted curve, the curve will be pulled towards the points below the curve.

Method 2 :

This requires defining your own optimization goal. regular OLS minimizes the objective $\left&space;(&space;&space;y_i&space;-&space;(Ax_i&space;+&space;b)\right&space;)^2$

add the term $\lambda(y_{pred}-y)$ to the standard objective and minimize it using your favorite optimization method. this gives you a new optimization objective:

$\left&space;(&space;&space;y_i&space;-&space;(Ax_i&space;+&space;b)\right&space;)^2&space;+&space;\lambda(y_i-(Ax_i&space;+&space;b))$

This again lowers the loss of points above the predicted curve and increases the loss of points below the curve, moving the optimal solution closer to the lower points.

but you have to be careful as selecting a large value of $\lambda$ will move the curve below all the points.