Generalized Linear Models
1. The Exponential Family
We shall refer to probability distributions of the following form to be members of the exponential family:
where the \(p(y)\) is being parameterized by the variable natural (or canonical) parameter \(\eta\); \(T(y)\) is the sufficient statistic (for the distribution) and; \(a(\eta)\) is the log partition function. The term \(exp{(-a(\eta))}\) essentially plays the role of a normalization constant, ensuring that \(p(y;\eta)\) remains within the bounds of \(0\) and \(1\).
A fixed choice of \(b(y)\), \(T(y)\) and \(a(\eta)\) defines a family (or set) of distributions. Varying \(\eta\) then gives different distributions within that family of distributions.
We shall now show that the Bernoulli distribution \(y;\phi \sim Bernoulli(\phi)\) and the Gaussian distribution \(y; \mu,\sigma \sim \mathcal{N} (\mu, \sigma^2)\) are members of the exponential family.
(i) Bernoulli Distribution
The random variable of a Bernoulli distribution can take on only two values \(0\) or \(1\). Therefore, \(y \sim Bernoulli(\phi)\) means:
Or, compactly:
As \(z = exp(log(z))\), we have:
Comparing the above equation with the general equation of the exponential family yields:
Note that:
(ii) Gaussian Distribution
For linear regression models we showed that \(y \vert x; \theta \sim \mathcal{N}(\mu,\sigma^2)\) under a certain set of assumptions. We also showed that the both the resulting hypothesis \(h_\theta(x)\) and \(\theta\) itself were independent of the value of \(\sigma^2\). Therefore, to simplify our discussion below we shall set \(\sigma^2 = 1\):
Therefore:
2. Generalized Linear Models (GLMs)
In order to define generalized linear models we shall make the following assumptions:
- \(y \vert x; \theta \sim Exponential\ Family(\eta)\) where \(\eta\) may depend on \(\theta\) and \(x\).
- \(h_\theta(x) = \mathbb{E}[T(y) \vert x; \theta]\), i.e., we need to predict the expected value of the sufficient statistic \(T(y)\) given \(x\) and the parameter \(\theta\). This is a reasonable assumption because \(T(y)\), being the sufficient statistic, contains all the ‘information’ regarding this particular distribution. Note that, by definition, a statistic is sufficient with respect to a statistical model and its unknown parameter if no other statistic derived from the same sample provides additional information as to the value of that parameter.
- \(\eta = \theta^Tx\) or \(\eta_i = \theta_i^Tx\) if \(\eta\) is a vector (this may also be thought of a design choice rather than an assumption).
We shall now first derive the linear regression and logistic regression models from the Gaussian and Bernoulli distributions respectively using this definition of GLMs and then introduce the softmax regression model that is based on the multinomial distribution and is a generalization of logistic regression.
In the following discussion, we shall refer to the function \(g(\eta) = \mathbb{E}[T(y);\eta]\) as the canonical response function and its inverse \(g^{-1}\) as the canonical link function.
(i) Linear Regression
Let \(y \vert x \sim \mathcal{N}(\mu,\sigma^2)\). We have from earlier that (for the Gaussian distribution) \(T(y)=y\). Therefore, \(\mathbb{E}[T(y) \vert x; \theta] = \mathbb{E}[y \vert x; \theta] = \mu\). We also know that \(\mu = \eta\). As per the third assumption, \(\eta = \theta^Tx\). As a result of the second assumption, we have:
which is the linear regression model we presented earlier.
Note that the canonical response function \(g(\eta)\) is just the identity function.
(ii) Logistic Regression
Let \(y \vert x \sim Bernoulli(\phi)\). We have from earlier that (for the Bernoulli distribution) \(T(y)=y\). Therefore:
We also know that \(\phi=\frac{1}{1+exp(-\eta)}\). Therefore:
which is the logistic regression model we presented earlier.
Note that the canonical response function \(g(\eta) = \frac{1}{1+exp(-\eta)}\).
(iii) Softmax Regression
Let \(y \in \{1,...,k\}\) for a given \(x\). Let there also be a set \(\{\phi_1, ..., \phi_{k-1}\}\) such that the probability that \(y\) takes on value \(i\), where \(i \in \{1,...,k-1\}\) is given by \(\phi_i\). The probability that \(y=k\) is then given by \(\phi_k = 1-\sum_{i=0}^{k-l}\phi_i\). Let us define an indicator function \(1\{\mathbb{o}\}\) that is \(1\) when its argument is \(True\) and \(0\) when it is \(False\). Finally, let us define \(T(y)\) to be a vector of length \(k-1\), i.e. \(T(y) \in \mathbb{R}^{k-1}\) such that \(T(y)_i = 1\{y=i\}\). Also, for notational convenience define \(T(y)_k=1\{y=k\}\). Therefore:
This is the multinomial distribution - a generalization of the Bernoulli distribution to \(k\) classes. We shall now show that the multinomial distribution is a member of the Exponential Family.
Let:
For notational convenience we shall also define \(\eta_k = log\left(\frac{\phi_k}{\phi_k}\right)=0\).
Therefore:
This shows that the multinomial distribution does indeed belong to the Exponential Family. Note:
The canonical link function is thus given by:
Note that the canonical response function \(g(\eta)\) expresses the expectation \(\mathbb{E}[T(y); \eta]\) in terms of \(\eta\) whereas the canonical link function \(g^{-1}\) expresses \(\eta\) in terms of the expectation \(\mathbb{E}[T(y); \eta]\). Note that the above equation satisfies this condition because \(\mathbb{E}[T(y) _i; \eta_i] = \phi_i\).
Therefore:
Substituting the value of \(\phi_k\) in the second equation above gives:
From our third assumption we have \(\eta_i=\theta^T_ix\). Therefore:
This is the softmax regression model - a generalization of the logistic regression model to \(k\) classes.
As per the second assumption, our hypothesis \(h_\theta(x) = \mathbb{E}[T(y) \vert x]\). Therefore:
Suppose that we are given a training set \(\{(x^{(i)}, y^{(i)}\}\) where \(i \in \{1,...,m\}\) and our goal is to find the parameter \(\theta\) that maps the \(x^{(i)}\)’s to the \(y^{(i)}\)’s. Let us define a likelihood function as follows:
We can now use gradient descent or the Netwon-Raphson method to find the value of \(\theta\) that maximizes \(\mathcal{l}(\theta) = log(L(\theta))\).