code: def test_multiclass_singletask():
      """Test balancing transformer on single-task dataset."""
      n_samples = 50
      n_features = 3
      n_tasks = 1
      n_classes = 5
      ids = np.arange(n_samples)
      X = np.random.rand(n_samples, n_features)
      y = np.random.randint(n_classes, size=(n_samples, n_tasks))
      w = np.ones((n_samples, n_tasks))
      dataset = dc.data.NumpyDataset(X, y, w)
  
      balancing_transformer = dc.trans.BalancingTransformer(
          dataset=dataset
      )
      dataset = balancing_transformer.transform(dataset)
      X_t, y_t, w_t, ids_t = (
          dataset.X,
          dataset.y,
          dataset.w,
          dataset.ids,
      )
      # Check ids are unchanged.
      for id_elt, id_t_elt in zip(ids, ids_t):
          assert id_elt == id_t_elt
      # Check X is unchanged since this is a w transformer
      np.testing.assert_allclose(X, X_t)
      # Check y is unchanged since this is a w transformer
      np.testing.assert_allclose(y, y_t)
      for ind, task in enumerate(dataset.get_task_names()):
          y_task = y_t[:, ind]
          w_task = w_t[:, ind]
          # Check that sum of 0s equals sum of 1s in transformed for each task
          for i, j in itertools.product(
              range(n_classes), range(n_classes)
          ):
              if i == j:
                  continue
              assert np.isclose(
                  np.sum(w_task[y_task == i]),
                  np.sum(w_task[y_task == j]),
              )
  
file_path: deepchem/deepchem/trans/tests/test_balancing.py
imports: import itertools
  import tempfile
  import numpy
  import deepchem
label_desc: Use image node_id 4 for calling a global function with example usage: test_multiclass_singletask() without return types