- Deep Learning By Example
- Ahmed Menshawy
- 335字
- 2021-06-24 18:52:41
Learning model coefficients
In order to estimate the coefficients of our model, we need to fit the data with a regression line that gives a similar answer to the actual sales. To get a regression line that best fits the data, we will use a criterion called least squares. So, we need to find a line that minimizes the difference between the predicted value and the observed (actual) one. In other words, we need to find a regression line that minimizes the sum of squared residuals (SSresiduals). Figure 2 illustrates this:

The following are the elements that exist in Figure 2:
- Black dots represent the actual or observed values of x (TV ad) and y (sales)
- The blue line represents the least squares line (regression line)
- The red line represents the residuals, which are the differences between the predicted and the observed (actual) values
So, this is how our coefficients relate to the least squares line (regression line):
- beta0 is the intercept, which is the value of y when x =0
- beta1 is the slope, which represents the change in y divided by the change in x
Figure 3 presents a graphical explanation of this:

Now, let's go ahead and start to learn these coefficients using Statsmodels:
# To use the formula notation below, we need to import the module like the following
import statsmodels.formula.api as smf
# create a fitted model in one line of code(which will represent the least squares line)
lm = smf.ols(formula='sales ~ TV', data=advertising_data).fit()
# show the trained model coefficients
lm.params
Output:
Intercept 7.032594
TV 0.047537
dtype: float64
As we mentioned, one of the advantages of linear regression models is that they are easy to interpret, so let's go ahead and interpret the model.
- 程序設(shè)計缺陷分析與實踐
- 圖解PLC控制系統(tǒng)梯形圖和語句表
- Dreamweaver CS3網(wǎng)頁設(shè)計與網(wǎng)站建設(shè)詳解
- 控制系統(tǒng)計算機仿真
- 網(wǎng)絡(luò)化分布式系統(tǒng)預(yù)測控制
- Visual Basic.NET程序設(shè)計
- 大數(shù)據(jù)驅(qū)動的機械裝備智能運維理論及應(yīng)用
- Practical Big Data Analytics
- 分析力!專業(yè)Excel的制作與分析實用法則
- DevOps Bootcamp
- Citrix? XenDesktop? 7 Cookbook
- Learning Linux Shell Scripting
- Hands-On Dashboard Development with QlikView
- 人工智能:智能人機交互
- 網(wǎng)絡(luò)安全原理與應(yīng)用