Ejemplo n.º 1
0
def test_normalize_3d_regression():
    """Tests 3d regression normalization."""
    y = np.random.rand(10, 5, 1)
    y_expected = np.squeeze(y)
    y_out = normalize_prediction_shape(y, mode="regression", n_tasks=5)
    assert y_out.shape == (10, 5)
    assert np.array_equal(y_expected, y_out)
Ejemplo n.º 2
0
def test_normalize_1d_regression():
    """Tests 1d regression normalization."""
    y = np.random.rand(10)
    y_expected = y[:, np.newaxis]
    y_out = normalize_prediction_shape(y, mode="regression", n_tasks=1)
    assert y_out.shape == (10, 1)
    assert np.array_equal(y_expected, y_out)
Ejemplo n.º 3
0
def test_normalize_1d_classification_multiclass_explicit_nclasses():
  """Tests 1d classification normalization."""
  y = np.random.randint(5, size=(10,))
  y_expected = np.expand_dims(to_one_hot(y, n_classes=10), 1)
  y_out = normalize_prediction_shape(
      y, mode="classification", n_classes=10, n_tasks=1)
  assert y_out.shape == (10, 1, 10)
  assert np.array_equal(y_expected, y_out)
Ejemplo n.º 4
0
def test_normalize_1d_classification_binary():
  """Tests 1d classification normalization."""
  y = np.array([0, 0, 1, 0, 1, 1, 0])
  expected = np.array([[[1., 0.]], [[1., 0.]], [[0., 1.]], [[1., 0.]],
                       [[0., 1.]], [[0., 1.]], [[1., 0.]]])
  y_out = normalize_prediction_shape(
      y, mode="classification", n_tasks=1, n_classes=2)
  assert y_out.shape == (7, 1, 2)
  assert np.array_equal(expected, y_out)
Ejemplo n.º 5
0
def test_normalize_2d_classification_binary():
  """Tests 2d classification normalization."""
  # Of shape (N, n_classes)
  y = np.random.randint(2, size=(10, 1))
  y_expected = np.expand_dims(dc.metrics.to_one_hot(np.squeeze(y)), 1)
  y_out = normalize_prediction_shape(
      y, mode="classification", n_tasks=1, n_classes=2)
  assert y_out.shape == (10, 1, 2)
  assert np.array_equal(y_expected, y_out)