Forked from abhijeet-talaulikar/mta-credit-card-steps.py
Created
September 27, 2023 16:02
-
-
Save Sandy4321/a8af6e7d29087350dd1b1f7cb0d67664 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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