Skip to content

Instantly share code, notes, and snippets.

@angellicadearaujo
Created November 7, 2016 12:00
Show Gist options
  • Select an option

  • Save angellicadearaujo/c9030224a571acdb20d82006a617b8e0 to your computer and use it in GitHub Desktop.

Select an option

Save angellicadearaujo/c9030224a571acdb20d82006a617b8e0 to your computer and use it in GitHub Desktop.
Mínimos quadrados para equações lineares
def MinimoQuadrado(h,e):
n=len(h)
sh=0
se=0
shh=0
she=0
m=0
b=0
# Prepare the sum for the equatio y = x*m + b
for i in range(n):
sh += h[i]
se += e[i]
shh += h[i]*h[i]
she += h[i]*e[i]
m= (n-1)*she - sh*se
m= m*((1/float((n-1))*shh - sh*sh))
b= ((se) - (m*sh))*(1/float(n-1))
# Build y
y=[]
for i in range(n):
y.append((h[i]*m + b))
return y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment