Giter Club home page Giter Club logo

Comments (3)

github-actions avatar github-actions commented on May 28, 2024

Hi! thanks for your contribution!, great first issue!

from torchmetrics.

SkafteNicki avatar SkafteNicki commented on May 28, 2024

Hi @vadim0x60, thanks for opening this issue.
The two formulations are equal:

$$TSS = \sum_{i=1}^n (y_i - \bar{y})^2$$

substitute the definition of

$$\bar{y} = \frac{\sum_{i=1}^{n} y_i}{n}$$

into the expression we get

$$TSS = \sum_{i=1}^n (y_i - \frac{1}{n}\sum_{i=1}^{n} y_i)^2$$

then expand the square term

$$TSS = \sum_{i=1}^{n} \left( y_i^2 - \frac{2y_i}{n} \sum_{i=1}^{n} y_i + \frac{1}{n^2} \sum_{i=1}^{n} y_i^2 \right)$$

Next, distributing the summation across the terms:

$$TSS = \sum_{i=1}^{n} y_i^2 - \frac{2}{n}\sum_{i=1}^{n} y_i^2 + \frac{1}{n}\sum_{i=1}^{n} y_i^2$$

And finally, simplifying the expression:

$$TSS = \sum_{i=1}^{n} y_i^2 - \frac{1}{n}(\sum_{i=1}^{n} y_i)^2$$

the last term we can rewrite again by using the definition of the average (in reverse order)

$$TSS = \sum_{i=1}^{n} y_i^2 - \frac{n^2 \times \bar{y}^2}{n}$$

expand again

$$TSS = \sum_{i=1}^{n} y_i^2 - \frac{n^2 \times \bar{y} \times \bar{y}}{n}$$

split

$$TSS = \sum_{i=1}^{n} y_i^2 - \frac{n^2 \times \bar{y}}{n} \times \bar{y}$$

simplify

$$TSS = \sum_{i=1}^{n} y_i^2 - n \times \bar{y} \times \bar{y}$$

again use the definition of the average to convert into the expression we want

$$TSS = \sum_{i=1}^{n} y_i^2 - \left( \sum_{i=1}^{n} y_i \right) \bar{y}$$

Hopefully this convince you that the two expressions are equal. The reason for why we use one over the other is kind of lost on me right now, but if I remember correctly one expression is a bit more numerical stable than the other, which is why we have chosen it.

from torchmetrics.

vadim0x60 avatar vadim0x60 commented on May 28, 2024

Thanks for taking the time to lay this out!

from torchmetrics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.