## code for coefficient of determination

A forum for general discussion of the Python programming language.

### code for coefficient of determination

I am trying to define a function to compute the coefficient of determination.here is what I have done so far.I appreciate any help to know what I am doing wrong

Code: Select all
`def r2( y, f ) :    from numpy import mean                            # importing required libraries    from cmath import sqrt    n = len(y)    ybar = mean(y)                                 # mean of y    sigma_y^2 = (1.0/n)*sum((y-ybar)**2)    # variance of y    m = (mean(x*y)-(mean(x)*mean(y)))/(mean(x**2)-(mean(x)**2))    b = mean(y) - m*mean(x)    f = m*x + b    sigma_f^2 = (1.0/n)*sum((f-y)**2)    R^2 = 1 - (sigma_f^2/sigma_y^2)    return R^2`
Last edited by stranac on Sat Nov 02, 2013 11:42 pm, edited 1 time in total.
Reason: Added code tags. Locked.
somayeh3333

Posts: 1
Joined: Sat Nov 02, 2013 11:15 pm

### Re: code for coefficient of determination

You should read this and then provide more information that would help us to help you.
Join the #python-forum IRC channel on irc.freenode.net for off-topic chat!

Please prefer not to PM members. The point of the forum is so that anyone can benefit. We don't want to help you over PMs/emails/Skype chats that others can't benefit from

micseydel

Posts: 2250
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

### Re: code for coefficient of determination

Code: Select all
`sigma_y^2 = ...R^2 = ...`
are not Python. Also, I don't think mean(x*y) works at all (and if it does I'd be surprised if it does what you want).

In other words: you cannot "translate" any formula to what you think it should look like in Python. You need to know at least some language before trying to write in it.
ochichinyezaboombwa

Posts: 203
Joined: Tue Jun 04, 2013 7:53 pm

Return to General Discussions

### Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests