Pdf&rendition 1
Pdf&rendition 1
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
customers_df = pd.DataFrame(data)
customers_df.head()
# Change income
new_income = row['Income'] * (1 + income_change)
income_value = customer_value(new_income, row['SpendingScore'])
results.append({
'CustomerID': row['CustomerID'],
'BaseValue': base_value,
'IncomeEffect': income_value,
'SpendingEffect': spending_value
})
return pd.DataFrame(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()