(self, data, debug=False)
Fit each segment. Segments that have not already been explicitly
        added will be automatically added with default model and ytransform.

        Parameters
        ----------
        data : pandas.DataFrame
            Must have a column with the same name as `segmentation_col`.
        debug : bool
            If set to true will pass debug to the fit method of each model.

        Returns
        -------
        fits : dict of statsmodels.regression.linear_model.OLSResults
            Keys are the segment names.
Fit each segment. Segments that have not already been explicitly
        added will be automatically added with default model and ytransform.
Fit each segment . Segments that have not already been explicitly added will be automatically added with default model and ytransform .
def fit(self, data, debug=False):
        """
        Fit each segment. Segments that have not already been explicitly
        added will be automatically added with default model and ytransform.

        Parameters
        ----------
        data : pandas.DataFrame
            Must have a column with the same name as `segmentation_col`.
        debug : bool
            If set to true will pass debug to the fit method of each model.

        Returns
        -------
        fits : dict of statsmodels.regression.linear_model.OLSResults
            Keys are the segment names.

        """
        data = util.apply_filter_query(data, self.fit_filters)

        unique = data[self.segmentation_col].unique()
        value_counts = data[self.segmentation_col].value_counts()

        # Remove any existing segments that may no longer have counterparts
        # in the data. This can happen when loading a saved model and then
        # calling this method with data that no longer has segments that
        # were there the last time this was called.
        gone = set(self._group.models) - set(unique)
        for g in gone:
            del self._group.models[g]

        for x in unique:
            if x not in self._group.models and \
                    value_counts[x] > self.min_segment_size:
                self.add_segment(x)

        with log_start_finish(
                'fitting models in segmented model {}'.format(self.name),
                logger):
            return self._group.fit(data, debug=debug)
def fit ( self , data , debug = False ) : data = util . apply_filter_query ( data , self . fit_filters ) unique = data [ self . segmentation_col ] . unique ( ) value_counts = data [ self . segmentation_col ] . value_counts ( ) # Remove any existing segments that may no longer have counterparts # in the data. This can happen when loading a saved model and then # calling this method with data that no longer has segments that # were there the last time this was called. gone = set ( self . _group . models ) - set ( unique ) for g in gone : del self . _group . models [ g ] for x in unique : if x not in self . _group . models and value_counts [ x ] > self . min_segment_size : self . add_segment ( x ) with log_start_finish ( 'fitting models in segmented model {}' . format ( self . name ) , logger ) : return self . _group . fit ( data , debug = debug )