<commit_before>"""
Testing for the base module (sklearn.ensemble.base).
"""

from numpy.testing import assert_equal
from nose.tools import assert_raises

from sklearn.ensemble import BaseEnsemble
from sklearn.tree import DecisionTreeClassifier


def test_base():
    """Check BaseEnsemble methods."""
    tree = DecisionTreeClassifier()
    ensemble = BaseEnsemble(base_estimator=tree, n_estimators=3)

    ensemble._make_estimator()
    ensemble._make_estimator()
    ensemble._make_estimator()

    assert_equal(3, len(ensemble))
    assert_equal(3, len(ensemble.estimators_))


def test_error():
    """Check that proper errors are triggered."""
    def instantiate(class_name, **params):
        return class_name(**params)

    base_estimator = object()
    assert_raises(TypeError, instantiate, class_name=BaseEnsemble,
                  base_estimator=base_estimator, n_estimators=1)

    base_estimator = DecisionTreeClassifier()
    assert_raises(ValueError, instantiate, class_name=BaseEnsemble,
                  base_estimator=base_estimator, n_estimators=-1)<commit_msg>TEST: Improved coverage of the ensemble package to 100%<commit_after>"""
Testing for the base module (sklearn.ensemble.base).
"""

from numpy.testing import assert_equal
from nose.tools import assert_raises

from sklearn.ensemble import BaseEnsemble
from sklearn.tree import DecisionTreeClassifier


def test_base():
    """Check BaseEnsemble methods."""
    tree = DecisionTreeClassifier()
    ensemble = BaseEnsemble(base_estimator=tree, n_estimators=3)

    ensemble._make_estimator()
    ensemble._make_estimator()
    ensemble._make_estimator()
    ensemble._make_estimator(append=False)

    assert_equal(3, len(ensemble))
    assert_equal(3, len(ensemble.estimators_))

    assert isinstance(ensemble[0], DecisionTreeClassifier)


def test_error():
    """Check that proper errors are triggered."""
    def instantiate(class_name, **params):
        return class_name(**params)

    base_estimator = object()
    assert_raises(TypeError, instantiate, class_name=BaseEnsemble,
                  base_estimator=base_estimator, n_estimators=1)

    base_estimator = DecisionTreeClassifier()
    assert_raises(ValueError, instantiate, class_name=BaseEnsemble,
                  base_estimator=base_estimator, n_estimators=-1)
{'fraction_non_alphanumeric': 0.09303331890956296, 'fraction_numerical': 0.006057983556901774, 'mean_word_length': 4.598062953995157, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6595151', 'n_tokens_mistral': 739, 'n_tokens_neox': 720, 'n_words': 145}