code: def test_preprocess_data_weighted(setup):
      n_samples = 200
      n_features = 2
      X = rng.rand(n_samples, n_features)
      y = rng.rand(n_samples)
      sample_weight = rng.rand(n_samples)
      expected_X_mean = np.average(X, axis=0, weights=sample_weight)
      expected_y_mean = np.average(y, axis=0, weights=sample_weight)
  
      # XXX: if normalize=True, should we expect a weighted standard deviation?
      #      Currently not weighted, but calculated with respect to weighted mean
      expected_X_norm = (
          np.sqrt(X.shape[0])
          * np.mean((X - expected_X_mean) ** 2, axis=0) ** 0.5
      )
  
      Xt, yt, X_mean, y_mean, X_norm = _preprocess_data(
          X,
          y,
          fit_intercept=True,
          normalize=False,
          sample_weight=sample_weight,
      )
      assert_array_almost_equal(X_mean, expected_X_mean)
      assert_array_almost_equal(y_mean, expected_y_mean)
      assert_array_almost_equal(X_norm, np.ones(n_features))
      assert_array_almost_equal(Xt, X - expected_X_mean)
      assert_array_almost_equal(yt, y - expected_y_mean)
  
      Xt, yt, X_mean, y_mean, X_norm = _preprocess_data(
          X,
          y,
          fit_intercept=True,
          normalize=True,
          sample_weight=sample_weight,
      )
      assert_array_almost_equal(X_mean, expected_X_mean)
      assert_array_almost_equal(y_mean, expected_y_mean)
      assert_array_almost_equal(X_norm, expected_X_norm)
      assert_array_almost_equal(
          Xt, (X - expected_X_mean) / expected_X_norm
      )
      assert_array_almost_equal(yt, y - expected_y_mean)
  
imports: import re
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal, assert_array_equal, assert_almost_equal, assert_allclose
  from scipy import sparse
  from scipy import linalg
  from sklearn.datasets import make_sparse_uncorrelated, make_regression, load_iris
  from sklearn.linear_model import LinearRegression
  from sklearn.linear_model._base import make_dataset
  from sklearn.utils import check_random_state
  from ..None import LinearRegression
  from .._base import _preprocess_data, _rescale_data
label_desc: Use image node_id 14 for calling a global function with example usage: test_preprocess_data_weighted(setup) without return types