Exemplo n.º 1
0
def test_high_n_bins_entropy():
    """Test that an error is raised when 'n_bins' is too large."""
    msg_error = ("The number of bins is too high for timestamp {0}. "
                 "Consider trying with a smaller number of bins or "
                 "removing this timestamp.".format(0))
    mcb = MultipleCoefficientBinning(n_bins=9, strategy='entropy')
    with pytest.raises(ValueError, match=msg_error):
        mcb.fit(X, y)
Exemplo n.º 2
0
def test_identical_bin_edges():
    """Test that an error is raised when two consecutive bins are equal."""
    msg_error = ("At least two consecutive quantiles are equal. "
                 "Consider trying with a smaller number of bins or "
                 "removing timestamps with low variation.")
    mcb = MultipleCoefficientBinning(n_bins=6, strategy='quantile')
    with pytest.raises(ValueError, match=msg_error):
        mcb.fit(np.r_[np.zeros((4, 2)), np.ones((4, 2))])
Exemplo n.º 3
0
def test_consistent_length():
    """Test that a ValueError is raised with a constant sample."""
    msg_error = ("The number of timestamps in X must be the same as "
                 "the number of timestamps when `fit` was called "
                 "({0} != {1}).".format(3, 1))
    mcb = MultipleCoefficientBinning()
    mcb.fit(X, y)
    with pytest.raises(ValueError, match=re.escape(msg_error)):
        mcb.transform(X[:, :1])
Exemplo n.º 4
0
def test_parameter_check(params, error, err_msg):
    """Test parameter validation."""
    mcb = MultipleCoefficientBinning(**params)
    with pytest.raises(error, match=re.escape(err_msg)):
        mcb.fit(X, y)
Exemplo n.º 5
0
def test_y_none_entropy():
    """Test that an error is raised when y is None and 'entropy' is used."""
    msg_error = "y cannot be None if strategy='entropy'."
    mcb = MultipleCoefficientBinning(n_bins=2, strategy='entropy')
    with pytest.raises(ValueError, match=msg_error):
        mcb.fit(X, None)