本文实例讲述了Python线性拟合实现函数与用法。分享给大家供大家参考,具体如下:
1. 参考别人写的:
#-*- coding:utf-8 -*-
import math
import matplotlib.pyplot as plt
def linefit(x , y):
N = float(len(x))
sx,sy,sxx,syy,sxy=0,0,0,0,0
for i in range(0,int(N)):
sx += x[i]
sy += y[i]
sxx += x[i]*x[i]
syy += y[i]*y[i]
sxy +=
1