Skip to content

Commit d08d69a

Browse files
committed
Show data
1 parent 1509b88 commit d08d69a

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

docs/src/getting_started/linear_regression.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,24 @@ Importing the required `Julia` packages -
1010
```jldoctest linear_regression_simple
1111
julia> using Flux, Plots
1212
```
13+
1314
### Generating a dataset
1415
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.
1516

1617
```jldoctest linear_regression_simple
17-
julia> x = hcat(collect(Float32, -3:0.1:3)...);
18-
19-
julia> x |> size
20-
(1, 61)
21-
22-
julia> typeof(x)
23-
Matrix{Float32} (alias for Array{Float32, 2})
18+
julia> x = hcat(collect(Float32, -3:0.1:3)...)
19+
1×61 Matrix{Float32}:
20+
-3.0 -2.9 -2.8 -2.7 -2.6 -2.5 … 2.4 2.5 2.6 2.7 2.8 2.9 3.0
2421
```
2522

2623
The `hcat` call generates a `Matrix` with numbers ranging from `-3.0` to `3.0` with a gap of `0.1` between them. Each column of this matrix holds a single `x`, a total of 61 `x`s. The next step would be to generate the corresponding labels or the `y`s.
2724

2825
```jldoctest linear_regression_simple
2926
julia> f(x) = @. 3x + 2;
3027
31-
julia> y = f(x);
32-
33-
julia> y |> size
34-
(1, 61)
35-
36-
julia> typeof(y)
37-
Matrix{Float32} (alias for Array{Float32, 2})
28+
julia> y = f(x)
29+
1×61 Matrix{Float32}:
30+
-7.0 -6.7 -6.4 -6.1 -5.8 -5.5 … 9.5 9.8 10.1 10.4 10.7 11.0
3831
```
3932

4033
The function `f` maps each `x` to a `y`, and as `x` is a `Matrix`, the expression broadcasts the scalar values using `@.` macro. Our data points are ready, but they are too perfect. In a real-world scenario, we will not have an `f` function to generate `y` values, but instead, the labels would be manually added.

0 commit comments

Comments
 (0)