code: def test_supervised(self):
      # Generate some data
      X = rand(3, 2)
      Y = rand(3, 1)
      feature_names = ["x1", "x2"]
      outcome_names = ["y"]
  
      # Test `__init__`
      dataset = SupervisedDataset(
          X=X,
          Y=Y,
          feature_names=feature_names,
          outcome_names=outcome_names,
      )
      self.assertIsInstance(dataset.X, Tensor)
      self.assertIsInstance(dataset._X, Tensor)
      self.assertIsInstance(dataset.Y, Tensor)
      self.assertIsInstance(dataset._Y, Tensor)
      self.assertEqual(dataset.feature_names, feature_names)
      self.assertEqual(dataset.outcome_names, outcome_names)
  
      dataset2 = SupervisedDataset(
          X=DenseContainer(X, X.shape[-1:]),
          Y=DenseContainer(Y, Y.shape[-1:]),
          feature_names=feature_names,
          outcome_names=outcome_names,
      )
      self.assertIsInstance(dataset2.X, Tensor)
      self.assertIsInstance(dataset2._X, DenseContainer)
      self.assertIsInstance(dataset2.Y, Tensor)
      self.assertIsInstance(dataset2._Y, DenseContainer)
      self.assertEqual(dataset, dataset2)
  
      # Test `_validate`
      with self.assertRaisesRegex(
          ValueError, "Batch dimensions .* incompatible."
      ):
          SupervisedDataset(
              X=rand(1, 2),
              Y=rand(2, 1),
              feature_names=feature_names,
              outcome_names=outcome_names,
          )
      with self.assertRaisesRegex(ValueError, "`Y` and `Yvar`"):
          SupervisedDataset(
              X=rand(2, 2),
              Y=rand(2, 1),
              Yvar=rand(2),
              feature_names=feature_names,
              outcome_names=outcome_names,
          )
      with self.assertRaisesRegex(ValueError, "feature_names"):
          SupervisedDataset(
              X=rand(2, 2),
              Y=rand(2, 1),
              feature_names=[],
              outcome_names=outcome_names,
          )
      with self.assertRaisesRegex(ValueError, "outcome_names"):
          SupervisedDataset(
              X=rand(2, 2),
              Y=rand(2, 1),
              feature_names=feature_names,
              outcome_names=[],
          )
  
      # Test with Yvar.
      dataset = SupervisedDataset(
          X=X,
          Y=Y,
          Yvar=DenseContainer(Y, Y.shape[-1:]),
          feature_names=feature_names,
          outcome_names=outcome_names,
      )
      self.assertIsInstance(dataset.X, Tensor)
      self.assertIsInstance(dataset._X, Tensor)
      self.assertIsInstance(dataset.Y, Tensor)
      self.assertIsInstance(dataset._Y, Tensor)
      self.assertIsInstance(dataset.Yvar, Tensor)
      self.assertIsInstance(dataset._Yvar, DenseContainer)
  
      # More equality checks with & without Yvar.
      self.assertEqual(dataset, dataset)
      self.assertNotEqual(dataset, dataset2)
      self.assertNotEqual(dataset2, dataset)
  
file_path: botorch/test/utils/test_datasets.py
imports: from typing import List, Optional
  import torch
  from botorch.exceptions.errors import InputDataError, UnsupportedError
  from botorch.utils.containers import DenseContainer, SliceContainer
  from botorch.utils.datasets import ContextualDataset, FixedNoiseDataset, MultiTaskDataset, RankingDataset, SupervisedDataset
  from botorch.utils.testing import BotorchTestCase
  from torch import rand, randperm, Size, stack, Tensor, tensor
label_desc: Use image node_id 1 for calling the TestDatasets obj's underlying member method code with example usage: obj.test_supervised() without return types