Skip to content

Commit f1d25e3

Browse files
authored
Merge pull request kodecocodes#474 from helmrich/master
Fix typos and markdown formatting
2 parents d1e9fa3 + e311ee9 commit f1d25e3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Linear Regression/README.markdown

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ for n in 1...numberOfIterations {
7575

7676
The program loops through each data point (each car age and car price). For each data point it adjusts the intercept and the slope to bring them closer to the correct values. The equations used in the code to adjust the intercept and the slope are based on moving in the direction of the maximal reduction of these variables. This is a *gradient descent*.
7777

78-
We want to minimse the square of the distance between the line and the points. We define a function `J` which represents this distance - for simplicity we consider only one point here. This function `J` is proprotional to `((slope.carAge + intercept) - carPrice)) ^ 2`.
78+
We want to minimise the square of the distance between the line and the points. We define a function `J` which represents this distance - for simplicity we consider only one point here. This function `J` is proportional to `((slope.carAge + intercept) - carPrice)) ^ 2`.
7979

8080
In order to move in the direction of maximal reduction, we take the partial derivative of this function with respect to the slope, and similarly for the intercept. We multiply these derivatives by our factor alpha and then use them to adjust the values of slope and intercept on each iteration.
8181

@@ -98,7 +98,7 @@ Here is the same data shown as a graph. Each of the blue lines on the graph repr
9898

9999
After 18,000 iterations it looks as if the line is getting closer to what we would expect (just by looking) to be the correct line of best fit. Also, each additional 2,000 iterations has less and less effect on the final result - the values of the intercept and the slope are converging on the correct values.
100100

101-
##A closed form solution
101+
## A closed form solution
102102

103103
There is another way we can calculate the line of best fit, without having to do multiple iterations. We can solve the equations describing the least squares minimisation and just work out the intercept and slope directly.
104104

@@ -139,7 +139,7 @@ This function takes as arguments two arrays of Doubles, and returns a function w
139139
Using this line, we would predict a price for our 4 year old car of £6952.
140140

141141

142-
##Summary
142+
## Summary
143143
We've seen two different ways to implement a simple linear regression in Swift. An obvious question is: why bother with the iterative approach at all?
144144

145145
Well, the line we've found doesn't fit the data perfectly. For one thing, the graph includes some negative values at high car ages! Possibly we would have to pay someone to tow away a very old car... but really these negative values just show that we have not modelled the real life situation very accurately. The relationship between the car age and the car price is not linear but instead is some other function. We also know that a car's price is not just related to its age but also other factors such as the make, model and engine size of the car. We would need to use additional variables to describe these other factors.

0 commit comments

Comments
 (0)