code: def train_and_compare(
      self,
      model_type,
      xs,
      ys,
      expected_loss,
      expected_reg=0.0,
      expected_hyperplane=None,
      norm_hyperplane=True,
      weights=None,
      delta=0.1,
      init_scheme="zeros",
      objective="lasso",
      bias=True,
  ):
      assert objective in ["lasso", "ridge", "ols"]
  
      if weights is None:
          train_dataset = torch.utils.data.TensorDataset(xs, ys)
      else:
          train_dataset = torch.utils.data.TensorDataset(
              xs, ys, weights
          )
  
      train_loader = torch.utils.data.DataLoader(
          train_dataset, batch_size=len(train_dataset), num_workers=0
      )
  
      model = model_type(bias=bias)
      model.fit(
          train_loader,
          init_scheme=init_scheme,
          max_epoch=150,
          initial_lr=0.1,
          patience=5,
      )
  
      self.assertTrue(
          model.bias() is not None if bias else model.bias() is None
      )
  
      l2_loss = _evaluate(train_loader, model)["l2"]
  
      if objective == "lasso":
          reg = model.representation().norm(p=1).view_as(l2_loss)
      elif objective == "ridge":
          reg = model.representation().norm(p=2).view_as(l2_loss)
      else:
          assert objective == "ols"
          reg = torch.zeros_like(l2_loss)
  
      if not isinstance(expected_loss, torch.Tensor):
          expected_loss = torch.tensor(
              [expected_loss], dtype=l2_loss.dtype
          ).view(1)
  
      if not isinstance(expected_reg, torch.Tensor):
          expected_reg = torch.tensor([expected_reg], dtype=reg.dtype)
  
      assertTensorAlmostEqual(self, l2_loss, expected_loss, delta=delta)
      assertTensorAlmostEqual(self, reg, expected_reg, delta=delta)
  
      if expected_hyperplane is not None:
          h = model.representation()
          if norm_hyperplane:
              h /= h.norm(p=2)
          assertTensorAlmostEqual(
              self, h, expected_hyperplane, delta=delta
          )
  
file_path: captum/tests/utils/test_linear_model.py
imports: import torch
  from captum._utils.models.linear_model.model import SGDLasso, SGDLinearRegression, SGDRidge
  from tests.helpers.basic import assertTensorAlmostEqual, BaseTest
label_desc: Use image node_id 1 for calling the TestLinearModel obj's underlying member method code with example usage: obj.train_and_compare(model_type, xs, ys, expected_loss, expected_reg, expected_hyperplane, norm_hyperplane, weights, delta, init_scheme, objective, bias) without return types