Monday, 20 December 2010

algorithm to Implement the linear regression algorithm

Algorithm:

Step 1. Read n

Step 2. Sumx=0

Step 3. Sumxsq=0

Step 4. Sumy=0

Step 5. Sumxy=0

Step 6. fori=1 to n do

Step 7. Read x,y

Step 8. Sumx=sumx+x

Step 9.Sumxsq=Sumxsq+x2

Step 10.Sumy=Sumy+y

Step 11.Sumxy=sumxy+x x y end for

Step 12. denom=n x sumxsq – sumx x sumx

Step 13. a0=(sumy x sumxsq – sumx x sumxy) / denom

Step 14. a1=(n x sumxy-sumx x sumy)/ denonm

Step 15. Write a1,a0

Step 16. STOP






No comments:

Post a Comment