-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEDA analysis.py
More file actions
66 lines (57 loc) · 2.17 KB
/
Copy pathEDA analysis.py
File metadata and controls
66 lines (57 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
from sklearn.preprocessing import StandardScaler
from joblib import dump
# Load the customer data from the CSV file on D Drive
customer_data = pd.read_csv('D:/customer_data.csv', index_col='Customer ID')
# Set the aesthetic style of the plots
sns.set_style("whitegrid")
# Get a statistical summary of the numerical columns
print(customer_data.describe())
# Plot the distribution of total spend
plt.figure(figsize=(10, 6))
sns.histplot(customer_data['TotalPrice'], kde=True, bins=30, color='blue')
plt.title('Distribution of Total Spend')
plt.xlabel('Total Spend')
plt.ylabel('Frequency')
plt.show()
# Plot the distribution of total orders
plt.figure(figsize=(10, 6))
sns.histplot(customer_data['TotalOrders'], kde=False, bins=30, color='green')
plt.title('Distribution of Total Orders')
plt.xlabel('Total Orders')
plt.ylabel('Frequency')
plt.show()
# Plot the distribution of days since last purchase
plt.figure(figsize=(10, 6))
sns.histplot(customer_data['DaysSinceLastPurchase'], kde=False, bins=30, color='red')
plt.title('Days Since Last Purchase')
plt.xlabel('Days')
plt.ylabel('Frequency')
plt.show()
# Box plot for total spend
plt.figure(figsize=(10, 6))
sns.boxplot(x=customer_data['TotalPrice'])
plt.title('Box Plot of Total Spend')
plt.show()
# Box plot for total orders
plt.figure(figsize=(10, 6))
sns.boxplot(x=customer_data['TotalOrders'])
plt.title('Box Plot of Total Orders')
plt.show()
# Compute the correlation matrix
corr = customer_data.corr()
# Generate a heatmap
plt.figure(figsize=(10, 8))
sns.heatmap(corr, annot=True, fmt=".2f", cmap="coolwarm")
plt.title('Correlation Matrix of Customer Data')
plt.show()
# Assuming customer_data includes all necessary transformations
customer_data.to_csv('D:/processed_customer_data.csv', index=True, index_label='Customer ID')
# Assume we're scaling TotalPrice, TotalOrders, and DaysSinceLastPurchase
scaler = StandardScaler()
customer_features = customer_data[['TotalPrice', 'TotalOrders', 'DaysSinceLastPurchase']]
scaler.fit(customer_features)
# Save the scaler
dump(scaler, 'D:/customer_data_scaler.joblib')