def test_min_change_greater_than_zero_forward():
    """
    Check that `min_change` is required to be > 0.
    """
    msg = "`min_change` must be greater than zero."
    with pytest.raises(ValueError, match=msg):
        forward(min_change=-0.5, n_features=None)
def test_min_change_fails_on_string_forward():
    """
    Check that forward raises when passed a string
    for `min_change`.
    """
    msg = "`min_change` must be of type int or float."
    with pytest.raises(TypeError, match=msg):
        forward(min_change='-0.75', n_features=None)
Ejemplo n.º 3
0
def test_selection_class_use_of_criterion():
    """Test Criterion through `forward()` and `backward()."""

    msg = "`criterion` must be one of: None, 'aic', 'bic'."
    with pytest.raises(ValueError, match=msg):
        forward(min_change=0.5, criterion='acc')

    with pytest.raises(ValueError, match=msg):
        backward(n_features=0.5, criterion='Santa')
def test_both_non_none_forward():
    """
    Check `forward()` raise when at least one
    of `min_change` or `n_features` are not None.
    """
    # Note: items in backticks (``) will be in alphabetical order.
    msg = "At least one of `min_change` and `n_features` must be None."
    with pytest.raises(TypeError, match=msg):
        forward(min_change=0.5, n_features=0.3)
Ejemplo n.º 5
0
def test_too_few_features():
    """
    Check that there are enough features for
    for selection to be a coherent goal (i.e., >= 2).
    """
    X_train = DEFAULT_SELECTION_PARAMS['X_train']
    X_train = X_train[:, 0:1]
    with pytest.raises(IndexError):
        forward(n_features=1, X_train=X_train)
    with pytest.raises(IndexError):
        backward(n_features=1, X_train=X_train)
Ejemplo n.º 6
0
def test_fsel_verbose_output():
    forward_output = forward(n_features=None, min_change=1, verbose=True)
    assert len(forward_output) >= 1
Ejemplo n.º 7
0
def test_fsel_min_change_output():
    forward_output = forward(n_features=None, min_change=1, criterion=None)
    assert len(forward_output) >= 1
Ejemplo n.º 8
0
def test_fsel_bic_output():
    forward_output = forward(n_features=2, min_change=None, criterion='bic')
    assert len(forward_output) > 0
Ejemplo n.º 9
0
# -----------------------------------------------------------------------------


def test_passing_significant_change():
    """
    Test cases where there is a significant `min_change`
    during backward selection.
    """
    backward(n_features=None, min_change=1, _last_score_punt=True)


# -----------------------------------------------------------------------------
# Outputs: Run the Forward and Backward Selection Algorithms
# -----------------------------------------------------------------------------

forward_output = forward()

# Run using the other parameter option
forward_output += forward(n_features=1, min_change=None)

# Force the backward selection algorithm to
# select the single feature it thinks is most predictive.
# If implemented correctly, `backward()` should be able to
# identify `true_best_features` as predictive.
backward_output = backward(n_features=1)

# Run using the other parameter option
backward_output += backward(min_change=0.0001, n_features=None)

# -----------------------------------------------------------------------------
# Test outputs: Type
def test_loop_exhaust():
    """Text Exhausting forwards()'s loop."""
    # Should not raise.
    forward(n_features=X_train.shape[-1], min_change=None, _do_not_skip=False)