Skip to content

Instantly share code, notes, and snippets.

@abhijeet-talaulikar
Created August 21, 2023 19:45
Show Gist options
  • Save abhijeet-talaulikar/e408085ebd673259788b2e561653420b to your computer and use it in GitHub Desktop.
Save abhijeet-talaulikar/e408085ebd673259788b2e561653420b to your computer and use it in GitHub Desktop.
def expected_steps(df):
Q = df.drop(
['Null', 'Activation'], axis=1).drop(['Null', 'Activation'], axis=0)
I = np.identity(Q.shape[1])
N = np.linalg.inv(I - Q.to_numpy())
t = np.sum(N, axis=1)
return {v:t[i] for i,v in enumerate(Q.index) if v != 'Start'}
steps = expected_steps(trans_matrix)
df_steps = pd.DataFrame({
'Channel': steps.keys(),
'Next Touchpoints': steps.values()
}).sort_values('Next Touchpoints', ascending=False)
sns.barplot(data=df_steps, x='Channel', y='Next Touchpoints', color='#2653de')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment