Python Tutorial : How to build a GLM?

GLMs extend linear regression to handle non-continuous data like binary outcomes and counts by connecting the expected response to a linear predictor through a link function. Gaussian data uses identity link, binary uses logit link, and counts use log link. This framework unifies different response types under exponential family distributions.
Chapters
Now you know that linear models are not suitable to accommodate different than continuous response data and provide rather strange results. In this lesson you will learn how to overcome such problems in a quite elegant way with GLMs which provide a unified framework for modeling data originating from the exponential family of densities which include Gaussian, Binomial and Poisson, among others. There are three components of the random component which defines the response variable Y and its probability distribution. As we saw previously, there are different response data types to consider depending on your data problem. One important assumption here is that the observations y1 through yn are independent. The second component is the systematic component which defines which explanatory variables to include in the model. We can include p different explanatory variables. Note that it allows for interaction effects where one variable depends on another and vice versa, or curvilinear effects, etc. Note that the right hand side represents a linear combination of the explanatory variables. The third and final component is the LNC function which connects the random and systematic component. It is the function of the expected value of the response variable which enables linearity in the parameters. By its construction, it allows the mean of the response variable to be non linearly related to the explanatory variables. It is the LN function that generalizes the linear model. Note that the choice of the LNC function is separate from the choice of the random component. Let's review the most common data types and how they are represented in in the GLM framework. One data type we are all very familiar with is continuous and approximately normally distributed with the real line as the domain. Some of the examples are house prices, level of salary, person's height, etc. When fitting a GLM we would use Gaussian for the distribution family where the link function is the identity. The identity length function is of the simplest form where it equals mu or the mean of the response. As such, it specifies the linear regression model where Y is assumed continuous and for which we can assume a normal distribution for the response. Therefore, the linear regression is a special case of the glm. Another data type we encounter quite often is binary data that is data with two possible classes, which we usually denote as 01, where 1 is true and 0 is false. To fit a GLM you should use binomial distribution where the default link function is the logit. Models of this form are called logistic regression which we will cover in chapters two and four. Count data are positive and some examples include the number of hurricanes, number of bike crossings on a bridge etc. To fit a GLM, you should use a Poisson for the distribution, where the default link function is logarithm. Models of this form are called Poisson regression, which we will cover in detail in chapter three. For reference, here's the list of the main link functions and their usage in model fitting. Let's summarize the concepts introduced in this video. As you learned in this lecture, the GLMs unify many different types of the response variable, where the distributions belong to the family of exponential densities. The link function transforms the expected value of Y and not y itself, and it enables linear combinations, which further provide benefits that many techniques from linear models apply to GLMs as well. We will further see the details of this in later lessons. Now, time for some.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







