Reputation: 191
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!
Upvotes: 2
Views: 301
Reputation: 186813
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;
Upvotes: 3