Commit 90d01863 authored by leswing's avatar leswing
Browse files

Fix unittests by defaulting n_classes=2

parent c9687ca5
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ from sklearn.metrics import precision_score
from scipy.stats import pearsonr


def to_one_hot(y, axis=-1):
def to_one_hot(y, axis=-1, n_classes=2):
  """Transforms label vector into one-hot encoding.

  Turns y into vector of shape [n_samples, 2] (assuming binary labels).
@@ -23,7 +23,6 @@ def to_one_hot(y, axis=-1):
    A vector of shape [n_samples, 1]
  """
  n_samples = np.shape(y)[0]
  n_classes = np.max(y, axis=axis)
  y_hot = np.zeros((n_samples, n_classes))
  y_hot[np.arange(n_samples), y.astype(np.int64)] = 1
  return y_hot
+0 −13
Original line number Diff line number Diff line
@@ -458,16 +458,3 @@ class MultiTaskTensorGraph(TensorGraph):
    if self.features is not None:
      feed_dict[self.features[0].out_tensor] = X_b
    return feed_dict

  def predict_on_batch(self, X, tf_initialized=False):
    # sample x task
    # Class is implied by the value of task [0,1]
    prediction = super(MultiTaskTensorGraph, self).predict_on_batch(X)
    prediction = np.transpose(from_one_hot(prediction, axis=2))
    return prediction

  def predict_proba_on_batch(self, X, tf_initialized=False):
    prediction = super(MultiTaskTensorGraph, self).predict_on_batch(X)
    # sample x task x class
    prediction1 = np.transpose(prediction, axes=[1, 0, 2])
    return prediction1
+1 −1
Original line number Diff line number Diff line
@@ -431,7 +431,7 @@ class TestOverfit(test_util.TensorFlowTestCase):
    np.random.seed(123)
    ids = np.arange(n_samples)
    X = np.random.randint(2, size=(n_samples, n_features))
    y = np.zeros((n_samples, n_tasks))
    y = np.ones((n_samples, n_tasks))
    w = np.ones((n_samples, n_tasks))
    dataset = dc.data.NumpyDataset(X, y, w, ids)
    IRV_transformer = dc.trans.IRVTransformer(5, n_tasks, dataset)