22 lines
737 B
Python
22 lines
737 B
Python
###################################################################################################
|
|
# This moddule is called by demo scripts to execute and embed CPython.
|
|
# Must be put in the scripts folder, or else in the python path.
|
|
###################################################################################################
|
|
import numpy as np
|
|
|
|
|
|
def linfit(x, y):
|
|
"""
|
|
Return linear fit
|
|
"""
|
|
print(1, type(x), type(y), x, y)
|
|
p = np.polyfit(x, y, 1)
|
|
f = np.poly1d(p)
|
|
x_fit = np.linspace(min(x), max(x), 100)
|
|
y_fit = f(x_fit)
|
|
yhat = f(x)
|
|
ybar = np.sum(y)/len(y)
|
|
ssreg = np.sum((yhat - ybar)**2)
|
|
sstot = np.sum((y - ybar)**2)
|
|
R2 = ssreg / sstot
|
|
return (p, x_fit, y_fit, R2) |