mindsdb / type_infer

Type inference for Machine Learning pipelines
GNU General Public License v3.0
17 stars 7 forks source link

Fix warning in division by log #17

Closed mrandri19 closed 2 years ago

mrandri19 commented 2 years ago

Fixes #5.

The warning was due to a divide by zero. The log was zero because N is equal to one so $\log N = \log 1 = 0$.

But, when $N=1$ the entropy $S$ also is 0 because the formula for entropy reduces to: $$S = p(x) \times \log p(x)$$ but since $p(x) = 1$, because we only have one element, then we have: $$S = 1 \times 0 = 0$$ In short, when N is 1 then S is 0 so S / N must be 0 too, which is the solution implemented here.