Case Study (Tele Company) : Churn Analysis
- Churn analysis is the evaluation of a company's customer loss rate
import pandas as pd
url= "https://datascienceschools.github.io/tele_customers.csv"
df = pd.read_csv(url)
df.head()
- who continued their subscriptions -> Churn : No
- who discontinued their subscriptions -> Churn : Yes
df['Churn'].value_counts()
- import matplotlib.pyplot as plt -> for plotting the graph
- import seaborn as sns -> for plotting interactive graph
- from pylab import rcParams -> for customizing Matplotlib plots
- Data to plot
labels = df['Churn'].value_counts(sort = True).index -> Labeling each slice
sizes = df['Churn'].value_counts(sort = True) -> Size of each slice
colors = ["lightblue","pink"] -> Color of each slice
explode = (0.05,0) -> This will explode first slice
- rcParams['figure.figsize'] = 6,6 -> Changing size of figure
- plt.axis('equal') -> Making a square plot with equal axes
- Plot
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=90,)
plt.title('Customer Churn Breakdown')
plt.show()
- Legend
patches, texts = plt.pie(sizes, explode=explode, colors=colors,shadow=True, startangle=90,)
plt.legend(patches, labels, loc="best")
import matplotlib.pyplot as plt
import seaborn as sns
from pylab import rcParams
labels = df['Churn'].value_counts(sort = True).index
sizes = df['Churn'].value_counts(sort = True)
colors = ["lightblue","pink"]
plt.pie(sizes, labels=labels, colors=colors)
plt.title('Customer Churn Breakdown')
plt.show()
- Changing size of figure
import matplotlib.pyplot as plt
import seaborn as sns
from pylab import rcParams
labels = df['Churn'].value_counts(sort = True).index
sizes = df['Churn'].value_counts(sort = True)
colors = ["lightblue","pink"]
rcParams['figure.figsize'] = 8,8
plt.pie(sizes, labels=labels, colors=colors)
plt.title('Customer Churn Breakdown')
plt.show()
- Making a square plot with equal axes
import matplotlib.pyplot as plt
import seaborn as sns
labels = df['Churn'].value_counts(sort = True).index
sizes = df['Churn'].value_counts(sort = True)
colors = ["lightblue","pink"]
plt.pie(sizes, labels=labels, colors=colors)
plt.title('Customer Churn Breakdown')
plt.axis('equal')
plt.show()
- plt.pie -> Add autopct='%1.1f%%'
import matplotlib.pyplot as plt
import seaborn as sns
from pylab import rcParams
labels = df['Churn'].value_counts(sort = True).index
sizes = df['Churn'].value_counts(sort = True)
colors = ["lightblue","pink"]
rcParams['figure.figsize'] = 6,6
plt.pie(sizes, labels=labels, colors=colors, autopct='%1.1f%%')
plt.title('Customer Churn Breakdown')
plt.show()
- explode = (0.1,0)
- plt.pie -> Add explode = explode
import matplotlib.pyplot as plt
import seaborn as sns
from pylab import rcParams
labels = df['Churn'].value_counts(sort = True).index
sizes = df['Churn'].value_counts(sort = True)
colors = ["lightblue","pink"]
explode = (0.1,0)
rcParams['figure.figsize'] = 6,6
plt.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%')
plt.title('Customer Churn Breakdown')
plt.show()
- plt.pie -> Add shadow=True
import matplotlib.pyplot as plt
import seaborn as sns
from pylab import rcParams
labels = df['Churn'].value_counts(sort = True).index
sizes = df['Churn'].value_counts(sort = True)
colors = ["lightblue","pink"]
explode = (0.1,0)
rcParams['figure.figsize'] = 6,6
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%',shadow=True)
plt.title('Customer Churn Breakdown')
plt.show()
- plt.pie -> Add startangle = 90
import matplotlib.pyplot as plt
import seaborn as sns
from pylab import rcParams
labels = df['Churn'].value_counts(sort = True).index
sizes = df['Churn'].value_counts(sort = True)
colors = ["lightblue","pink"]
explode = (0.1,0)
rcParams['figure.figsize'] = 6,6
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=90)
plt.title('Customer Churn Breakdown')
plt.show()
- patches, texts = plt.pie(sizes, explode=explode, colors=colors,shadow=True, startangle=90,)
- plt.legend(patches, labels, loc="best")
import matplotlib.pyplot as plt
import seaborn as sns
from pylab import rcParams
#labels = df['Churn'].value_counts(sort = True).index
sizes = df['Churn'].value_counts(sort = True)
colors = ["lightblue","pink"]
explode = (0.1,0)
rcParams['figure.figsize'] = 6,6
patches, texts = plt.pie(sizes, explode=explode, colors=colors, shadow=True, startangle=90)
plt.legend(patches, labels, loc="best")
plt.title('Customer Churn Breakdown')
plt.show()