def linear_fit_slope(ps):
 avex = ave([x for (x, y) in ps])
 avey = ave([y for (x, y) in ps])
 sxy = sum([((x - avex) * (y - avey)) for (x, y) in ps])
 sxx = sum([((x - avex) ** 2) for (x, y) in ps])
 if (sxx == 0):
  return None
 return (sxy / sxx)

def linear_fit_slope ( ps ) : avex = ave ( [ x for ( x , y ) in ps ] ) avey = ave ( [ y for ( x , y ) in ps ] ) sxy = sum ( [ ( ( x - avex ) * ( y - avey ) ) for ( x , y ) in ps ] ) sxx = sum ( [ ( ( x - avex ) ** 2 ) for ( x , y ) in ps ] ) if ( sxx == 0 ) : return None return ( sxy / sxx )
single-independent-variable linear regression -- least squares method .