regression coeffiecients

I’m answering to myself on the mailing list just in case it might help some in the future.

As, someone pointed out the error is in the assignment operator:

I wrote in the code:
sum1 =+ (i-mx)*(j-my)

which does not add the values but puts them.
Instead I should have wrote
sum1 += (i-mx)*(j-my)

a little difference that does a lot… :slight_smile:

here is the correct function:

def slope(x,y):
sum1 = 0
sum2 = 0
mx = mean(x)
my = mean(y)
for i,j in zip(x,y):

    sum1 += (i-mx)*(j-my)
    print sum1
    sum2 += (i-mx)**2   
slope = sum1/sum2
return slope

: :’ : We are Lower your prices,

.’ surrender your code.
`- We will add your hardware and software
distinctiveness to our own.
Resistance is futile.

        Imagine there's no countries

        It isn't hard to do
        Nothing to kill or die for
        And no religion too
        Imagine all the people
        Living life in peace

       You all must read 'The God Delusion'


when one person suffers from a delusion it is called insanity. When many people suffer from a delusion it is called religion."

Robert Pirsig, Zen and the Art of Motorcycle Maintenance