def test_regression_iterate_seed(self):
    elastic_net = linear_model.ElasticNet(random_state=123)
    expected_result = bootstrap.regression_iterate(
        elastic_net, self.data, self.target, seed=1)

    result = bootstrap.regression_iterate(
        elastic_net, self.data, self.target, seed=1)

    self.assertIsInstance(result, dict)
    self.assertEqual(result, expected_result)
  def test_regression_iterate_randomize_target(self):
    """Ensures the target randomization delivers different results."""
    kw = {'regressor': linear_model.Ridge(),
          'data': self.data,
          'target': self.target}

    bootstrapped_results = bootstrap.regression_iterate(
        randomize_target=False, **kw)
    randomized_results = bootstrap.regression_iterate(
        randomize_target=True, **kw)

    # Checks randomize and bootstrap results have same keys.
    self.assertEqual(randomized_results.keys(), bootstrapped_results.keys())
    # But they have different data.
    self.assertNotEqual(
        randomized_results.values(), bootstrapped_results.values())
  def test_regression_not_numeric_index(self):
    """Makes sure that regression_iterate handles non numeric indexing."""
    elastic_net = linear_model.ElasticNet(random_state=123)
    data = self.data.copy()
    target = self.target.copy()
    # Convert index to string for `data` and `target`
    data.index = [f'data_{index}' for index in data.index]
    target.index = [f'test_{index}' for index in target.index]
    expected_result = bootstrap.regression_iterate(
        elastic_net, self.data, self.target, seed=1)

    result = bootstrap.regression_iterate(
        elastic_net, data, target, seed=1)

    self.assertIsInstance(result, dict)
    self.assertEqual(result, expected_result)
  def test_regression_iterate_no_intercept(self):
    elastic_net = linear_model.ElasticNet(fit_intercept=False)
    expected_keys = set(self.data.columns)

    result = bootstrap.regression_iterate(
        elastic_net, self.data, self.target, seed=1)

    self.assertIsInstance(result, dict)
    # Assert all the keys are the DataFrame columns.
    self.assertEqual(expected_keys, set(result))
  def test_regression_iterate(self):
    elastic_net = linear_model.ElasticNet()
    expected_keys = set(list(self.data.columns) + ['Intercept'])

    result = bootstrap.regression_iterate(
        elastic_net, self.data, self.target, seed=1)

    self.assertIsInstance(result, dict)
    # Assert all the keys are the DataFrame columns plus the intercept.
    self.assertEqual(expected_keys, set(result))