Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5d59dba

Browse files
committed
new
1 parent012df3e commit5d59dba

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1+
importsys
2+
importos
13
importpandasaspd
2-
fromdatapreprocimportpreprocess_data
3-
frommodel_trainingimporttrain_model
4-
frommodelevelutionimportevaluate_model
4+
fromsrc.model_evaluationimportevaluate_model
5+
fromsrc.data_preprocessingimportpreprocess_data
6+
fromsrc.model_trainingimporttrain_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+
exceptFileNotFoundError:
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)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# model_evaluation.py
2+
3+
fromsklearn.metricsimportaccuracy_score,precision_score,recall_score,f1_score,confusion_matrix,roc_curve,roc_auc_score
4+
5+
defevaluate_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)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
fromsklearn.ensembleimportRandomForestClassifier
3+
4+
deftrain_model(X_train,y_train):
5+
rf_model=RandomForestClassifier(random_state=42)
6+
rf_model.fit(X_train,y_train)
7+
returnrf_model

‎Random_Forest_project/src/modelevelution.py

Whitespace-only changes.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp