code: def fit_model(df, filters, model_expression):
      
      df = util.apply_filter_query(df, filters)
      model = smf.ols(formula=model_expression, data=df)
  
      if len(model.exog) != len(df):
          raise ModelEvaluationError(
              'Estimated data does not have the same length as input.  '
              'This suggests there are null values in one or more of '
              'the input columns.')
  
      with log_start_finish('statsmodels OLS fit', logger):
          return model.fit()
docs: Use statsmodels OLS to construct a model relation.
  
      Parameters
      ----------
      df : pandas.DataFrame
          Data to use for fit. Should contain all the columns
          referenced in the `model_expression`.
      filters : list of str
          Any filters to apply before doing the model fit.
      model_expression : str
          A patsy model expression that can be used with statsmodels.
          Should contain both the left- and right-hand sides.
  
      Returns
      -------
      fit : statsmodels.regression.linear_model.OLSResults