|
|
|
"""silverChairprediction.159 |
|
|
|
Automatically generated by Colab. |
|
|
|
Original file is located at |
|
https://colab.research.google.com/drive/1oUsaV8V9oOXQWEeYS_uQYUu3WuVk21rP |
|
""" |
|
|
|
import warnings |
|
warnings.filterwarnings('ignore') |
|
|
|
import numpy as np |
|
import pandas as pd |
|
import matplotlib.pyplot as plt |
|
import seaborn as sns |
|
|
|
file_path = 'customer_purchase_data.csv' |
|
df = pd.read_csv(file_path) |
|
|
|
df.head() |
|
|
|
df.info() |
|
|
|
df.describe() |
|
|
|
plt.figure(figsize=(10,6)) |
|
sns.histplot(df['Age'], kde=True, bins=30) |
|
plt.title('Distribution of Age') |
|
plt.xlabel('Age') |
|
plt.ylabel('Frequency') |
|
plt.show() |
|
|
|
plt.figure(figsize=(10, 6)) |
|
sns.histplot(df['AnnualIncome'], kde=True, bins=30) |
|
plt.title('Distribution of Annual Income') |
|
plt.xlabel('Annual Income') |
|
plt.ylabel('Frequency') |
|
plt.show |
|
|
|
numeric_df = df.select_dtypes(include=[np.number]) |
|
plt.figure(figsize=(12, 8)) |
|
sns.heatmap(numeric_df.corr(), annot=True, cmap='coolwarm', fmt='.2f') |
|
plt.title('Correlation Heatmap') |
|
plt.show() |
|
|
|
from sklearn.model_selection import train_test_split |
|
from sklearn.ensemble import RandomForestClassifier |
|
from sklearn.metrics import classification_report, confusion_matrix |
|
|
|
X = df.drop('PurchaseStatus', axis=1) |
|
y = df['PurchaseStatus'] |
|
|
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42) |
|
|
|
model = RandomForestClassifier(random_state=42) |
|
model.fit(X_train, y_train) |
|
|
|
y_pred = model.predict(X_test) |
|
|
|
print(confusion_matrix(y_test, y_pred)) |
|
print(classification_report(y_test, y_pred)) |