code: def test_multiclass_singletask():
      """Test balancing transformer on single-task dataset."""
      n_samples = 10
      n_features = 3
      X = np.random.rand(n_samples, n_features)
      # 6-1 imbalance in favor of class 0
      y = np.array([0, 0, 0, 0, 0, 0, 1, 2, 3, 4])
      w = np.ones((n_samples,))
      dataset = dc.data.NumpyDataset(X, y, w)
  
      duplicator = dc.trans.DuplicateBalancingTransformer(
          dataset=dataset
      )
      dataset = duplicator.transform(dataset)
      X_t, y_t, w_t, ids_t = (
          dataset.X,
          dataset.y,
          dataset.w,
          dataset.ids,
      )
  
      # Check that we have length 30 now with duplication
      assert len(dataset) == 30
      X_t, y_t, w_t, ids_t = (
          dataset.X,
          dataset.y,
          dataset.w,
          dataset.ids,
      )
      # Check shapes
      assert X_t.shape == (30, n_features)
      assert y_t.shape == (30,)
      assert w_t.shape == (30,)
      assert ids_t.shape == (30,)
      # Check that we have 6 of each class
      assert np.sum(y_t == 0) == 6
      assert np.sum(y_t == 1) == 6
      assert np.sum(y_t == 2) == 6
      assert np.sum(y_t == 3) == 6
      assert np.sum(y_t == 4) == 6
      # Check that sum of all class weights is equal by comparing to 0 weight
      assert np.isclose(np.sum(w_t[y_t == 0]), np.sum(w_t[y_t == 1]))
      assert np.isclose(np.sum(w_t[y_t == 0]), np.sum(w_t[y_t == 2]))
      assert np.isclose(np.sum(w_t[y_t == 0]), np.sum(w_t[y_t == 3]))
      assert np.isclose(np.sum(w_t[y_t == 0]), np.sum(w_t[y_t == 4]))
  
file_path: deepchem/deepchem/trans/tests/test_duplicate_balancing.py
imports: import numpy
  import tempfile
  import deepchem
label_desc: Use image node_id 4 for calling a global function with example usage: test_multiclass_singletask() without return types