def _lowess_robustify_fit(x_copy, y_copy, fitted, weights, k, n):
 nn_indices = [0, k]
 X = np.ones((k, 2))
 residual_weights = np.copy(y_copy)
 residual_weights.shape = (n,)
 residual_weights -= fitted
 residual_weights = np.absolute(residual_weights)
 s = np.median(residual_weights)
 residual_weights /= (6 * s)
 too_big = (residual_weights >= 1)
 _lowess_bisquare(residual_weights)
 residual_weights[too_big] = 0
 for i in range(n):
  total_weights = (weights[i, :] * np.sqrt(residual_weights[nn_indices[0]:nn_indices[1]]))
  X[:, 1] = x_copy[nn_indices[0]:nn_indices[1]]
  y_i = (total_weights * y_copy[nn_indices[0]:nn_indices[1]])
  total_weights.shape = (k, 1)
  beta = lstsq((total_weights * X), y_i)[0]
  fitted[i] = (beta[0] + (beta[1] * x_copy[i]))
  _lowess_update_nn(x_copy, nn_indices, (i + 1))

def _lowess_robustify_fit ( x_copy , y_copy , fitted , weights , k , n ) : nn_indices = [ 0 , k ] X = np . ones ( ( k , 2 ) ) residual_weights = np . copy ( y_copy ) residual_weights . shape = ( n , ) residual_weights -= fitted residual_weights = np . absolute ( residual_weights ) s = np . median ( residual_weights ) residual_weights /= ( 6 * s ) too_big = ( residual_weights >= 1 ) _lowess_bisquare ( residual_weights ) residual_weights [ too_big ] = 0 for i in range ( n ) : total_weights = ( weights [ i , : ] * np . sqrt ( residual_weights [ nn_indices [ 0 ] : nn_indices [ 1 ] ] ) ) X [ : , 1 ] = x_copy [ nn_indices [ 0 ] : nn_indices [ 1 ] ] y_i = ( total_weights * y_copy [ nn_indices [ 0 ] : nn_indices [ 1 ] ] ) total_weights . shape = ( k , 1 ) beta = lstsq ( ( total_weights * X ) , y_i ) [ 0 ] fitted [ i ] = ( beta [ 0 ] + ( beta [ 1 ] * x_copy [ i ] ) ) _lowess_update_nn ( x_copy , nn_indices , ( i + 1 ) )
additional weighted local linear regressions .