Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the scripts for downstream tasks #18

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions benchmark_code/downstream_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@
from global_config import RANDOM_SEEDS


def calc_multiclass_classification_metrics(proba_predictions, y_true, n_classes):
# calc weighted roc auc
weighted_roc_auc = 0
weighted_pr_auc = 0
for i in range(n_classes):
result_metrics = calc_binary_classification_metrics(
proba_predictions[:, i], y_true == i
)
pr_auc = result_metrics["pr_auc"]
roc_auc = result_metrics["roc_auc"]
weighted_pr_auc += pr_auc * (y_true == i).sum()
weighted_roc_auc += roc_auc * (y_true == i).sum()
weighted_roc_auc /= len(y_true)
weighted_pr_auc /= len(y_true)
return weighted_pr_auc, weighted_roc_auc


class LoadImputedDataAndLabel(Dataset):
def __init__(self, imputed_data, labels):
self.imputed_data = imputed_data
Expand Down Expand Up @@ -269,11 +286,13 @@ def get_dataloaders(train_X, train_y, val_X, val_y, test_X, test_y, batch_size=1
classification_metrics["roc_auc"],
)
else:
pr_auc, roc_auc = None, None
pr_auc, roc_auc = calc_multiclass_classification_metrics(
proba_predictions, test_y, args.n_classes
)
xgb_wo_pr_auc_collector.append(pr_auc)
xgb_wo_roc_auc_collector.append(roc_auc)

# XGBoost model without imputation
# XGBoost model with imputation
xgb = XGBClassifier()
xgb.fit(
train_X.reshape(-1, n_flatten_features),
Expand All @@ -291,7 +310,9 @@ def get_dataloaders(train_X, train_y, val_X, val_y, test_X, test_y, batch_size=1
classification_metrics["roc_auc"],
)
else:
pr_auc, roc_auc = None, None
pr_auc, roc_auc = calc_multiclass_classification_metrics(
proba_predictions, test_y, args.n_classes
)
xgb_pr_auc_collector.append(pr_auc)
xgb_roc_auc_collector.append(roc_auc)

Expand All @@ -312,7 +333,9 @@ def get_dataloaders(train_X, train_y, val_X, val_y, test_X, test_y, batch_size=1
classification_metrics["roc_auc"],
)
else:
pr_auc, roc_auc = None, None
pr_auc, roc_auc = calc_multiclass_classification_metrics(
proba_predictions, test_y, args.n_classes
)
rnn_pr_auc_collector.append(pr_auc)
rnn_roc_auc_collector.append(roc_auc)

Expand All @@ -339,7 +362,9 @@ def get_dataloaders(train_X, train_y, val_X, val_y, test_X, test_y, batch_size=1
classification_metrics["roc_auc"],
)
else:
pr_auc, roc_auc = None, None
pr_auc, roc_auc = calc_multiclass_classification_metrics(
proba_predictions, test_y, args.n_classes
)
transformer_pr_auc_collector.append(pr_auc)
transformer_roc_auc_collector.append(roc_auc)

Expand Down
Loading