(self, choosers, alternatives, filter_tables=True)
return probabilities
Returns the probabilities for a set of choosers to choose
        from among a set of alternatives.

        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.
        filter_tables : bool, optional
            If True, filter `choosers` and `alternatives` with prediction
            filters before calculating probabilities.

        Returns
        -------
        probabilities : pandas.Series
            Probability of selection associated with each chooser
            and alternative. Index will be a MultiIndex with alternative
            IDs in the inner index and chooser IDs in the out index.
Returns the probabilities for a set of choosers to choose
        from among a set of alternatives.
Returns the probabilities for a set of choosers to choose from among a set of alternatives .
def probabilities(self, choosers, alternatives, filter_tables=True):
        """
        Returns the probabilities for a set of choosers to choose
        from among a set of alternatives.

        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.
        filter_tables : bool, optional
            If True, filter `choosers` and `alternatives` with prediction
            filters before calculating probabilities.

        Returns
        -------
        probabilities : pandas.Series
            Probability of selection associated with each chooser
            and alternative. Index will be a MultiIndex with alternative
            IDs in the inner index and chooser IDs in the out index.

        """
        logger.debug('start: calculate probabilities for LCM model {}'.format(
            self.name))
        self.assert_fitted()

        if filter_tables:
            choosers, alternatives = self.apply_predict_filters(
                choosers, alternatives)

        if self.prediction_sample_size is not None:
            sample_size = self.prediction_sample_size
        else:
            sample_size = len(alternatives)

        if self.probability_mode == 'single_chooser':
            _, merged, _ = interaction.mnl_interaction_dataset(
                choosers.head(1), alternatives, sample_size)
        elif self.probability_mode == 'full_product':
            _, merged, _ = interaction.mnl_interaction_dataset(
                choosers, alternatives, sample_size)
        else:
            raise ValueError(
                'Unrecognized probability_mode option: {}'.format(
                    self.probability_mode))

        merged = util.apply_filter_query(
            merged, self.interaction_predict_filters)
        model_design = dmatrix(
            self.str_model_expression, data=merged, return_type='dataframe')

        if len(merged) != model_design.values.shape[0]:
            raise ModelEvaluationError(
                'Simulated data does not have the same length as input.  '
                'This suggests there are null values in one or more of '
                'the input columns.')

        # get the order of the coefficients in the same order as the
        # columns in the design matrix
        coeffs = [self.fit_parameters['Coefficient'][x]
                  for x in model_design.columns]

        # probabilities are returned from mnl_simulate as a 2d array
        # with choosers along rows and alternatives along columns
        if self.probability_mode == 'single_chooser':
            numalts = len(merged)
        else:
            numalts = sample_size

        probabilities = mnl.mnl_simulate(
            model_design.values,
            coeffs,
            numalts=numalts, returnprobs=True)

        # want to turn probabilities into a Series with a MultiIndex
        # of chooser IDs and alternative IDs.
        # indexing by chooser ID will get you the probabilities
        # across alternatives for that chooser
        mi = pd.MultiIndex.from_arrays(
            [merged['join_index'].values, merged.index.values],
            names=('chooser_id', 'alternative_id'))
        probabilities = pd.Series(probabilities.flatten(), index=mi)

        logger.debug('finish: calculate probabilities for LCM model {}'.format(
            self.name))
        return probabilities
def probabilities ( self , choosers , alternatives , filter_tables = True ) : logger . debug ( 'start: calculate probabilities for LCM model {}' . format ( self . name ) ) self . assert_fitted ( ) if filter_tables : choosers , alternatives = self . apply_predict_filters ( choosers , alternatives ) if self . prediction_sample_size is not None : sample_size = self . prediction_sample_size else : sample_size = len ( alternatives ) if self . probability_mode == 'single_chooser' : _ , merged , _ = interaction . mnl_interaction_dataset ( choosers . head ( 1 ) , alternatives , sample_size ) elif self . probability_mode == 'full_product' : _ , merged , _ = interaction . mnl_interaction_dataset ( choosers , alternatives , sample_size ) else : raise ValueError ( 'Unrecognized probability_mode option: {}' . format ( self . probability_mode ) ) merged = util . apply_filter_query ( merged , self . interaction_predict_filters ) model_design = dmatrix ( self . str_model_expression , data = merged , return_type = 'dataframe' ) if len ( merged ) != model_design . values . shape [ 0 ] : raise ModelEvaluationError ( 'Simulated data does not have the same length as input.  ' 'This suggests there are null values in one or more of ' 'the input columns.' ) # get the order of the coefficients in the same order as the # columns in the design matrix coeffs = [ self . fit_parameters [ 'Coefficient' ] [ x ] for x in model_design . columns ] # probabilities are returned from mnl_simulate as a 2d array # with choosers along rows and alternatives along columns if self . probability_mode == 'single_chooser' : numalts = len ( merged ) else : numalts = sample_size probabilities = mnl . mnl_simulate ( model_design . values , coeffs , numalts = numalts , returnprobs = True ) # want to turn probabilities into a Series with a MultiIndex # of chooser IDs and alternative IDs. # indexing by chooser ID will get you the probabilities # across alternatives for that chooser mi = pd . MultiIndex . from_arrays ( [ merged [ 'join_index' ] . values , merged . index . values ] , names = ( 'chooser_id' , 'alternative_id' ) ) probabilities = pd . Series ( probabilities . flatten ( ) , index = mi ) logger . debug ( 'finish: calculate probabilities for LCM model {}' . format ( self . name ) ) return probabilities