Created
May 3, 2019 20:40
-
-
Save karamanbk/e873e28f095dece22d6fb36ca84b8714 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
#Revenue vs Frequency | |
tx_graph = tx_user.query("Revenue < 50000 and Frequency < 2000") | |
plot_data = [ | |
go.Scatter( | |
x=tx_graph.query("Segment == 'Low-Value'")['Frequency'], | |
y=tx_graph.query("Segment == 'Low-Value'")['Revenue'], | |
mode='markers', | |
name='Low', | |
marker= dict(size= 7, | |
line= dict(width=1), | |
color= 'blue', | |
opacity= 0.8 | |
) | |
), | |
go.Scatter( | |
x=tx_graph.query("Segment == 'Mid-Value'")['Frequency'], | |
y=tx_graph.query("Segment == 'Mid-Value'")['Revenue'], | |
mode='markers', | |
name='Mid', | |
marker= dict(size= 9, | |
line= dict(width=1), | |
color= 'green', | |
opacity= 0.5 | |
) | |
), | |
go.Scatter( | |
x=tx_graph.query("Segment == 'High-Value'")['Frequency'], | |
y=tx_graph.query("Segment == 'High-Value'")['Revenue'], | |
mode='markers', | |
name='High', | |
marker= dict(size= 11, | |
line= dict(width=1), | |
color= 'red', | |
opacity= 0.9 | |
) | |
), | |
] | |
plot_layout = go.Layout( | |
yaxis= {'title': "Revenue"}, | |
xaxis= {'title': "Frequency"}, | |
title='Segments' | |
) | |
fig = go.Figure(data=plot_data, layout=plot_layout) | |
pyoff.iplot(fig) | |
#Revenue Recency | |
tx_graph = tx_user.query("Revenue < 50000 and Frequency < 2000") | |
plot_data = [ | |
go.Scatter( | |
x=tx_graph.query("Segment == 'Low-Value'")['Recency'], | |
y=tx_graph.query("Segment == 'Low-Value'")['Revenue'], | |
mode='markers', | |
name='Low', | |
marker= dict(size= 7, | |
line= dict(width=1), | |
color= 'blue', | |
opacity= 0.8 | |
) | |
), | |
go.Scatter( | |
x=tx_graph.query("Segment == 'Mid-Value'")['Recency'], | |
y=tx_graph.query("Segment == 'Mid-Value'")['Revenue'], | |
mode='markers', | |
name='Mid', | |
marker= dict(size= 9, | |
line= dict(width=1), | |
color= 'green', | |
opacity= 0.5 | |
) | |
), | |
go.Scatter( | |
x=tx_graph.query("Segment == 'High-Value'")['Recency'], | |
y=tx_graph.query("Segment == 'High-Value'")['Revenue'], | |
mode='markers', | |
name='High', | |
marker= dict(size= 11, | |
line= dict(width=1), | |
color= 'red', | |
opacity= 0.9 | |
) | |
), | |
] | |
plot_layout = go.Layout( | |
yaxis= {'title': "Revenue"}, | |
xaxis= {'title': "Recency"}, | |
title='Segments' | |
) | |
fig = go.Figure(data=plot_data, layout=plot_layout) | |
pyoff.iplot(fig) | |
# Revenue vs Frequency | |
tx_graph = tx_user.query("Revenue < 50000 and Frequency < 2000") | |
plot_data = [ | |
go.Scatter( | |
x=tx_graph.query("Segment == 'Low-Value'")['Recency'], | |
y=tx_graph.query("Segment == 'Low-Value'")['Frequency'], | |
mode='markers', | |
name='Low', | |
marker= dict(size= 7, | |
line= dict(width=1), | |
color= 'blue', | |
opacity= 0.8 | |
) | |
), | |
go.Scatter( | |
x=tx_graph.query("Segment == 'Mid-Value'")['Recency'], | |
y=tx_graph.query("Segment == 'Mid-Value'")['Frequency'], | |
mode='markers', | |
name='Mid', | |
marker= dict(size= 9, | |
line= dict(width=1), | |
color= 'green', | |
opacity= 0.5 | |
) | |
), | |
go.Scatter( | |
x=tx_graph.query("Segment == 'High-Value'")['Recency'], | |
y=tx_graph.query("Segment == 'High-Value'")['Frequency'], | |
mode='markers', | |
name='High', | |
marker= dict(size= 11, | |
line= dict(width=1), | |
color= 'red', | |
opacity= 0.9 | |
) | |
), | |
] | |
plot_layout = go.Layout( | |
yaxis= {'title': "Frequency"}, | |
xaxis= {'title': "Recency"}, | |
title='Segments' | |
) | |
fig = go.Figure(data=plot_data, layout=plot_layout) | |
pyoff.iplot(fig) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It may be easier to use this code to replace all the code above:
`import seaborn as sns
RFM_pairplot = sns.pairplot(data=tx_user, vars=['Recency','Frequency','Revenue'], hue='Segment', plot_kws={"s": 20}, diag_kws={'bw': 0.1})
set diag_kws to avoid error`