Browse Source

Merge remote-tracking branch 'origin/main'

main
Taha Mohammadzadeh 1 year ago
parent
commit
d73954040d
2 changed files with 13 additions and 11 deletions
  1. 3
    1
      evaluation.py
  2. 10
    10
      main.py

+ 3
- 1
evaluation.py View File

@@ -66,7 +66,9 @@ class Evaluation:
- results (dict): Dictionary containing evaluation metrics.
"""
# Step 1: Convert predicted probabilities to binary labels
predicted_labels = np.where(mlp_output > 0.5, 1, 0)
mlp_output = mlp_output.cpu()
all_targets = all_targets.cpu()
predicted_labels = np.where(mlp_output.cpu() > 0.5, 1, 0)
predicted_labels = predicted_labels.reshape(-1)
all_predictions = predicted_labels


+ 10
- 10
main.py View File

@@ -42,7 +42,8 @@ def train_DeepDRA(x_cell_train, x_cell_test, x_drug_train, x_drug_test, y_train,


model = DeepDRA(cell_sizes, drug_sizes, ae_latent_dim, ae_latent_dim)
model.to(device)
model= model.to(device)

# Step 3: Convert your training data to PyTorch tensors
x_cell_train_tensor = torch.Tensor(x_cell_train.values)
x_drug_train_tensor = torch.Tensor(x_drug_train.values)
@@ -51,9 +52,7 @@ def train_DeepDRA(x_cell_train, x_cell_test, x_drug_train, x_drug_test, y_train,
y_train_tensor = torch.Tensor(y_train)
y_train_tensor = y_train_tensor.unsqueeze(1)

x_cell_train_tensor.to(device)
x_drug_train_tensor.to(device)
y_train_tensor.to(device)

# Compute class weights
classes = [0, 1] # Assuming binary classification
class_weights = torch.tensor(compute_class_weight(class_weight='balanced', classes=classes, y=y_train),
@@ -65,10 +64,10 @@ def train_DeepDRA(x_cell_train, x_cell_test, x_drug_train, x_drug_test, y_train,
random_state=RANDOM_SEED,
shuffle=True)

# Step 4: Create a TensorDataset with the input features and target labels
train_dataset = TensorDataset(x_cell_train_tensor, x_drug_train_tensor, y_train_tensor)
val_dataset = TensorDataset(x_cell_val_tensor, x_drug_val_tensor, y_val_tensor)

# Step 4: Create a TensorDataset with the input features and target labels
train_dataset = TensorDataset(x_cell_train_tensor.to(device), x_drug_train_tensor.to(device), y_train_tensor.to(device))
val_dataset = TensorDataset(x_cell_val_tensor.to(device), x_drug_val_tensor.to(device), y_val_tensor.to(device))
# Step 5: Create the train_loader
train_loader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True)
val_loader = DataLoader(val_dataset, batch_size=batch_size, shuffle=True)
@@ -85,11 +84,11 @@ def train_DeepDRA(x_cell_train, x_cell_test, x_drug_train, x_drug_test, y_train,
# Step 9: Convert your test data to PyTorch tensors
x_cell_test_tensor = torch.Tensor(x_cell_test.values)
x_drug_test_tensor = torch.Tensor(x_drug_test.values)
y_test_tensor = torch.Tensor(y_test)
y_test_tensor = torch.Tensor(y_test).to(device)

# normalize data
x_cell_test_tensor = torch.nn.functional.normalize(x_cell_test_tensor, dim=0)
x_drug_test_tensor = torch.nn.functional.normalize(x_drug_test_tensor, dim=0)
x_cell_test_tensor = torch.nn.functional.normalize(x_cell_test_tensor, dim=0).to(device)
x_drug_test_tensor = torch.nn.functional.normalize(x_drug_test_tensor, dim=0).to(device)

# Step 10: Create a TensorDataset with the input features and target labels for testing
test_dataset = TensorDataset(x_cell_test_tensor, x_drug_test_tensor, y_test_tensor)
@@ -156,6 +155,7 @@ def run(k, is_test=False ):
- history (dict): Dictionary containing evaluation metrics for each run.
"""
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print(device)
# Step 1: Initialize a dictionary to store evaluation metrics
history = {'AUC': [], 'AUPRC': [], "Accuracy": [], "Precision": [], "Recall": [], "F1 score": []}


Loading…
Cancel
Save