You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let sum1 =average(multiply(ys, xs)) -average(xs) *average(ys)
128
128
let sum2 =average(multiply(xs, xs)) -pow(average(xs), 2)
129
129
let slope = sum1 / sum2
130
130
let intercept =average(ys) - slope *average(xs)
131
-
return { intercept + slope *$0 }
131
+
return { x inintercept + slope *x }
132
132
}
133
133
```
134
134
This function takes as arguments two arrays of Doubles, and returns a function which is the line of best fit. The formulas to calculate the slope and the intercept can be derived from our definition of the function J. Let's see how the output from this line fits our data:
0 commit comments