(self, choosers, alternatives, current_choice)
return self.log_likelihoods
Fit and save model parameters based on given data.

        Parameters
        ----------
        choosers : pandas.DataFrame
            Table describing the agents making choices, e.g. households.
        alternatives : pandas.DataFrame
            Table describing the things from which agents are choosing,
            e.g. buildings.
        current_choice : pandas.Series or any
            A Series describing the `alternatives` currently chosen
            by the `choosers`. Should have an index matching `choosers`
            and values matching the index of `alternatives`.

            If a non-Series is given it should be a column in `choosers`.

        Returns
        -------
        log_likelihoods : dict
            Dict of log-liklihood values describing the quality of the
            model fit. Will have keys 'null', 'convergence', and 'ratio'.
Fit and save model parameters based on given data.
Fit and save model parameters based on given data .
def fit(self, choosers, alternatives, current_choice):
        """
        Fit and save model parameters based on given data.

        Parameters
        ----------
        choosers : pandas.DataFrame
            Table describing the agents making choices, e.g. households.
        alternatives : pandas.DataFrame
            Table describing the things from which agents are choosing,
            e.g. buildings.
        current_choice : pandas.Series or any
            A Series describing the `alternatives` currently chosen
            by the `choosers`. Should have an index matching `choosers`
            and values matching the index of `alternatives`.

            If a non-Series is given it should be a column in `choosers`.

        Returns
        -------
        log_likelihoods : dict
            Dict of log-liklihood values describing the quality of the
            model fit. Will have keys 'null', 'convergence', and 'ratio'.

        """
        logger.debug('start: fit LCM model {}'.format(self.name))

        if not isinstance(current_choice, pd.Series):
            current_choice = choosers[current_choice]

        choosers, alternatives = self.apply_fit_filters(choosers, alternatives)

        if self.estimation_sample_size:
            choosers = choosers.loc[np.random.choice(
                choosers.index,
                min(self.estimation_sample_size, len(choosers)),
                replace=False)]

        current_choice = current_choice.loc[choosers.index]

        _, merged, chosen = interaction.mnl_interaction_dataset(
            choosers, alternatives, self.sample_size, current_choice)
        model_design = dmatrix(
            self.str_model_expression, data=merged, return_type='dataframe')

        if len(merged) != model_design.values.shape[0]:
            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.')

        self.log_likelihoods, self.fit_parameters = mnl.mnl_estimate(
            model_design.values, chosen, self.sample_size)
        self.fit_parameters.index = model_design.columns

        logger.debug('finish: fit LCM model {}'.format(self.name))
        return self.log_likelihoods
def fit ( self , choosers , alternatives , current_choice ) : logger . debug ( 'start: fit LCM model {}' . format ( self . name ) ) if not isinstance ( current_choice , pd . Series ) : current_choice = choosers [ current_choice ] choosers , alternatives = self . apply_fit_filters ( choosers , alternatives ) if self . estimation_sample_size : choosers = choosers . loc [ np . random . choice ( choosers . index , min ( self . estimation_sample_size , len ( choosers ) ) , replace = False ) ] current_choice = current_choice . loc [ choosers . index ] _ , merged , chosen = interaction . mnl_interaction_dataset ( choosers , alternatives , self . sample_size , current_choice ) model_design = dmatrix ( self . str_model_expression , data = merged , return_type = 'dataframe' ) if len ( merged ) != model_design . values . shape [ 0 ] : 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.' ) self . log_likelihoods , self . fit_parameters = mnl . mnl_estimate ( model_design . values , chosen , self . sample_size ) self . fit_parameters . index = model_design . columns logger . debug ( 'finish: fit LCM model {}' . format ( self . name ) ) return self . log_likelihoods