Browse Source

Merge remote-tracking branch 'origin/main'

main
Taha Mohammadzadeh 11 months 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

- results (dict): Dictionary containing evaluation metrics. - results (dict): Dictionary containing evaluation metrics.
""" """
# Step 1: Convert predicted probabilities to binary labels # 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) predicted_labels = predicted_labels.reshape(-1)
all_predictions = predicted_labels all_predictions = predicted_labels



+ 10
- 10
main.py View File





model = DeepDRA(cell_sizes, drug_sizes, ae_latent_dim, ae_latent_dim) 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 # Step 3: Convert your training data to PyTorch tensors
x_cell_train_tensor = torch.Tensor(x_cell_train.values) x_cell_train_tensor = torch.Tensor(x_cell_train.values)
x_drug_train_tensor = torch.Tensor(x_drug_train.values) x_drug_train_tensor = torch.Tensor(x_drug_train.values)
y_train_tensor = torch.Tensor(y_train) y_train_tensor = torch.Tensor(y_train)
y_train_tensor = y_train_tensor.unsqueeze(1) 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 # Compute class weights
classes = [0, 1] # Assuming binary classification classes = [0, 1] # Assuming binary classification
class_weights = torch.tensor(compute_class_weight(class_weight='balanced', classes=classes, y=y_train), class_weights = torch.tensor(compute_class_weight(class_weight='balanced', classes=classes, y=y_train),
random_state=RANDOM_SEED, random_state=RANDOM_SEED,
shuffle=True) 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 # Step 5: Create the train_loader
train_loader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True) train_loader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True)
val_loader = DataLoader(val_dataset, batch_size=batch_size, shuffle=True) val_loader = DataLoader(val_dataset, batch_size=batch_size, shuffle=True)
# Step 9: Convert your test data to PyTorch tensors # Step 9: Convert your test data to PyTorch tensors
x_cell_test_tensor = torch.Tensor(x_cell_test.values) x_cell_test_tensor = torch.Tensor(x_cell_test.values)
x_drug_test_tensor = torch.Tensor(x_drug_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 # 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 # 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) test_dataset = TensorDataset(x_cell_test_tensor, x_drug_test_tensor, y_test_tensor)
- history (dict): Dictionary containing evaluation metrics for each run. - history (dict): Dictionary containing evaluation metrics for each run.
""" """
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print(device)
# Step 1: Initialize a dictionary to store evaluation metrics # Step 1: Initialize a dictionary to store evaluation metrics
history = {'AUC': [], 'AUPRC': [], "Accuracy": [], "Precision": [], "Recall": [], "F1 score": []} history = {'AUC': [], 'AUPRC': [], "Accuracy": [], "Precision": [], "Recall": [], "F1 score": []}



Loading…
Cancel
Save