docstr: Ensure that `Factor.linear_regression` is consistent with the built-in
  factor `RollingLinearRegressionOfReturns`.
docstr_tok: ["Ensure","that","`","Factor.linear_regression","`","is","consistent","with","the","built-in","factor","`","RollingLinearRegressionOfReturns","`","."]
code: def _test_factor_regression_method(
      self, returns_length, regression_length
  ):
      """
      Ensure that `Factor.linear_regression` is consistent with the built-in
      factor `RollingLinearRegressionOfReturns`.
      """
      my_asset = self.asset_finder.retrieve_asset(self.sids[0])
  
      returns = Returns(window_length=returns_length, inputs=[self.col])
      returns_slice = returns[my_asset]
  
      regression = returns.linear_regression(
          target=returns_slice,
          regression_length=regression_length,
      )
      expected_regression = RollingLinearRegressionOfReturns(
          target=my_asset,
          returns_length=returns_length,
          regression_length=regression_length,
      )
  
      # These built-ins construct their own Returns factor to use as inputs,
      # so the only way to set our own inputs is to do so after the fact.
      # This should not be done in practice. It is necessary here because we
      # want Returns to use our random data as an input, but by default it is
      # using USEquityPricing.close.
      expected_regression.inputs = [returns, returns_slice]
  
      columns = {
          "regression": regression,
          "expected_regression": expected_regression,
      }
  
      results = self.run_pipeline(
          Pipeline(columns=columns),
          self.pipeline_start_date,
          self.pipeline_end_date,
      )
      regression_results = results["regression"].unstack()
      expected_regression_results = results[
          "expected_regression"
      ].unstack()
  
      assert_frame_equal(
          regression_results, expected_regression_results
      )
  
      # Make sure we cannot call the linear regression method on factors or
      # slices of dtype `datetime64[ns]`.
      class DateFactor(CustomFactor):
          window_length = 1
          inputs = []
          dtype = datetime64ns_dtype
          window_safe = True
  
          def compute(self, today, assets, out):
              pass
  
      date_factor = DateFactor()
      date_factor_slice = date_factor[my_asset]
  
      with self.assertRaises(TypeError):
          date_factor.linear_regression(
              target=returns_slice,
              regression_length=regression_length,
          )
      with self.assertRaises(TypeError):
          returns.linear_regression(
              target=date_factor_slice,
              regression_length=regression_length,
          )
  
imports: from numpy import where
  from pandas import Int64Index, Timestamp
  from pandas.util.testing import assert_frame_equal
  from catalyst.assets import Asset
  from catalyst.errors import NonExistentAssetInTimeFrame, NonSliceableTerm, NonWindowSafeInput, UnsupportedPipelineOutput
  from catalyst.pipeline import CustomFactor, Pipeline
  from catalyst.pipeline.data import USEquityPricing
  from catalyst.pipeline.data.testing import TestingDataSet
  from catalyst.pipeline.factors.equity import Returns, RollingLinearRegressionOfReturns, RollingPearsonOfReturns, RollingSpearmanOfReturns, SimpleMovingAverage
  from catalyst.testing import AssetID, AssetIDPlusDay, check_arrays, OpenPrice, parameter_space
  from catalyst.testing.fixtures import WithSeededRandomPipelineEngine, CatalystTestCase
  from catalyst.utils.numpy_utils import datetime64ns_dtype
label_desc: Use image node_id 11 for calling the SliceTestCase obj's underlying member method code with example usage: obj._test_factor_regression_method(returns_length, regression_length) without return types