Skip to content
Snippets Groups Projects
Commit c3cb7724 authored by Belfiore, Asia's avatar Belfiore, Asia
Browse files

Added F3 score check for performance evaluation

parent 617be477
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
import argparse
import csv
from sklearn.linear_model import SGDClassifier as SGD
from sklearn.metrics import fbeta_score
import numpy as np
from utils import *
......@@ -18,16 +19,33 @@ def main():
next(r) # skip headers
model = SGD(loss="hinge", penalty="l2", max_iter=100)
# Model training
print("Starting Model Training...")
train_data = prepare_train_data('data/training.csv') # extract features from input data
X_train = train_data.loc[:,'sex':'D'] # input features
Y_train = train_data.loc[:,'aki'] # target labels
train_split = len(train_data)*0.8 # split training data into training (80%) and validation (20%) sets
X_train = train_data.loc[:train_split,'sex':'D'] # input features
Y_train = train_data.loc[:train_split,'aki'] # target labels
model.fit(X_train.values, Y_train.values) # train SGD model
print("Model Training Complete.")
X_test = train_data.loc[train_split:,'sex':'D']
Y_test = train_data.loc[train_split:,'aki']
test_pred = model.predict(X_test.values)
f3_score = fbeta_score(Y_test, test_pred, beta=3)
if f3_score < 0.7:
raise Exception(f"Model performance ({f3_score}) is below the required threshold of 0.7.")
else:
print(f"Model performance meets F3 score requirements ({f3_score})")
print("Starting Model Prediction...")
for row in r:
patient = prepare_test_data(row) # format input data for model prediction
y_pred = model.predict(np.array(patient).reshape(1, -1))
aki_pred = to_label(y_pred[0], 'y', 'n') # convert binary prediction to 'y'/'n' labels
w.writerow((aki_pred,))
print("Model Prediction Complete.")
except Exception as e:
print(f"An error occurred while running the prediction: {e}")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment