Beispiel #1
0
def test_TextModel():
    from b4msa.textmodel import TextModel
    X, y = get_data()
    evo = EvoMSA()
    evo.model(X)
    assert isinstance(evo._textModel, list)
    assert isinstance(evo._textModel[0], TextModel)
    assert len(evo._textModel) == 1
Beispiel #2
0
def test_vector_space():
    X, y = get_data()
    evo = EvoMSA(evodag_args=dict(popsize=10,
                                  early_stopping_rounds=10,
                                  n_estimators=3),
                 models=[['EvoMSA.model.Corpus', 'EvoMSA.model.Bernulli']])
    evo.model(X)
    nrows = len(X)
    X = evo.vector_space(X)
    assert X[0].shape[0] == nrows
Beispiel #3
0
def test_EvoMSA_model():
    X, y = get_data()
    model = EvoMSA(evodag_args=dict(popsize=10,
                                    early_stopping_rounds=10,
                                    n_estimators=3),
                   models=[['EvoMSA.model.Corpus', 'EvoMSA.model.Bernulli']],
                   n_jobs=2)
    assert len(model.models) == 2
    model.model(X)
    assert len(model._textModel) == 2
    print(model._textModel)
Beispiel #4
0
def test_EvoMSA_kfold_decision_function():
    from sklearn.preprocessing import LabelEncoder
    X, y = get_data()
    le = LabelEncoder().fit(y)
    y = le.transform(y)
    evo = EvoMSA(evodag_args=dict(popsize=10,
                                  early_stopping_rounds=10,
                                  n_estimators=3),
                 models=[['EvoMSA.model.Corpus', 'EvoMSA.model.Bernulli']])
    evo.model(X)
    X = evo.vector_space(X)
    cl = evo.models[1][1]
    D = evo.kfold_decision_function(cl, X[1], y)
    assert len(D[0]) == 4
    assert isinstance(D[0], list)
Beispiel #5
0
def test_EvoMSA_fit_svm():
    from sklearn.preprocessing import LabelEncoder
    X, y = get_data()
    from sklearn.svm import LinearSVC
    from EvoMSA.model import Bernoulli
    model = EvoMSA(stacked_method_args=dict(popsize=10,
                                            early_stopping_rounds=10,
                                            n_estimators=3),
                   models=[['EvoMSA.model.Corpus', 'EvoMSA.model.Bernoulli']],
                   n_jobs=2)
    le = LabelEncoder().fit(y)
    y = le.transform(y)
    model.model(X)
    Xvs = model.vector_space(X)
    model.fit_svm(Xvs, y)
    print(model._svc_models)
    assert len(model._svc_models) == 2
    for ins, klass in zip(model._svc_models, [LinearSVC, Bernoulli]):
        assert isinstance(ins, klass)