RFGF
RFGF
Experiment 05
Number
Problem
Predicting Customer Behavior Using Markov Chains
Statement
A retail company aims to predict customer behavior based on past
interactions. Customers transition between different states such as browsing
products, adding items to the cart, making a purchase, or abandoning the
site.
def compute_steady_state(T):
"""
Computes the steady-state probability vector for a
given transition matrix T.
"""
# Number of states
n = T.shape[0]
return steady_state
steady_state = compute_steady_state(T)
for i in range(len(states)):
for j in range(len(states)):
if T[i, j] > 0: # Only show transitions
with probability > 0
G.add_edge(states[i], states[j],
weight=T[i, j])
pos = nx.spring_layout(G)
labels = {(states[i], states[j]): f"{T[i, j]:.2f}"
for i in range(len(states)) for j in range(len(states))
if T[i, j] > 0}
plt.figure(figsize=(8, 6))
nx.draw(G, pos, with_labels=True,
node_color='lightblue', edge_color='gray',
node_size=3000, font_size=10)
nx.draw_networkx_edge_labels(G, pos,
edge_labels=labels)
plt.title("Markov State Transition Diagram")
plt.show()
draw_markov_chain(T, states)
Output
`
Business Insights & Applications
Using the Markov model, we can extract insights and apply strategies
to improve customer behavior:
Conclusion The Markov model helps predict customer behavior, highlighting key
areas for improvement. High retention loss suggests many users drop
off before purchasing, requiring better engagement strategies. A low
conversion rate indicates the need for optimized marketing and UX
enhancements. Businesses can use targeted marketing, discounts,
and A/B testing to improve customer retention and sales.