Commit d8575698 authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

Some cleanup and minor-bugfixes on tox21 examples.

parent 8216fd80
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -29,8 +29,6 @@ install:
- conda install -c omnia mdtraj 
- python setup.py install
- conda install -c https://conda.anaconda.org/jjhelmus tensorflow
#- pip install --upgrade --no-deps theano
#- pip install keras
script:
- nosetests -v deepchem --nologcapture
after_success:
+4 −11
Original line number Diff line number Diff line
@@ -29,8 +29,6 @@ def load_bace(mode="regression", transform=True, split="20-80"):
  elif split == "80-20":
    dataset_file = os.path.join(
        current_dir, "../../datasets/rev8020split_desc.csv")
  print("dataset_file")
  print(dataset_file)
  dataset = load_from_disk(dataset_file)
  num_display = 10
  pretty_columns = (
@@ -85,11 +83,6 @@ def load_bace(mode="regression", transform=True, split="20-80"):
  train_samples, valid_samples, test_samples = splitter.train_valid_test_split(
      featurized_samples, train_dir, valid_dir, test_dir,
      reload=reload)
  ######################### DEBUG
  #print("bace_datasets")
  #print("len(train_samples), len(valid_samples), len(test_samples)")
  #print(len(train_samples), len(valid_samples), len(test_samples))
  ######################### DEBUG

  #NOTE THE RENAMING:
  if split == "20-80":
@@ -137,8 +130,8 @@ def load_bace(mode="regression", transform=True, split="20-80"):
      transformer.transform(valid_dataset)
  for transformer in transformers:
      transformer.transform(test_dataset)
  #for transformer in transformers:
  #    transformer.transform(crystal_dataset)
  for transformer in transformers:
      transformer.transform(crystal_dataset)

  #return (bace_tasks, train_dataset, valid_dataset, test_dataset, crystal_dataset, transformers)
  return (bace_tasks, train_dataset, valid_dataset, test_dataset, crystal_dataset, output_transformers)
  return (bace_tasks, train_dataset, valid_dataset, test_dataset,
          crystal_dataset, output_transformers)
+0 −12
Original line number Diff line number Diff line
@@ -143,18 +143,6 @@ class Model(object):
      y_preds.append(y_pred_batch)
    y_pred = np.vstack(y_preds)
  
    ################ DEBUG
    #y_plain = []
    #for (X_batch, y_batch, w_batch, ids_batch) in dataset.iterbatches(batch_size):
    #  y_pred_batch = np.reshape(self.predict_on_batch(X_batch), y_batch.shape)
    #  y_plain.append(y_pred_batch)
    #y_plain_pred = np.vstack(y_plain)
    #y = dataset.get_labels()
    #import sklearn
    #print("sklearn.metrics.r2_score(y, y_plain_pred)")
    #print(sklearn.metrics.r2_score(y, y_plain_pred))
    ################ DEBUG
  
    # The iterbatches does padding with zero-weight examples on the last batch.
    # Remove padded examples.
    n_samples, n_tasks = len(dataset), len(self.tasks)
+2 −29
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ valid_scores = {}

print("Using following tasks")
print(tox21_tasks)
##### CHANGE IF N_TASKS IS CHANGED!

## This is for good debug (to make sure nasty state isn't being passed around)
if os.path.exists(feature_dir):
  shutil.rmtree(feature_dir)
@@ -117,39 +117,12 @@ valid_dataset = Dataset.from_numpy(valid_dir, X_valid, y_valid,
transformers = []

# Fit models
tox21_task_types = {task: "Classification" for task in tox21_tasks}
tox21_task_types = {task: "classification" for task in tox21_tasks}

classification_metric = Metric(metrics.roc_auc_score, np.mean,
                               verbosity=verbosity,
                               mode="classification")

####################### DEBUG
y_train = np.reshape(y_train, (len(y_train), n_tasks))
print("w_valid")
print(w_valid)
for task, _ in enumerate(tox21_tasks):
  print("BASELINE FOR TASK %s" % str(task))
  model = RandomForestClassifier(class_weight="balanced",
                                 n_estimators=500)
  y_train_task = y_train[:, task]
  y_valid_task = y_valid[:, task]
  w_valid_task = w_valid[:, task]
  model.fit(X_train, y_train_task)
  #y_valid_task = metrics.to_one_hot(y_valid_task)
  y_valid_task = y_valid_task[:, np.newaxis]
  y_pred_task = model.predict_proba(X_valid)
  y_pred_task = y_pred_task[:, np.newaxis]
  w_valid_task = w_valid_task[:, np.newaxis]
  print("y_valid_task.shape, y_pred_task.shape, w_valid_task.shape")
  print(y_valid_task.shape, y_pred_task.shape, w_valid_task.shape)
  print("classification_metric.compute_metric(y_valid_task, y_pred_task, w_valid_task)")
  print(classification_metric.compute_metric(y_valid_task, y_pred_task, w_valid_task))
  #print("metrics.roc_auc_score(y_valid_task, y_pred_task)")
  #print(metrics.roc_auc_score(y_valid_task, y_pred_task))
  print("----------------------")
####################### DEBUG


params_dict = { 
    "batch_size": None,
    "data_shape": train_dataset.get_data_shape(),
+0 −13
Original line number Diff line number Diff line
@@ -65,13 +65,8 @@ print("About to featurize Tox21 dataset.")
featurizers = [CircularFingerprint(size=1024)]
tox21_tasks = ['NR-AR', 'NR-AR-LBD', 'NR-AhR', 'NR-Aromatase', 'NR-ER', 'NR-ER-LBD',
               'NR-PPAR-gamma', 'SR-ARE', 'SR-ATAD5', 'SR-HSE', 'SR-MMP', 'SR-p53']
# For debugging purposes
#tox21_tasks = tox21_tasks[0:1]
#tox21_tasks = tox21_tasks[0:2]
all_valid_scores = {}

print("Using following tasks")
print(tox21_tasks)
# This is for good debug (to make sure nasty state isn't being passed around)
if os.path.exists(feature_dir):
  shutil.rmtree(feature_dir)
@@ -86,8 +81,6 @@ featurized_samples = featurizer.featurize(

# Generate datasets
print("About to create datasets")
print("tox21_tasks")
print(tox21_tasks)

# This is for good debug (to make sure nasty state isn't being passed around)
if os.path.exists(full_dir):
@@ -107,11 +100,6 @@ ids_train, ids_valid = ids[:num_train], ids[num_train:]
# Not sure if we need to constantly delete these directories...
if os.path.exists(train_dir):
  shutil.rmtree(train_dir)
print("tox21_tf_models.py")
print("type(y_train)")
print(type(y_train))
print("type(X_train)")
print(type(X_train))
train_dataset = Dataset.from_numpy(train_dir, X_train, y_train,
                                   w_train, ids_train, tox21_tasks)

@@ -131,7 +119,6 @@ classification_metric = Metric(metrics.roc_auc_score, np.mean,
                               mode="classification")
params_dict = { 
    "batch_size": 32,
    #"batch_size": 5120,
    "nb_epoch": 50,
    "data_shape": train_dataset.get_data_shape(),
    "layer_sizes": [1000],