<jupyter_start><jupyter_text>sort order of columnscols = list(prob_matrix.columns)cols = [cols[-1]] + cols[:-1]prob_matrix = prob_matrix[cols]<jupyter_code>prob_matrix
# Average number of steps during journey
# counting every stage (including ideling customers)
(df_journey.shape[0]-1)/df_journey['customer_unique'].nunique()
df_journey['customer_unique'].nunique()
len(set(df_journey['customer_unique'].values))
# counting every different stage
df.shape[0]/df_journey['customer_unique'].nunique()
# calculate probabilities at entrance
# by counting first stage of all unique customers
# cal. percentage value
# use this number in markov.next_state('XXX') function 
x = prob_dict.keys()
list(x)[5]<jupyter_output><empty_output><jupyter_text>_______________________________<jupyter_code>class Customer(object):
    def __init__(self, transition_prob):
        """
        Initialize the MarkovChain instance.
        Parameters
        ----------
        transition_prob: dict
            A dict object representing the transition
            probabilities in Markov Chain.
            Should be of the form:
                {'state1': {'state1': 0.1, 'state2': 0.4},
                 'state2': {...}}
        """
        self.transition_prob = transition_prob
        self.states = list(transition_prob.keys())
        self.first_state = 'entrance'

    def next_state(self, current_state):
        return np.random.choice(
            self.states,
            p=[self.transition_prob[current_state][next_state]
               for next_state in self.states])

    def generate_states(self, current_state='entrance', no=50):
        future_states = []
        for i in range(no):
            next_state = self.next_state(current_state)
            future_states.append(next_state)
            current_state = next_state
            if future_states[-1] == self.states[-1]:
                break
        return future_states<jupyter_output><empty_output><jupyter_text>namespacedir(list)<jupyter_code>markow = Customer(prob_dict)
markow.generate_states()
markov.transition_prob<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1112167300380228, 'fraction_numerical': 0.008555133079847909, 'mean_word_length': 3.3135245901639343, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '3203', 'license': 'MIT', 'n_tokens_mistral': 618, 'n_tokens_neox': 605, 'n_words': 124, 'path': 'customer_journey_05.ipynb', 'repo_name': 'quosi/doodl', 'size': '2104'}