Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
31faa5f
added my code in and folder
IBR-41379 Oct 10, 2023
bb40ab3
Appropriated the name of the existing program according to the repo i…
IBR-41379 Oct 10, 2023
578b159
Rename Simple_Adaline.py to simple_adaline.py
IBR-41379 Oct 10, 2023
0154cd4
Chaged the name of yhe folder according to the convention.
IBR-41379 Oct 10, 2023
c08165b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2023
5f373c1
Update simple_adaline.py
IBR-41379 Oct 10, 2023
b3a7404
Rename Churn_Modelling.csv to churn_modelling.csv
IBR-41379 Oct 10, 2023
d5af854
Update churn_cal.py
IBR-41379 Oct 10, 2023
669cf9d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2023
df219a0
Update simple_adaline.py
IBR-41379 Oct 10, 2023
7dd3fb5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2023
537d850
Update churn_cal.py
IBR-41379 Oct 10, 2023
38a8a0b
Update simple_adaline.py
IBR-41379 Oct 10, 2023
e0f8aa1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2023
52b868f
Made appropriate changes to churn_cal
IBR-41379 Oct 11, 2023
6239124
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 11, 2023
e60546a
Made some changes to pass the test
IBR-41379 Oct 11, 2023
86af749
Made changes to pass the test
IBR-41379 Oct 11, 2023
ceed900
Made changes to the file to pass the ruff test
IBR-41379 Oct 11, 2023
4156be4
Modified file according to requirement
IBR-41379 Oct 11, 2023
03e5235
Update machine_learning/decision_tree_churn/churn_cal.py
IBR-41379 Oct 11, 2023
87e3e8b
Update machine_learning/decision_tree_churn/churn_cal.py
IBR-41379 Oct 11, 2023
632be92
Apply suggestions from code review
cclauss Oct 11, 2023
b62c9b4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 11, 2023
9800d56
Update churn_cal.py
cclauss Oct 11, 2023
94e542d
appropriate changes made to both the files
IBR-41379 Oct 11, 2023
dd0ae6b
Made appropriate changes to churn_cal
IBR-41379 Oct 11, 2023
811fdf2
Made some more appropriate changes
IBR-41379 Oct 11, 2023
266edfe
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 11, 2023
38f492c
made changes for the tests
IBR-41379 Oct 11, 2023
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions machine_learning/decision_tree_churn/churn_cal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from pathlib import Path

import numpy as np
import pandas as pd
from sklearn import model_selection, tree


def calculate_churn_rate(filename: str = "churn_modelling.csv") -> np.ndarray:
"""
Calculate the churn rate of customers using a decision tree classifier.
>>> calculate_churn_rate()
array([0, 0, 0, 0, 1])
"""
churn_md = pd.read_csv(Path(__file__).with_name(filename).absolute())

# Sorting the dependent and independent values
x = churn_md[
[
"CreditScore",
"Age",
"Tenure",
"Balance",
"NumOfProducts",
"HasCrCard",
"IsActiveMember",
"EstimatedSalary",
]
].to_numpy()
y = churn_md["Exited"]

# Splitting the dataset into training and testing data
x_test, x_train, y_test, y_train = model_selection.train_test_split(
x, y, test_size=0.3, random_state=3
)

# Creating the decision tree classifier
decision_tree = tree.DecisionTreeClassifier(criterion="entropy", max_depth=4)
decision_tree.fit(x_train, y_train)

# Predicting the values
pred_tree = decision_tree.predict(x_test)

# Returning the predicted values

return pred_tree[0:5]


if __name__ == "__main__":
from doctest import testmod

testmod()
print(f"{calculate_churn_rate('churn_modelling.csv')=}")
Loading