Example #1
0
def test_unfitted_models():
    """Calling predict before fit should raise exception
	"""
    bnn = BnnBinaryClassifier()
    with pytest.raises(NotFittedError):
        bnn.predict(np.random.randn(10, 3))
        bnn.predict_proba(np.random.randn(10, 3))
        bnn.predict_samples(np.random.randn(10, 3))
        bnn.predict_proba_samples(np.random.randn(10, 3))
    bnn = BnnScalarRegressor()
    with pytest.raises(NotFittedError):
        bnn.predict(np.random.randn(10, 3))
        bnn.predict_samples(np.random.randn(10, 3))
Example #2
0
def test_predictions_classification():
    """Binary classifier only predicts 0s and 1s for labels and values in
	[0,1] for prbabilities. Also checks shapes
	"""
    n, p = 100, 10
    n_test = 50
    n_mc_samples = 15
    #(X_train, y_train), (X_test, y_test) = toy_binary_classification_data(n, p)
    bnn = BnnBinaryClassifier(verbose=0)
    bnn.fit(np.random.randn(n, p), np.random.randint(2, size=n))
    yhat_labels = bnn.predict(np.random.randn(n_test, p))
    assert yhat_labels.shape[0] == n_test
    assert np.sum(yhat_labels == 0) + np.sum(yhat_labels == 1) == n_test
    yhat_proba = bnn.predict_proba(np.random.randn(n_test, p))
    assert np.all([prob >= 0.0 or prob <= 1.0 for prob in yhat_proba])
    yhat_labels_samples = bnn.predict_samples(np.random.randn(n_test, p),
                                              n_mc_samples)
    assert yhat_labels_samples.shape == (n_mc_samples, n_test)
    assert np.all([val in [0, 1] for val in yhat_labels_samples.flat])
    yhat_proba_samples = bnn.predict_proba_samples(np.random.randn(n_test, p),
                                                   n_mc_samples)
    assert yhat_proba_samples.shape == (n_mc_samples, n_test)
    assert np.all(
        [prob >= 0.0 or prob <= 1.0 for prob in yhat_proba_samples.flat])