def _lowess_initial_fit(x_copy, y_copy, k, n):
 weights = np.zeros((n, k), dtype=x_copy.dtype)
 nn_indices = [0, k]
 X = np.ones((k, 2))
 fitted = np.zeros(n)
 for i in range(n):
  left_width = (x_copy[i] - x_copy[nn_indices[0]])
  right_width = (x_copy[(nn_indices[1] - 1)] - x_copy[i])
  width = max(left_width, right_width)
  _lowess_wt_standardize(weights[i, :], x_copy[nn_indices[0]:nn_indices[1]], x_copy[i], width)
  _lowess_tricube(weights[i, :])
  weights[i, :] = np.sqrt(weights[i, :])
  X[:, 1] = x_copy[nn_indices[0]:nn_indices[1]]
  y_i = (weights[i, :] * y_copy[nn_indices[0]:nn_indices[1]])
  beta = lstsq((weights[i, :].reshape(k, 1) * X), y_i)[0]
  fitted[i] = (beta[0] + (beta[1] * x_copy[i]))
  _lowess_update_nn(x_copy, nn_indices, (i + 1))
 return (fitted, weights)

def _lowess_initial_fit ( x_copy , y_copy , k , n ) : weights = np . zeros ( ( n , k ) , dtype = x_copy . dtype ) nn_indices = [ 0 , k ] X = np . ones ( ( k , 2 ) ) fitted = np . zeros ( n ) for i in range ( n ) : left_width = ( x_copy [ i ] - x_copy [ nn_indices [ 0 ] ] ) right_width = ( x_copy [ ( nn_indices [ 1 ] - 1 ) ] - x_copy [ i ] ) width = max ( left_width , right_width ) _lowess_wt_standardize ( weights [ i , : ] , x_copy [ nn_indices [ 0 ] : nn_indices [ 1 ] ] , x_copy [ i ] , width ) _lowess_tricube ( weights [ i , : ] ) weights [ i , : ] = np . sqrt ( weights [ i , : ] ) X [ : , 1 ] = x_copy [ nn_indices [ 0 ] : nn_indices [ 1 ] ] y_i = ( weights [ i , : ] * y_copy [ nn_indices [ 0 ] : nn_indices [ 1 ] ] ) beta = lstsq ( ( weights [ i , : ] . reshape ( k , 1 ) * X ) , y_i ) [ 0 ] fitted [ i ] = ( beta [ 0 ] + ( beta [ 1 ] * x_copy [ i ] ) ) _lowess_update_nn ( x_copy , nn_indices , ( i + 1 ) ) return ( fitted , weights )
the initial weighted local linear regression for lowess .