MLpp
ml::LinearRegression::Result Struct Reference

Result of linear regression. More...

#include <LinearRegression.hpp>

Inheritance diagram for ml::LinearRegression::Result:

Public Member Functions

double var_y () const
 Estimated variance of observations Y, equal to rss / dof.
 
double r2 () const
 R2 coefficient. More...
 
double adjusted_r2 () const
 Adjusted R2 coefficient. More...
 

Public Attributes

unsigned int n
 
unsigned int dof
 
double rss
 
double tss
 

Detailed Description

Result of linear regression.

Supports R2 calculated w/r to a "base model" returning average Y. R2 is defined as 1 - RSS / TSS, where RSS is the residual sum of squares for the fitted model:

\( \sum_{i=1}^N (\hat{y}_i - y_i)^2 \)

and TSS is the RSS for the "base model":

\( \mathrm{TSS} = \sum_{i=1}^N (y_i - N^{-1} \sum_{j=1}^N y_j)^2 \).

Member Function Documentation

◆ r2()

double ml::LinearRegression::Result::r2 ( ) const
inline

R2 coefficient.

1 - fraction of variance unexplained relative to a "base model" (returning average Y), estimated as population variance. Equal to 1 - rss / tss.

◆ adjusted_r2()

double ml::LinearRegression::Result::adjusted_r2 ( ) const
inline

Adjusted R2 coefficient.

1 - fraction of variance unexplained relative to a "base model" (returning average Y), estimated as sample variance. Equal to 1 - (rss / dof) / (tss / (n - 1)).

Member Data Documentation

◆ n

unsigned int ml::LinearRegression::Result::n

Number of data points.

◆ dof

unsigned int ml::LinearRegression::Result::dof

Number of residual degrees of freedom (e.g. n - 2 or n - 1 for univariate regression with or without intercept).

◆ rss

double ml::LinearRegression::Result::rss

Residual sum of squares (RSS).

◆ tss

double ml::LinearRegression::Result::tss

Total sum of squares (TSS, equal to the RSS for the "base model" always returning average Y).


The documentation for this struct was generated from the following file: