Skip to content

Commit 1c09008

Browse files
committed
Update README.md
1 parent f7ec3c4 commit 1c09008

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
@@ -104,8 +104,8 @@ There is another way we can calculate the line of best fit, without having to do
104104
First we need some helper functions. This one calculates the average (the mean) of an array of Doubles:
105105

106106
```swift
107-
func average(input: [Double]) -> Double {
108-
return input.reduce(0, combine: +) / Double(input.count)
107+
func average(_ input: [Double]) -> Double {
108+
return input.reduce(0, +) / Double(input.count)
109109
}
110110
```
111111
We are using the ```reduce``` Swift function to sum up all the elements of the array, and then divide that by the number of elements. This gives us the mean value.
@@ -123,7 +123,7 @@ We are using the ```map``` function to multiply each element.
123123
Finally, the function which fits the line to the data:
124124

125125
```swift
126-
func linearRegression(xs: [Double], _ ys: [Double]) -> (Double -> Double) {
126+
func linearRegression(_ xs: [Double], _ ys: [Double]) -> (Double -> Double) {
127127
let sum1 = average(multiply(xs, ys)) - average(xs) * average(ys)
128128
let sum2 = average(multiply(xs, xs)) - pow(average(xs), 2)
129129
let slope = sum1 / sum2

0 commit comments

Comments
 (0)