Skip to content

Commit

Permalink
[simple_linear_regression] Update translations (#88)
Browse files Browse the repository at this point in the history
* [simple_linear_regression] Translation

* Update translations
  • Loading branch information
SylviaZhaooo authored Oct 8, 2024
1 parent e9e0cd6 commit a547a00
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lectures/simple_linear_regression.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ $$

我们希望通过参数 $\alpha$ 和 $\beta$ 来最小化这个成本函数。

## 错误相对于 $\alpha$ 和 $\beta$ 的变化
## 残差相对于 $\alpha$ 和 $\beta$ 的变化

首先让我们看看总误差相对于 $\beta$ 的变化(保持截距 $\alpha$ 不变)

Expand All @@ -204,24 +204,24 @@ $$
α_optimal = -14.72
```

我们可以计算一个范围内的 $\beta$ 值的错误
我们可以计算一个范围内的 $\beta$ 值的残差

```{code-cell} ipython3
errors = {}
for β in np.arange(20,100,0.5):
errors[β] = abs((α_optimal + β * df['X']) - df['Y']).sum()
```

绘制错误图
绘制残差图

```{code-cell} ipython3
---
mystnb:
figure:
caption: "绘制错误图"
caption: "绘制残差图"
name: plt-errors
---
ax = pd.Series(errors).plot(xlabel='β', ylabel='error')
ax = pd.Series(errors).plot(xlabel='β', ylabel='残差')
plt.axvline(β_optimal, color='r');
```

Expand All @@ -233,16 +233,16 @@ for α in np.arange(-500,500,5):
errors[α] = abs((α + β_optimal * df['X']) - df['Y']).sum()
```

绘制错误图
绘制残差图

```{code-cell} ipython3
---
mystnb:
figure:
caption: "绘制错误图 (2)"
caption: "绘制残差图 (2)"
name: plt-errors-2
---
ax = pd.Series(errors).plot(xlabel='α', ylabel='error')
ax = pd.Series(errors).plot(xlabel='α', ylabel='残差')
plt.axvline(α_optimal, color='r');
```

Expand Down

0 comments on commit a547a00

Please sign in to comment.