Skip to content

Commit 5d59dba

Browse files
committed
new
1 parent 012df3e commit 5d59dba

10 files changed

+51
-5
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Random_Forest_project/src/kuchbhi.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1+
import sys
2+
import os
13
import pandas as pd
2-
from datapreproc import preprocess_data
3-
from model_training import train_model
4-
from modelevelution import evaluate_model
4+
from src.model_evaluation import evaluate_model
5+
from src.data_preprocessing import preprocess_data
6+
from src.model_training import train_model
57

8+
# Add the parent directory of 'src' to the Python path
9+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
610

7-
data = pd.read_csv('Churn_Modelling.csv')
11+
# Specify the path to the CSV file
12+
csv_file_path = os.path.join(os.path.dirname(__file__), '..', 'Churn_Modelling.csv')
813

14+
# Load the data
15+
try:
16+
data = pd.read_csv(csv_file_path)
17+
except FileNotFoundError:
18+
print(f"The file {csv_file_path} was not found.")
19+
exit()
20+
21+
# Preprocess the data
922
X_train, X_test, y_train, y_test = preprocess_data(data)
1023

24+
# Train the model
1125
model = train_model(X_train, y_train)
1226

13-
evaluate_model(model, X_test, y_test)
27+
# Evaluate the model
28+
evaluate_model(model, X_test, y_test)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# model_evaluation.py
2+
3+
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, confusion_matrix, roc_curve, roc_auc_score
4+
5+
def evaluate_model(model, X_test, y_test):
6+
y_pred = model.predict(X_test)
7+
accuracy = accuracy_score(y_test, y_pred)
8+
precision = precision_score(y_test, y_pred)
9+
recall = recall_score(y_test, y_pred)
10+
f1 = f1_score(y_test, y_pred)
11+
print("Accuracy:", accuracy)
12+
print("Precision:", precision)
13+
print("Recall:", recall)
14+
print("F1-score:", f1)
15+
16+
# Confusion matrix
17+
cm = confusion_matrix(y_test, y_pred)
18+
print("Confusion Matrix:\n", cm)
19+
20+
# ROC and AUC
21+
y_pred_proba = model.predict_proba(X_test)
22+
fpr, tpr, thresholds = roc_curve(y_test, y_pred_proba[:, 1])
23+
auc = roc_auc_score(y_test, y_pred_proba[:, 1])
24+
print("AUC:", auc)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
from sklearn.ensemble import RandomForestClassifier
3+
4+
def train_model(X_train, y_train):
5+
rf_model = RandomForestClassifier(random_state=42)
6+
rf_model.fit(X_train, y_train)
7+
return rf_model

Random_Forest_project/src/modelevelution.py

Whitespace-only changes.

0 commit comments

Comments
 (0)