Difference between revisions of "Linear Methods"

From Bitnami MediaWiki
Jump to navigation Jump to search
Line 24: Line 24:
 
::<math>SS_\text{tot} = SS_\text{reg} + SS_\text{res}</math>
 
::<math>SS_\text{tot} = SS_\text{reg} + SS_\text{res}</math>
 
* <math>F = \dfrac{\left(\dfrac{\text{RSS}_1-\text{RSS}_2}{p_2-p_1}\right)}{\left(\dfrac{\text{RSS}_2}{n-p_2}\right)} </math>
 
* <math>F = \dfrac{\left(\dfrac{\text{RSS}_1-\text{RSS}_2}{p_2-p_1}\right)}{\left(\dfrac{\text{RSS}_2}{n-p_2}\right)} </math>
−
 
+
* <math>\text{Adj} R^2 = 1 - (1-R^2)\dfrac{n-1}{n-p-1} </math> with p independent variables and n observations.
  
 
Confusingly, the literature also uses ESS (explained sum of squares) to mean <math>SS_\text{reg}</math> and RSS (Residual sum of squares) to mean <math>SS_\text{res}</math>. In addition, for the formulae above the acronyms SST (total), SSE (errors/residuals) and SSR (regression) are also in use.
 
Confusingly, the literature also uses ESS (explained sum of squares) to mean <math>SS_\text{reg}</math> and RSS (Residual sum of squares) to mean <math>SS_\text{res}</math>. In addition, for the formulae above the acronyms SST (total), SSE (errors/residuals) and SSR (regression) are also in use.

Revision as of 00:33, 7 February 2021

Metrics

Primary purpose is to minimize some error metric:

[math]\displaystyle{ \displaystyle \textrm{RMSE(}\textbf{X}\textit{,h}) = \sqrt{\dfrac{1}{m} \sum^m_{i=1}(h(\textbf{x}^{(i)} - y^{(i)})^2} }[/math]

[math]\displaystyle{ \displaystyle \textrm{MAE(}\textbf{X}\textit{,h}) = \dfrac{1}{m}\sum^m_{i=1} | h(\textbf{x}^{(i)} - y^{(i)} }[/math]

RMSE gives the Euclidean norm, [math]\displaystyle{ \ell_2 }[/math]. MAE gives the Manhattan norm, [math]\displaystyle{ \ell_1 }[/math]. A higher norm index overweights large values relative to small ones. This makes RMSE more sensitive to outliers than MAE. In general,

[math]\displaystyle{ \|\textbf{v}\|_k = (|v_0|^k + |v_1|^k + \dots + |v_n|^k)^{1/k} }[/math]

Linear Regression

[math]\displaystyle{ \hat{y} = \theta_0 + \theta_1x_1 + \theta_2x_2 + \cdots + \theta_nx_n = h_\theta(\textbf{x}) = \boldsymbol{\theta} \cdot \textbf{x} }[/math]
  • [math]\displaystyle{ \mathbf{\theta} }[/math] is the parameter vector. The bias term is [math]\displaystyle{ \theta_0 }[/math] and the feature weights are the [math]\displaystyle{ \theta_1 \dots \theta_n }[/math]
  • [math]\displaystyle{ \textbf{x} }[/math] is the feature vector of [math]\displaystyle{ x_0 \dots x_n }[/math] where [math]\displaystyle{ x_0 = 1 }[/math]
  • [math]\displaystyle{ \boldsymbol{\theta}\cdot \mathbf{x} }[/math] is the dot product of feature weights and features
  • Solve using the normal equation:
[math]\displaystyle{ \boldsymbol{\hat{\theta}} = (\mathbf{X}^T\mathbf{X})^{-1} \,\mathbf{X}^T\,\mathbf{y} }[/math]
Performance Metrics
  • [math]\displaystyle{ R^2 = 1 - \dfrac{SS_\text{res}}{SS_\text{tot}} }[/math], where
[math]\displaystyle{ SS_\text{tot} = \displaystyle\sum_i (y_i-\bar{y})^2 }[/math],
[math]\displaystyle{ SS_\text{res} = \displaystyle\sum_i e_i^2 = \sum(y_i - \hat{y}_i)^2 }[/math], and
[math]\displaystyle{ SS_\text{reg} = \displaystyle\sum_i (\hat{y}_i-\bar{y})^2 }[/math]
[math]\displaystyle{ SS_\text{tot} = SS_\text{reg} + SS_\text{res} }[/math]
  • [math]\displaystyle{ F = \dfrac{\left(\dfrac{\text{RSS}_1-\text{RSS}_2}{p_2-p_1}\right)}{\left(\dfrac{\text{RSS}_2}{n-p_2}\right)} }[/math]
  • [math]\displaystyle{ \text{Adj} R^2 = 1 - (1-R^2)\dfrac{n-1}{n-p-1} }[/math] with p independent variables and n observations.

Confusingly, the literature also uses ESS (explained sum of squares) to mean [math]\displaystyle{ SS_\text{reg} }[/math] and RSS (Residual sum of squares) to mean [math]\displaystyle{ SS_\text{res} }[/math]. In addition, for the formulae above the acronyms SST (total), SSE (errors/residuals) and SSR (regression) are also in use.

name 1 name 2 formula meaning
TSS
Total sum of squares
SST
Sum of squares, total
[math]\displaystyle{ \displaystyle\sum (y_i-\bar{y})^2 }[/math] observed vs. mean
ESS
Explained sum of squares
SSR
Sum of squares, regression
[math]\displaystyle{ \displaystyle\sum (\hat{y}_i-\bar{y}_i)^2 }[/math] predicted vs. mean
RSS
Residual sum of squares
SSE
Sum of squared errors
[math]\displaystyle{ \displaystyle\sum (y_i-\hat{y})^2 }[/math] observed vs. predicted

Logistic Regression

Logistic regression, unlike linear regression, is more of a classifier. It generates probabilities rather than scalar estimates. Some terminology:

  • The logit function or log-odds is the log of the odds p/(1-p):
[math]\displaystyle{ \log \left(\dfrac{p}{1-p} \right) = \log(p) - \log(1-p) }[/math]
  • The sigmoid function is
[math]\displaystyle{ \sigma(x) = \dfrac{1}{1+e^{-x}} }[/math]
  • The logistic function:
[math]\displaystyle{ P(Y=1|X) = \dfrac{\exp({\beta_0+\beta_1x})}{\exp({\beta_0+\beta_1x}+1)} }[/math]
  • Unlike linear regression which uses OLS to determine coefficients, logistic regression uses the maximum likelihood method:
[math]\displaystyle{ \ell(\beta_0, \beta_1) = \displaystyle \prod_{i:y_i=1} p(x_i) \prod_{i':y'_i=0} (1-p(x'_i)) }[/math]
  • Measures of goodness of fit include AIC, null and residual deviance, and the confusion matrix
AIC (Akaike Information Criterion): [math]\displaystyle{ \textrm{AIC} = 2k - 2\ln(\hat{L}) }[/math]
Null and Residual Deviance:
Confusion Matrix. Here is some Python code that explains it compactly:
def deconfuse(tn, fp, fn, tp):
    print('Precision:', tp/(tp+fp))
    print('Recall (TPR):', tp/(tp+fn))
    print('Specificity (TNR):', tn/(tn+fp))
    print('Accuracy:', (tp+tn)/(tp+tn+fp+fn))
    print('F1-score:', tp/(tp+(fn+fp)/2))