0% found this document useful (0 votes)
0 views

Assignment

The document outlines an assignment consisting of basic Python questions focusing on conditional statements, loops, and functions, as well as tasks related to data manipulation using Pandas. It also includes a scenario for applying supervised and unsupervised machine learning techniques to optimize customer retention for a retail company. The assignment specifies steps for building predictive models, segmenting customers, and analyzing results to derive insights.

Uploaded by

mohitsurwade149
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Assignment

The document outlines an assignment consisting of basic Python questions focusing on conditional statements, loops, and functions, as well as tasks related to data manipulation using Pandas. It also includes a scenario for applying supervised and unsupervised machine learning techniques to optimize customer retention for a retail company. The assignment specifies steps for building predictive models, segmenting customers, and analyzing results to derive insights.

Uploaded by

mohitsurwade149
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment

Basic Python Questions:


Here are five questions on Python's conditional statements, loops, and functions:
1. Conditional Statements:
Write a Python function check number that takes an integer as input and returns:
o "Positive" if the number is greater than zero,
o "Negative" if the number is less than zero,
o "Zero" if the number is zero.
2. Loops:
Write a Python function sum_of_squares that uses a for loop to return the sum of squares
of numbers from 1 to n (inclusive), where n is a positive integer input.
3. Nested Conditionals:
Write a Python function grade_category that takes a score (0–100) and returns:
o "Distinction" if the score is 75 or above,
o "First Class" if the score is between 60 and 74,
o "Second Class" if the score is between 50 and 59,
o "Fail" if the score is below 50.
4. While Loop:
Write a Python function countdown that takes a positive integer n and prints numbers
from n down to 1 using a while loop. When the countdown reaches 1, print "Liftoff!".
5. Function with Conditional and Loop:
Write a Python function find_divisible that takes two integers, start and end, and a divisor
d. The function should return a list of all numbers between start and end that are divisible
by d.
Pandas in Python
DataFrame Creation and Indexing: Create a Pandas Data Frame using the following
dictionary:
Now, write code to:
 Select and display the 'Name' and 'Salary' columns.
 Filter rows where the 'Age' is greater than 25.
2. Handling Missing Data: Given the following DataFrame:

 Write code to fill missing values in column 'A' with the column mean.
 Drop rows where all values are missing.
Scenario Question: Applying Supervised and Unsupervised Machine Learning Techniques
You are working as a data scientist for a retail company that wants to optimize its customer
retention strategy. The company has historical data on customers, including their purchase
behavior and demographic information. Your task is to build machine learning models to:
1. Predict whether a customer will churn (leave) based on their behavior and demographic
features (a supervised learning problem).
2. Segment customers into groups with similar purchasing behaviors (an unsupervised
learning problem) to identify different customer personas for targeted marketing.
Data Description:
 Features for supervised and unsupervised learning:
o CustomerID: Unique identifier for each customer.
o Age: Age of the customer.
o Income: Annual income of the customer.
o Num_Purchases: Number of purchases made by the customer.
o Avg_Purchase_Value: Average value of purchases made.
o Last_Purchase_Days_Ago: Number of days since the last purchase.
o Churn: Target variable indicating whether a customer has churned (1) or not (0)
(only available for supervised learning).
Step 1: Apply Supervised Learning Techniques
Use the following supervised learning algorithms to predict customer churn:
1. Logistic Regression
2. Decision Trees
3. Random Forest
4. Support Vector Machine (SVM)
5. K-Nearest Neighbors (KNN)
Step 2: Apply Unsupervised Learning Techniques
Use the following unsupervised learning techniques to segment customers based on their
purchase behavior:
1. K-Means Clustering
2. Hierarchical Clustering
3. DBSCAN

Step 3: Compare Accuracy for Supervised Learning

For each supervised learning model, compute the accuracy, precision, recall, and F1-score on a
test set. Present the results in the following table:

Step 4: Visualize Unsupervised Learning


After applying the unsupervised learning techniques, plot the customer segments on a 2D graph
(e.g., using PCA or t-SNE for dimensionality reduction). Include the following:

 Cluster centroids for K-Means.


 Dendrogram for Hierarchical Clustering.
 Core and border points for DBSCAN.

Step 5: Provide Insights

 Which supervised learning model performed the best, and why do you think it was
effective for this problem?
 How many customer segments were found using unsupervised learning? Describe the
characteristics of the customer segments (e.g., high-value vs. low-value customers).
 What strategies could the company employ based on the model's predictions and
segmentation results?

You might also like