Last change
on this file since 9 was
6,
checked in by gaclod, 12 years ago
|
add GC python scripts
|
-
Property svn:executable set to
*
|
File size:
437 bytes
|
Rev | Line | |
---|
[6] | 1 | #!/usr/bin/env python |
---|
| 2 | # -*- coding: utf-8 -*- |
---|
| 3 | import numpy |
---|
| 4 | |
---|
| 5 | # Polynomial Regression |
---|
| 6 | def reg_lin1(x, y, degree): |
---|
| 7 | results = {} |
---|
| 8 | |
---|
| 9 | m, c = numpy.polyfit(x, y, degree) |
---|
| 10 | |
---|
| 11 | # r-squared |
---|
| 12 | p = numpy.poly1d(m,c) |
---|
| 13 | # fit values, and mean |
---|
| 14 | yhat = [p(z) for z in x] |
---|
| 15 | ybar = sum(y)/len(y) |
---|
| 16 | ssreg = sum([ (yihat - ybar)**2 for yihat in yhat]) |
---|
| 17 | sstot = sum([ (yi - ybar)**2 for yi in y]) |
---|
| 18 | r = ssreg / sstot |
---|
| 19 | |
---|
| 20 | return m,c, r |
---|
Note: See
TracBrowser
for help on using the repository browser.