4
$\begingroup$

I'm wondering how can machine learning approach solves a problem which has some restrictions.

Let's say we have a demand prediction problem (regression) and the demand must be less or equal than 50. Therefore, the outputs of the machine must be less or equal than 50.

In this situation, how can I keep the constraint (demand <= 50) in machine learning algorithm? The question also includes how to keep integer, equality and inequality constraints.

I think I can use a lagrangian multiplier, but I'm not sure. Can I include the constraints in the loss function of the machine?

$\endgroup$
6
  • $\begingroup$ I'd sure go for a personalized loss function. however, there is more to say if we knew better your problem and your data. $\endgroup$
    – carlo
    Commented Nov 8, 2019 at 9:28
  • $\begingroup$ @carlo There are no data. I asked it just curious. Can you explain how can I make my own loss function to me more details? $\endgroup$ Commented Nov 8, 2019 at 9:31
  • $\begingroup$ @carlo For examples, demand must be positive numbers because it can never be negative. However, a linear regression line can result in negative demand. So I want to add this positive condition on my machine. $\endgroup$ Commented Nov 8, 2019 at 9:35
  • $\begingroup$ if demand $\in [0, 50]$ then you can normalize it to $[0,1]$ and use logistic regression and use returned $probs$ (or any sigmoid-like head for NN)..., also machine learning require data to learn (upfront or by reinforced learning), because you have to find correct values of coefficients in your model $\endgroup$
    – quester
    Commented Nov 8, 2019 at 21:46
  • $\begingroup$ @quester So changing a regression problem to a classification problem is the answer? $\endgroup$ Commented Nov 11, 2019 at 8:50

1 Answer 1

1
$\begingroup$

If your model is $f$ you can always transform the outputs, so that they meet the constraint. For your example you could use something like

$$ g(x) = 50-\exp(-f(x)) $$

and instead of optimizing the loss function between $y$ and $f(x)$, minimize loss between $y$ and $g(x)$. You would be seeking for such parameters that make the transformed predictions fit best to the data.

$\endgroup$
11
  • $\begingroup$ Thanks! So modifying both output function and loss function is your answer, right? One more question. Why did you use $-exp(-f(x))$? $\endgroup$ Commented Nov 11, 2019 at 8:53
  • $\begingroup$ @YooInhyeok it maps real line to increasing, positive values. You can choose also other functions, this is just example. $\endgroup$
    – Tim
    Commented Nov 11, 2019 at 9:10
  • $\begingroup$ I'm sorry but I don't understand what you mean. Can you give me more detail explanations for the function $g(x)$? $\endgroup$ Commented Nov 11, 2019 at 10:01
  • $\begingroup$ @YooInhyeok what exactly is unclear for you? $\endgroup$
    – Tim
    Commented Nov 11, 2019 at 11:21
  • $\begingroup$ I think the function $g(x)$ is the output of the model in the case. I want to know how you derive the function $g(x)$. In other words, why is $g(x)$ my constraint? $\endgroup$ Commented Nov 12, 2019 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.