0% found this document useful (0 votes)
13 views3 pages

Pdf&rendition 1

The document outlines a process for conducting sensitivity analysis on customer data using Python in Google Colab. It includes steps for importing libraries, creating sample customer data, defining a function to calculate customer value, performing sensitivity analysis on income and spending score changes, and visualizing the results. The final output is a line plot showing the effects of income and spending changes on customer value.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Pdf&rendition 1

The document outlines a process for conducting sensitivity analysis on customer data using Python in Google Colab. It includes steps for importing libraries, creating sample customer data, defining a function to calculate customer value, performing sensitivity analysis on income and spending score changes, and visualizing the results. The final output is a line plot showing the effects of income and spending changes on customer value.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CUSTOMER DATA USING SENSITIVITY ANALYSIS IN COLAB

Step 1: Import Necessary Libraries

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

Step 2: Create Sample Customer Data

# Create sample customer data


data = {
'CustomerID': range(1, 101),
'Age': np.random.randint(18, 70, size=100),
'Income': np.random.randint(30000, 100000, size=100),
'SpendingScore': np.random.randint(1, 100, size=100)
}

customers_df = pd.DataFrame(data)
customers_df.head()

Step 3: Define a Function for Sensitivity Analysis

def customer_value(income, spending_score):


return (income * 0.5) + (spending_score * 0.5)

# Calculate Customer Value


customers_df['CustomerValue'] = customers_df.apply(lambda x: customer_value(x['Income'], x['SpendingScore']),
axis=1)
CUSTOMER DATA USING SENSITIVITY ANALYSIS IN COLAB
Step 4: Perform Sensitivity Analysis

# Function to perform sensitivity analysis


def sensitivity_analysis(df, income_change, spending_change):
results = []

for index, row in df.iterrows():


base_value = row['CustomerValue']

# Change income
new_income = row['Income'] * (1 + income_change)
income_value = customer_value(new_income, row['SpendingScore'])

# Change spending score


new_spending = row['SpendingScore'] * (1 + spending_change)
spending_value = customer_value(row['Income'], new_spending)

results.append({
'CustomerID': row['CustomerID'],
'BaseValue': base_value,
'IncomeEffect': income_value,
'SpendingEffect': spending_value
})

return pd.DataFrame(results)

# Perform analysis with 10% increase in income and spending score


sensitivity_df = sensitivity_analysis(customers_df, 0.1, 0.1)
sensitivity_df.head()
CUSTOMER DATA USING SENSITIVITY ANALYSIS IN COLAB
Step 5: Visualize Results

# Visualization
plt.figure(figsize=(12, 6))
sns.lineplot(data=sensitivity_df, x='CustomerID', y='BaseValue', label='Base Value', marker='o')
sns.lineplot(data=sensitivity_df, x='CustomerID', y='IncomeEffect', label='Income Effect', marker='o')
sns.lineplot(data=sensitivity_df, x='CustomerID', y='SpendingEffect', label='Spending Effect', marker='o')
plt.title('Sensitivity Analysis of Customer Value')
plt.xlabel('Customer ID')
plt.ylabel('Customer Value')
plt.legend()
plt.show()

You might also like