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.my_asset
      start_date = self.pipeline_start_date
      end_date = self.pipeline_end_date
      run_pipeline = self.run_pipeline
  
      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,
      )
  
      # This built-in constructs its own Returns factor to use as an input,
      # so the only way to set our own input 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 = run_pipeline(
          Pipeline(columns=columns), start_date, end_date
      )
      regression_results = results["regression"].unstack()
      expected_regression_results = results[
          "expected_regression"
      ].unstack()
  
      assert_frame_equal(
          regression_results, expected_regression_results
      )
  
imports: import numpy
  from numpy import arange, full, full_like, nan, where
  from pandas import DataFrame, date_range, Int64Index, Timestamp
  from pandas.util.testing import assert_frame_equal
  from scipy.stats import linregress, pearsonr, spearmanr
  from empyrical.stats import beta_aligned
  from zipline.assets import Equity, ExchangeInfo
  from zipline.errors import IncompatibleTerms, NonExistentAssetInTimeFrame
  from zipline.pipeline import CustomFactor, Pipeline
  from zipline.pipeline.data import USEquityPricing
  from zipline.pipeline.data.testing import TestingDataSet
  from zipline.pipeline.domain import US_EQUITIES
  from zipline.pipeline.engine import SimplePipelineEngine
  from zipline.pipeline.factors import Returns, RollingLinearRegressionOfReturns, RollingPearsonOfReturns, RollingSpearmanOfReturns, SimpleBeta
  from zipline.pipeline.factors.statistical import vectorized_beta, vectorized_pearson_r
  from zipline.pipeline.loaders.frame import DataFrameLoader
  from zipline.pipeline.sentinels import NotSpecified
  from zipline.testing import AssetID, AssetIDPlusDay, check_arrays, make_alternating_boolean_array, make_cascading_boolean_array, parameter_space
  import zipline.testing.fixtures
  from zipline.testing.predicates import assert_equal
  from zipline.utils.numpy_utils import as_column, bool_dtype, datetime64ns_dtype, float64_dtype
label_desc: Use image node_id 4 for calling the StatisticalMethodsTestCase obj's underlying member method code with example usage: obj.test_factor_regression_method(returns_length, regression_length) without return types