python 3.x - Iterating through values to find average equation of a line (Python3) -
i trying find equation of line within df
here fake data set explain:
clicks sales 5 10 5 11 10 16 10 20 10 18 15 28 15 26 ... ... 100 200
what trying do:
calculate equation of line between able input number of clicks , have output of sales @ predicted level. the thing trying wrap brain around have many different line functions (e.g. there multiple sales each amount of clicks). how can iterate through df calculate 1 aggregate line function?
here's have accept 1 input @ time, create average or aggregate...
def slope(self, target): return slope(target.x - self.x, target.y - self.y) def y_int(self, target): # <= here's magic return self.y - self.slope(target)*self.x def line_function(self, target): slope = self.slope(target) y_int = self.y_int(target) def fn(x): return slope*x + y_int return fn = point(5, 10) # stuck here since - input!? b = point(10, 16) # stuck here since - input!? line = a.line_function(b) print(line(x=10))
use scipy
function scipy.stats.linregress
fit data. maybe check https://en.wikipedia.org/wiki/linear_regression better understand linear regression.
Comments
Post a Comment