Skip to content

Commit 23a3a68

Browse files
committed
Minor language fixes
1 parent ca8d0af commit 23a3a68

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

docs/src/getting_started/linear_regression.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ julia> using Flux
1313
julia> using Plots
1414
```
1515
### Generating a dataset
16-
The data usually comes from the real world, which we will be exploring in the last part of this tutorial, but we don't want to jump straight to the relatively harder part. Here we will generate the `x`s of our data points and map them to the respective `y`s using a simple function. Remember, here each `x` is equivalent to a feature, and each `y` is the corresponding label. Combining all the `x`s and `y`s would create the complete dataset.
16+
The data usually comes from the real world, which we will be exploring in the last part of this guide, but we don't want to jump straight to the relatively harder part. Here we will generate the `x`s of our data points and map them to the respective `y`s using a simple function. Remember, here each `x` is equivalent to a feature, and each `y` is the corresponding label. Combining all the `x`s and `y`s would create the complete dataset.
1717

1818
```jldoctest linear_regression_simple
1919
julia> x = hcat(collect(Float32, -3:0.1:3)...);
@@ -62,7 +62,7 @@ We can now proceed ahead and build a model for our dataset!
6262

6363
### Building a model
6464

65-
A linear regression model is mathematically defined as -
65+
A linear regression model is defined mathematically as -
6666

6767
```math
6868
model(W, b, x) = Wx + b
@@ -165,11 +165,9 @@ julia> loss(W, b, x, y), flux_loss(x, y)
165165
(22.74856f0, 22.74856f0)
166166
```
167167

168-
The losses are identical! This means that our `model` and the `flux_model` are identical on some level, and the loss functions are completely identical! The difference in models would be that `Flux`'s [`Dense`](@ref) layer supports many other arguments that can be used to customize the layer further. But, for this tutorial, let us stick to our simple custom `model`.
168+
The losses are identical! This means that our `model` and the `flux_model` are identical on some level, and the loss functions are completely identical! The difference in models would be that `Flux`'s [`Dense`](@ref) layer supports many other arguments that can be used to customize the layer further. But, for this guide, let us stick to our simple custom `model`.
169169

170-
### Training the model
171-
172-
Let's train our model using the classic Gradient Descent algorithm. According to the gradient descent algorithm, the weights and biases are iteratively updated using the following mathematical equations -
170+
Let's train our model using the classic Gradient Descent algorithm. According to the gradient descent algorithm, the weights and biases should be iteratively updated using the following mathematical equations -
173171

174172
```math
175173
\begin{aligned}
@@ -180,7 +178,7 @@ b &= b - \eta * \frac{dL}{db}
180178

181179
Here, `W` is the weight matrix, `b` is the bias vector, ``\eta`` is the learning rate, ``\frac{dL}{dW}`` is the derivative of the loss function with respect to the weight, and ``\frac{dL}{db}`` is the derivative of the loss function with respect to the bias.
182180

183-
The derivatives are usually calculated using an Automatic Differentiation tool, and `Flux` uses `Zygote.jl` for the same. Since `Zygote.jl` is an independent Julia package, it can be used outside of Flux as well! Refer to the documentation of `Zygote.jl` for more information on the same.
181+
The derivatives are calculated using an Automatic Differentiation tool, and `Flux` uses [`Zygote.jl`](https://github.com/FluxML/Zygote.jl) for the same. Since `Zygote.jl` is an independent Julia package, it can be used outside of Flux as well! Refer to the documentation of `Zygote.jl` for more information on the same.
184182

185183
Our first step would be to obtain the gradient of the loss function with respect to the weights and the biases. `Flux` re-exports `Zygote`'s `gradient` function; hence, we don't need to import `Zygote` explicitly to use the functionality.
186184

@@ -260,7 +258,7 @@ julia> W, b, loss(W, b, x, y)
260258
We can train the model even more or tweak the hyperparameters to achieve the desired result faster, but let's stop here. We trained our model for 42 epochs, and loss went down from `22.74856` to `7.6680417f`. Time for some visualization!
261259

262260
### Results
263-
The main objective of this tutorial was to fit a line to our dataset using the linear regression algorithm. The training procedure went well, and the loss went down significantly! Let's see what the fitted line looks like. Remember, `Wx + b` is nothing more than a line's equation, with `slope = W[1]` and `y-intercept = b[1]` (indexing at `1` as `W` and `b` are iterable).
261+
The main objective of this guide was to fit a line to our dataset using the linear regression algorithm. The training procedure went well, and the loss went down significantly! Let's see what the fitted line looks like. Remember, `Wx + b` is nothing more than a line's equation, with `slope = W[1]` and `y-intercept = b[1]` (indexing at `1` as `W` and `b` are iterable).
264262

265263
Plotting the line and the data points using `Plot.jl` -
266264
```jldoctest linear_regression_simple
@@ -361,7 +359,7 @@ julia> function train_model()
361359
end;
362360
```
363361

364-
Contrary to our last training procedure, let's say that this time we don't want to hardcode the number of epochs. We want the training procedure to stop when the loss converges, that is, when `change in loss < δ`. The quantity `δ` can be altered according to a user's need, but let's fix it to `10⁻³` for this tutorial.
362+
Contrary to our last training procedure, let's say that this time we don't want to hardcode the number of epochs. We want the training procedure to stop when the loss converges, that is, when `change in loss < δ`. The quantity `δ` can be altered according to a user's need, but let's fix it to `10⁻³` for this guide.
365363

366364
We can write such custom training loops effortlessly using `Flux` and plain `Julia`!
367365
```jldoctest linear_regression_complex
@@ -395,7 +393,7 @@ julia> loss(model, x_train_n, y_train)
395393
The loss went down significantly! It can be minimized further by choosing an even smaller `δ`.
396394

397395
### Testing
398-
The last step of this tutorial would be to test our model using the testing data. We will first normalise the testing data and then calculate the corresponding loss.
396+
The last step of this guide would be to test our model using the testing data. We will first normalise the testing data and then calculate the corresponding loss.
399397

400398
```jldoctest linear_regression_complex; filter = r"[+-]?([0-9]*[.])?[0-9]+"
401399
julia> x_test_n = Flux.normalise(x_test);
@@ -408,7 +406,7 @@ The loss is not as small as the loss of the training data, but it looks good! Th
408406

409407
---
410408

411-
Summarising this tutorial, we started by generating a random yet correlated dataset for our custom model. We then saw how a simple linear regression model could be built with and without `Flux`, and how they were almost identical.
409+
Summarising this guide, we started by generating a random yet correlated dataset for our custom model. We then saw how a simple linear regression model could be built with and without `Flux`, and how they were almost identical.
412410

413411
Next, we trained the model by manually writing down the Gradient Descent algorithm and optimising the loss. We also saw how `Flux` provides various wrapper functionalities and keeps the API extremely intuitive and simple for the users.
414412

@@ -507,4 +505,4 @@ print("Final loss", loss(model, x_train_n, y_train), "\n")
507505
# test
508506
x_test_n = Flux.normalise(x_test);
509507
print("Test loss", loss(model, x_test_n, y_test), "\n")
510-
```
508+
```

0 commit comments

Comments
 (0)