Data Science
Data Science
BSc CS
Data Science
Index
Sr Page
Aim Date Signature
No. No.
Introduction to Excel
Perform conditional formatting on
a dataset using various criteria.
Create a pivot table to analyze and
summarize data.
1 Use VLOOKUP function to retrieve 13/01/2025 03
information from a different
worksheet or table.
Perform what-if analysis using
Goal Seek to determine input
values for desired output.
Data Frames and Basic Data Pre-
processing
Read data from CSV and JSON
files into a data frame.
Perform basic data pre-processing
2 20/01/2025 07
tasks such as handling missing
values and outliers.
Manipulate and transform data
using functions like filtering,
sorting, and grouping.
Feature Scaling and Dummification
Apply feature-scaling techniques
like standardization and
normalization to numerical
3 27/01/2025 16
features.
Perform feature dummification to
convert categorical variables into
numerical representations.
Hypothesis Testing
Formulate null and alternative
hypothesis for a given problem.
Conduct a hypothesis test using
4 appropriate statistical tests (e.g., t- 03/02/2025 22
test, chi-square test).
Interpret the results and draw
conclusions based on the test
outcomes.
ANOVA (Analysis of Variance)
5 10/02/2025 25
1
[Link] CS
2
[Link] CS
Practical No.1
Aim: Introduction to Excel
Perform conditional formatting on a dataset using various criteria.
Create a pivot table to analyze and summarize data.
Use VLOOKUP function to retrieve information from a different
worksheet or table.
Perform what-if analysis using Goal Seek to determine input values for
desired output.
Theory:
The VLOOKUP function is one of the most widely used tools in Excel
for looking up and retrieving data from a table.
Goal Seek is a part of what-if analysis which allows you to adjust a
variable to achieve a desired outcome without manually testing values.
Input (A):
We perform conditional formatting on the “Profit” column to highlight cells
with a profit greater than 250 using following steps:
Step 1: Select the “Profit” column (Column C).
Step 2: Go to the “Home” tab on the ribbon.
Step 3: Click on “Conditional Formatting” in the toolbar.
Step 4: Choose “Highlight Cells Rules” and then “Greater Than”.
Step 5: Enter the threshold value as 250.
Step 6: Customize the formatting options (e.g., choose a fill color).
Step 7: Click “OK” to apply the rule.
3
[Link] CS
Output (A):
Input (B):
Following are the steps to create a pivot table to analyze total sales by category.
Step 1: Select the entire dataset including headers.
Step 2: Go to the “Insert” tab on the ribbon.
Step 3: Click on “PivotTable”.
Step 4: Choose where you want to place the PivotTable (e.g., new worksheet).
Step 5: Drag “Category” to the Rows area.
Step 6: Drag “Sales” to the Values area, choosing the sum function.
4
[Link] CS
Output (B):
Input (C):
Use the VLOOKUP function to retrieve the category of “Product M” from a
separate worksheet named “Product Table” using following steps:
Step 1: Assuming your “Product Table” is in a different worksheet.
Step 2: In a cell in your main dataset, enter the formula:
=VLOOKUP("M", 'Product Table'!A:B, 2, FALSE)
Output (C):
5
[Link] CS
Input (D):
Use Goal Seek to find the required sales for “Product P” to achieve a profit of
1000 using the following steps.
Step 1: Identify the cell containing the formula for “Profit” for “Product P”
(let's assume it's in cell E17).
Step 2: Go to the “Data” tab on the ribbon.
Step 3: Click on “What-If Analysis” and select “Goal Seek”.
Step 4: Set “Set cell: to the profit cell (E17), “To value” to 1000, and “By
changing cell” to the sales cell (C17).
Step 5: Click “OK” to let Excel determine the required sales.
Output (D):
6
[Link] CS
Practical No.2
Aim: Data Frames and Basic Data Pre-processing
Read data from CSV and JSON files into a data frame.
Perform basic data pre-processing tasks such as handling missing values
and outliers.
Manipulate and transform data using functions like filtering, sorting, and
grouping.
Theory:
A data frame is a two-dimensional labeled data structure with columns of
potentially different types.
Data Pre-processing refers to the cleaning, transforming, and integrating
of data in order to make it ready for analysis.
Input (A):
import numpy as np
import [Link] as plt
import pandas as pd
ds = pd.read_csv('/content/[Link]')
print("Data Head:\n",[Link]())
print("Data Describe:\n",[Link]())
X = [Link][:, :-1].values
Y = [Link][:, 3].values
print("\nInput",X)
print("\nOutput",Y)
7
[Link] CS
Output (A):
Input (B):
# handling missing values
from [Link] import SimpleImputer
# Use 'most_frequent' for non-numeric colums
imputer = SimpleImputer(missing_values = [Link], strategy = 'most_frequent')
imputer = [Link](X[:, 1:3])
X[:, 1:3] = [Link](X[:, 1:3])
print("\n New Input with Most Frequent value for NaN:",X)
8
[Link] CS
Output (B):
Input (C):
# Outliers
import sklearn
from [Link] import load_diabetes
import pandas as pd
import [Link] as plt
db = load_diabetes()
column_name = db.feature_names
df_db = [Link]([Link])
df_db.columns = column_name
df_db.head()
Output (C):
9
[Link] CS
Input (D):
import seaborn as sns
[Link](x=df_db['bmi'])
import numpy as np
print([Link](df_db['bmi']>0.12))
#sorting
display(df_db)
sorted = df_db.sort_values(by=['age'])
display(sorted)
#filtering rows
a = df_db.query('age>0')
display(a)
#filtering columns
b = df_db.filter(['age','bp'])
display(b)
#grouping data
g = df_db.groupby('age')
[Link]()
10
[Link] CS
Output (D):
11
[Link] CS
12
[Link] CS
13
[Link] CS
14
[Link] CS
15
[Link] CS
Practical No.3
Aim: Feature Scaling and Dummification
Apply feature-scaling techniques like standardization and normalization
to numerical features.
Perform feature dummification to convert categorical variables into
numerical representations.
Theory:
Feature Scaling is a technique to standardize the independent features
present in the data.
Normalization is used to transform features to be on a similar scale.
Standardization is the transformation of features by subtracting from
mean and dividing by standard deviation.
Feature dummification is the process of transforming the variables into a
numerical representation.
Input (A):
from [Link] import Normalizer
import pandas as pd
url = '/content/[Link]'
df = pd.read_csv(url,delimiter=",")
scalar = Normalizer()
scaled_data = scalar.fit_transform(df)
scaled_df = [Link](scaled_data, columns=[Link])
print(scaled_df.head())
16
[Link] CS
Output (A):
Input (B):
from [Link] import StandardScaler
scaler = StandardScaler()
scaled_data = scalar.fit_transform(df)
scaled_df = [Link](scaled_data, columns=[Link])
print(scaled_df.head())
Output (B):
Input (C):
# creating dataset
import pandas as pd
data = [Link]({
'Language':['VN','ENG','DE','DE','VN','ENG','VN','DE'],
'Density':['HIGH','MEDIUM','LOW','MEDIUM','MEDIUM','HIGH','LOW','HIGH'],
'Ethnic Group':['Kinh','Dao','Kinh','Kinh','Kinh','Kinh','Hmong','Kinh'],
'Target':[12,5,3,6,9,10,6,8]
})
17
[Link] CS
print(data)
Output (C):
Input (D):
language_data = pd.get_dummies([Link])
print(language_data)
Output (D):
Input (E):
language_data = pd.get_dummies([Link])
new_data = [Link](['Language'],axis=1)
new_data = [Link]((new_data,language_data),axis=1)
print(new_data)
18
[Link] CS
Output (E):
Input (F):
density_map = {
'LOW' : 1,
'MEDIUM' : 2,
'HIGH' : 3
}
density_data = data['Density'].map(density_map)
print(new_data)
Output (F):
Input (G):
new_data = [Link]()
new_data['Density'] = density_data
print(new_data)
19
[Link] CS
Output (G):
Input (H):
print([Link](['Density']).\
agg({'Target' : 'mean'}))
Output (H):
Input (I):
density_map = [Link](['Density']).\
agg({'Target' : 'mean'}).to_dict()['Target']
new_data = [Link]()
new_data['Density'] = new_data['Density'].map(density_map)
print(new_data)
20
[Link] CS
Output (I):
Input (J):
density_type_count = \
[Link](['Density']).size().to_dict()
print(density_type_count)
Output (J):
21
[Link] CS
Practical No.4
Aim: Hypothesis Testing
Formulate null and alternative hypothesis for a given problem.
Conduct a hypothesis test using appropriate statistical tests (e.g., t-test,
chi-square test).
Interpret the results and draw conclusions based on the test outcomes.
Theory:
Hypothesis testing is a fundamental statistical method employed in
various fields, including data science, machine learning, and statistics,
to make informed decisions based on empirical evidence.
hypothesis testing is a systematic approach that allows researchers to
assess the validity of a statistical claim about an unknown population
parameter.
Input:
import numpy as np
from scipy import stats
import [Link] as plt
[Link](42)
sample1 = [Link](loc=10,scale=2,size=30)
sample2 = [Link](loc=10,scale=2,size=30)
alpha = 0.05
print("Result of two-sample t-test")
print(f"t-statistic: {t_statistic}")
print(f"p-value: {p_value}")
22
[Link] CS
[Link](figsize=(10,6))
[Link](sample1,alpha=0.5,label='sample 1',color='blue')
[Link](sample2,alpha=0.5,label='sample 2',color='orange')
[Link]([Link](sample1),color='blue',linestyle='dashed',linewidth=2)
[Link]([Link](sample2),color='orange',linestyle='dashed',linewidth=2)
[Link]('Distributions of Sample1 and Sample2')
[Link]('Value')
[Link]('Frequency')
[Link]()
[Link](11,5,f'T-statistics:{t_statistic:2f}',ha='center',color='black',background='white')
[Link]()
23
[Link] CS
else:
print("Conclusion: Fail to reject null.")
print("Interpretation: There is not enough evidence to claim a significant difference between
the mean.")
Output:
24
[Link] CS
Practical No.5
Aim: ANOVA (Analysis of Variance)
Perform one-way ANOVA to compare means across multiple groups.
Conduct post-hoc tests to identify significant differences between group
means.
Theory:
Analysis of Variance is a parametric statistical technique which checks
the impact of various factors by comparing groups (samples) based on
their respective.
One-way ANOVA is the most basic form of ANOVA and is used when
there is only one independent variable with more than two levels or
groups.
Input:
import [Link] as stats
from [Link] import pairwise_tukeyhsd
# Sample data(replace this with your actual data)
group1 = [23,25,29,34,30]
group2 = [19,20,22,25,24]
group3 = [15,18,20,21,47]
group4 = [28,24,26,30,29]
# combine all data into a single array
all_data = group1 + group2 + group3 + group4
#create corresponding group labels
group_labels = ['Group1']*len(group1) + ['Group2']*len(group2) + ['Group3']*len(group3) +
['Group4']*len(group4)
#perform one-way ANOVA
f_statistic, p_value = stats.f_oneway(group1,group2,group3,group4)
#print ANOVA results
25
[Link] CS
print("One-way ANOVA:")
print(f"F-statistic: ",f_statistic)
print(f"P-value: ",p_value)
#perform Tukey-Kramer post-hoc test
tukey_result = pairwise_tukeyhsd(all_data,group_labels)
#print Tukey-Kramer result
print("\nTukey-Kramer Post-hoc test:")
print(tukey_result)
Output:
26
[Link] CS
Practical No.6
Aim: Regression and its Types
Implement simple linear regression using a dataset.
Explore and interpret the regression model coefficients and goodness-of-
fit measures.
Extend the analysis to multiple linear regression and assess the impact of
additional predictors.
Theory:
Regression is a fundamental concept in machine learning used to model
relationships between dependent and independent variables.
Linear Regression is a linear approach for modeling the relationship
between the criterion or the scalar response and the multiple predictors or
explanatory variables.
Linear regression focuses on the conditional probability distribution of
the response given the values of the predictors.
Input (A):
import numpy as np
import pandas as pd
from [Link] import fetch_california_housing
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from [Link] import mean_squared_error, r2_score
housing = fetch_california_housing()
housing_df = [Link](data=[Link], columns=housing.feature_names)
print(housing_df)
housing_df['PRICE'] = [Link]
27
[Link] CS
Output (A):
Input (B):
x = housing_df[['AveRooms']]
y = housing_df[['PRICE']]
model = LinearRegression()
[Link](x_train,y_train)
y_pred = [Link](X_test)
mse = mean_squared_error(y_test,y_pred)
28
[Link] CS
r2 = r2_score(y_test,y_pred)
Output (B):
Input (C):
x = housing_df.drop('PRICE', axis=1)
y = housing_df['PRICE']
x_train,X_test,y_train,y_test = train_test_split(x,y,test_size=0.2,random_state=42)
model = LinearRegression()
[Link](x_train,y_train)
y_pred = [Link](X_test)
mse = mean_squared_error(y_test,y_pred)
r2 = r2_score(y_test,y_pred)
29
[Link] CS
print("Coefficients, model.coef_")
Output (C):
30
[Link] CS
Practical No.7
Aim: Logistic Regression and Decision Tree
Build a logistic regression model to predict a binary outcome.
Evaluate the model's performance using classification metrics (e.g.,
accuracy, precision, recall).
Construct a decision tree model and interpret the decision rules for
classification.
Theory:
Logistic regression is a fundamental statistical method used in data
science for binary classification tasks. It models the probability that a
given input belongs to a particular category.
Decision trees are a versatile and powerful tool in data science, valued for
their simplicity and effectiveness in a wide range of applications.
Input (A):
import numpy as np
import pandas as pd
from [Link] import load_iris
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from [Link] import DecisionTreeClassifier
from [Link] import accuracy_score, precision_score,
recall_score,classification_report
31
[Link] CS
X=binary_df.drop('target',axis=1)
y=binary_df['target']
# Splitting the data into training and testing sets
X_train,X_test,y_train,y_test= train_test_split(X,y,test_size=0.2,random_state=42)
# Logistic Regression model
logistic_model = LogisticRegression()
logistic_model.fit(X_train,y_train)
# Predictions
y_pred_logistic= logistic= logistic_model.predict(X_test)
# Evaluate logistic regression model
print("Logistic Regresssion Metrics:")
print("Accuracy:",accuracy_score(y_test,y_pred_logistic))
print("Precision:",precision_score(y_test,y_pred_logistic))
print("Recall:",recall_score(y_test,y_pred_logistic))
print("\nClassfication Report:")
print(classification_report(y_test,y_pred_logistic))
Output (A):
32
[Link] CS
Input (B):
# Decision Tree model
decision_tree_model =DecisionTreeClassifier()
decision_tree_model.fit(X_train,y_train)
#Predictions
y_pred_tree = decision_tree_model.predict(X_test)
#Evaluate decision tree model
print("\nDecision Tree Metrics:")
print("Accuracy:",accuracy_score(y_test,y_pred_tree))
print("Precision:",precision_score(y_test,y_pred_tree))
print("Recall:",recall_score(y_test,y_pred_tree))
print("\nClassfication Report:")
print(classification_report(y_test,y_pred_tree))
Output (B):
33
[Link] CS
Practical No.8
Aim: K-Means Clustering
Apply the K-Means algorithm to group similar data points into
clusters.
Determine the optimal number of clusters using elbow method
or silhouette analysis.
Visualize the clustering results and analyze the cluster
characteristics.
Theory:
K-means clustering is a technique used to organize data into groups based
on their similarity.
It is a centroid-based algorithm, where each cluster is associated with a
centroid. The main aim of this algorithm is to minimize the sum of
distances between the data point and their corresponding clusters.
Input (A):
import numpy as np
import pandas as pd
import [Link] as plt
from [Link] import ListedColormap
%matplotlib inline
blobs = pd.read_csv('kmeans_blobs.csv')
colnames = list([Link] [ 1 :-1])
blobs
34
[Link] CS
c=blobs['cluster'].astype('category'),
cmap = customcmap)
ax.set_xlabel(r'x', fontsize=14)
ax.set_ylabel(r'y', fontsize=14)
[Link](fontsize=12)
[Link](fontsize=12)
[Link]()
Output (A):
35
[Link] CS
Input (B):
customcmap = ListedColormap(["crimson", "mediumblue", "darkmagenta"])
Output (B):
36
[Link] CS
Input (C):
import numpy as np
import pandas as pd
k=3
# Assuming 'blobs' is a predefined DataFrame
df = blobs[['x', 'y']]
centroids = initiate_centroids(k, df)
print(centroids)
Output (C):
37
[Link] CS
Input (D):
ef rsserr(a,b):
'''
Calculate the root of sum of squared errors.
a and b are numpy arrays
'''
return [Link]([Link]((a-b)**2))
Output (D):
Input (E):
def centroid_assignation(dset, centroids):
'''
Given a dataframe `dset` and a set of `centroids`, we assign each
data point in `dset` to a centroid.
- dset - pandas dataframe with observations
- centroids - pa das dataframe with centroids
'''
k = [Link][0]
n = [Link][0]
assignation = []
assign_errors = []
38
[Link] CS
Output (E):
39
[Link] CS
Input (F):
fig, ax = [Link](figsize=(8, 6))
[Link]([Link][:,0], [Link][:,1], marker = 'o',
c=df['centroid'].astype('category'),
cmap = customcmap, s=80, alpha=0.5)
[Link]([Link][:,0], [Link][:,1],
marker = 's', s=200, c=[0, 1, 2],
cmap = customcmap)
ax.set_xlabel(r'x', fontsize=14)
ax.set_ylabel(r'y', fontsize=14)
[Link](fontsize=12)
[Link](fontsize=12)
[Link]()
Output (F):
40
[Link] CS
Input (G):
from [Link] import KMeans
from sklearn import metrics
from [Link] import cdist
import numpy as np
import [Link] as plt
41
[Link] CS
Output (G):
Input (H):
distortions = []
inertias = []
mapping1 = {}
mapping2 = {}
K = range(1, 10)
for k in K:
# Building and fitting the model
kmeanModel = KMeans(n_clusters=k).fit(X)
[Link](X)
[Link](sum([Link](cdist(X, kmeanModel.cluster_centers_,
42
[Link] CS
Output (H):
Input (I):
[Link](K, distortions, 'bx-')
[Link]('Values of K')
[Link]('Distortion')
[Link]('The Elbow Method using Distortion')
[Link]()
43
[Link] CS
Output (I):
Input (J):
import [Link] as plt
44
[Link] CS
kmeans.cluster_centers_[:, 1], \
s=100, c='red')
[Link]('K-means clustering (k={})'.format(k))
[Link]('Feature 1')
[Link]('Feature 2')
[Link]()
# Plot the inertia values for each k
[Link](k_range, inertia_values, 'bo-')
[Link]('Elbow Method')
[Link]('Number of clusters (k)')
[Link]('Inertia')
[Link]()
Output (J):
45
[Link] CS
Input (K):
import pandas as pd
df = pd.read_csv('/content/sample_data/[Link]')
# prepare data
types = df['Type 1'].isin(['Grass', 'Fire', 'Water'])
drop_cols = ['Type 1', 'Type 2', 'Generation', 'Legendary', '#']
df = df[types].drop(columns = drop_cols)
46
[Link] CS
[Link]()
Output (K):
Input (L):
from [Link] import KMeans
import numpy as np
# k means
kmeans = KMeans(n_clusters=3, random_state=0)
df['cluster'] = kmeans.fit_predict(df[['Attack', 'Defense']])
# get centroids
centroids = kmeans.cluster_centers_
cen_x = [i[0] for i in centroids]
cen_y = [i[1] for i in centroids]
## add to df
df['cen_x'] = [Link]({0:cen_x[0], 1:cen_x[1], 2:cen_x[2]})
df['cen_y'] = [Link]({0:cen_y[0], 1:cen_y[1], 2:cen_y[2]})
# define and map colors
colors = ['#DF2020', '#81DF20', '#2095DF']
df['c'] = [Link]({0:colors[0], 1:colors[1], 2:colors[2]})
47
[Link] CS
Output (L):
Input (M):
import [Link] as plt
[Link]([Link], [Link], c=df.c, alpha = 0.6, s=10)
Output (M):
48
[Link] CS
Input (N):
[Link]([Link], [Link], c=df.c, s=[Link], alpha = 0.6)
Output (N):
49
[Link] CS
Practical No.9
Aim: Principal Component Analysis (PCA)
Perform PCA on a dataset to reduce dimensionality.
Evaluate the explained variance and select the appropriate number of
principal components.
Visualize the data in the reduced-dimensional space.
Theory:
Principal Component Analysis (PCA) works on the condition that while
the data in a higher dimensional space is mapped to data in a lower
dimension space, the variance of the data in the lower dimensional space
should be maximum.
The main goal of Principal Component Analysis (PCA) is to reduce the
dimensionality of a dataset while preserving the most important patterns
or relationships between the variables without any prior knowledge of the
target variables.
Input (A):
import pandas as pd
Iris=pd.read_csv("/content/[Link]")
X = Iris[['SepalLengthCm','SepalWidthCm','PetalLengthCm','PetalWidthCm']]
y=[Link]
Step 1: Standardization
from [Link] import StandardScaler
X= StandardScaler().fit_transform(X)
import numpy as np
X_mean=[Link](X, axis=0)
#cov_mat = [Link](X)
cov_mat = (X-X_mean).[Link]((X-X_mean))/ ([Link][0]-1)
print('covariance matrix \n%s'%cov_mat)
50
[Link] CS
Output (A):
Input (B):
eig_vals, eig_vecs = [Link](cov_mat)
print('Eigenvectors \n%s' %eig_vecs)
print('\nEigenvalues \n%s' %eig_vals)
u,s,v = [Link](X.T)
u
Output (B):
Input (C):
# Make a list of (eigenvalue, eigenvector) tuples
eig_pairs = [([Link](eig_vals[i]), eig_vecs[:,i]) for i in range(len(eig_vals))]
51
[Link] CS
Output (C):
Input (D):
tot = sum(eig_vals)
var_exp = [(i / tot)*100 for i in sorted(eig_vals, reverse=True)]
cum_var_exp = [Link](var_exp)
cum_var_exp
Output (D):
Input (E):
matrix_w = [Link]((eig_pairs[0][1].reshape(4,1),
eig_pairs[1][1].reshape(4,1)))
52
[Link] CS
Output (E):
Input (F):
Y = [Link](matrix_w)
Output (F):
53
[Link] CS
Input (G):
from [Link] import PCA as sklearnPCA
sklearn_pca = sklearnPCA(n_components=2)
Y_sklearn = sklearn_pca.fit_transform(X)
sklearn_pca.explained_variance_ratio_
with [Link]('seaborn-v0_8-whitegrid'):
[Link](figsize=(6, 4))
for lab, col in zip(('Iris-setosa', 'Iris-versicolor', 'Iris-virginica'),
('blue', 'red', 'green')):
[Link](Y_sklearn[y==lab, 0],
Y_sklearn[y==lab, 1],
label=lab,
c=col)
[Link]('Principal Component 1')
[Link]('Principal Component 2')
[Link](loc='lower center')
plt.tight_layout()
[Link]()
Output (G):
54
[Link] CS
Practical No.10
Aim: Data Visualization and Storytelling
Create meaningful visualizations using data visualization tools.
Combine multiple visualizations to tell a compelling data story.
Present the findings and insights in a clear and concise manner.
Theory:
Data visualization translates complex data sets into visual formats that are
easier for the human brain to understand.
The primary goal of data visualization is to make data more
accessible and easier to interpret allow users to identify patterns, trends,
and outliers quickly.
Data science primarily revolves around extracting meaningful insights
from vast datasets, Data-science storytelling takes the world of data
analysis and adds the storytelling touch to it.
Input (A):
import [Link] as plt
import seaborn as sns
import [Link] as px
import pandas as pd
data = {
'gender': ['Male', 'Female', 'Male', 'Female', 'Male'],
'churn': ['Yes', 'No', 'No', 'Yes', 'Yes'],
'age': [25, 30, 35, 40, 45],
'service_churn': ['A', 'B', 'A', 'B', 'A'], # Assuming you have a column named
'service_churn'
'tenure': [2, 5, 7, 3, 8], # Assuming you have a column named 'tenure'
'feature1': [10, 15, 20, 25, 30], # Assuming you have a column named 'feature1'
'feature2': [5, 8, 12, 18, 22], # Assuming you have a column named 'feature2'
'cluster': ['A', 'B', 'A', 'B', 'A'] # Assuming you have a column named 'cluster'
55
[Link] CS
# Creating DataFrame
df = [Link](data)
[Link](data=df, x='gender', hue='churn')
[Link]()
Output (A):
Input (B):
fig = [Link](df, x='age', color='churn', nbins=20, histnorm='percent')
fig.update_layout(title='Churn Rate by Age Group', xaxis_title='Age', yaxis_title='% of
Customers')
[Link]()
56
[Link] CS
Output (B):
Input (C):
df['churn_numeric'] = df['churn'].map({'No': 0, 'Yes': 1})
service_churn = [Link]('service_churn')['churn_numeric'].mean()
[Link](service_churn,labels=service_churn.index, autopct='%1.1f%%')
[Link]('Churn Rate by service Type')
Output (C):
57
[Link] CS
Input (D):
correlation_matrix = [Link](numeric_only=True)
[Link](correlation_matrix,annot=True,cmap='coolwarm')
[Link]('Correlation Matrix')
Output (D):
Input (E):
fig = [Link](df,x='tenure',y='churn',color='churn')
fig.update_layout(title='Customer Tenure vs. Churn', xaxis_title='Churn(1=Yes,0=No)')
58
[Link] CS
Output (E):
Input (F):
fig = [Link](df,x='feature1',y='feature2',color='cluster')
fig.update_layout(title="Customer Segmentation")
Output (F):
59