-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomer_churn.py
45 lines (33 loc) · 1.34 KB
/
customer_churn.py
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
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 21 11:46:58 2023
@author: Aditya King
"""
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report, confusion_matrix
# Loading the dataset
data = pd.read_csv(r'H:\CODESOFT\Customer Churn Prediction\customer_churn_dataset\Churn_Modelling.csv')
# Excluded non-numeric columns like 'Surname'
numeric_columns = ['CreditScore', 'Age', 'Tenure', 'Balance', 'NumOfProducts', 'HasCrCard', 'IsActiveMember', 'EstimatedSalary']
X = data[numeric_columns]
# Splitting data in target label
y = data['Exited']
# Splitting data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Feature scaling
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
# Building and train of model (Random Forest)
model = RandomForestClassifier()
model.fit(X_train, y_train)
# Predicting
y_pred = model.predict(X_test)
# Evaluating the model
report = classification_report(y_test, y_pred)
conf_matrix = confusion_matrix(y_test, y_pred)
print("Classification Report:\n", report)
print("Confusion Matrix:\n", conf_matrix)