2

I have 2 sets of data - one is an average position and the other a score so for every position, i have the predicted score of an item -

double[] positions = {0.1,0.2,0.3,0.45,0.46,...};
double[] scores = {1,1.2,1.5,2.2,3.4,...};

I need to create a function that predicts the score for average position, so given a new item with position 1.7. I under stand the function should be something like y=a*x + b but how do i get to it?

Any help will be appreciated!

Chen
  • 161
  • 1
  • 10

1 Answers1

3

Yes, you have to build a linear function

  y = a * x + b

in order to do this you have to compute the sums (x is predictor's values and y - is corresponding results):

 sx  - sum of x's
 sxx - sum of x * x
 sy  - sum of y's
 sxy - sum of x * y

So

 a = (N * sxy - sx * sy) / (N * sxx - sx * sx);
 b = (sy - a * sx) / N;
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
  • Thanks Dmitry! If i want a logarithmic regression i simply add log to the equation? so its y = a * log(x) + b – Chen Sep 07 '15 at 08:22
  • @Chen: if you want to *fit* `y` into `y = a * log(x) + b` then, yes, just take *logarithms* (just use `log(x)` instead of `x`). – Dmitry Bychenko Sep 07 '15 at 08:25