Last active
November 17, 2019 21:34
-
-
Save MortenHegewald/d13a1288da1d92e00379fc97af6fa0d1 to your computer and use it in GitHub Desktop.
MA - Transition Matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def transition_matrix(list_of_paths, transition_probabilities): | |
trans_matrix = pd.DataFrame() | |
list_of_unique_channels = set(x for element in list_of_paths for x in element) | |
for channel in list_of_unique_channels: | |
trans_matrix[channel] = 0.00 | |
trans_matrix.loc[channel] = 0.00 | |
trans_matrix.loc[channel][channel] = 1.0 if channel in ['Conversion', 'Null'] else 0.0 | |
for key, value in transition_probabilities.items(): | |
origin, destination = key.split('>') | |
trans_matrix.at[origin, destination] = value | |
return trans_matrix | |
trans_matrix = transition_matrix(list_of_paths, trans_prob) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment