check_test.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:MetaHeuristic 作者: gonzalesMK 项目源码 文件源码
def test_plot():
    dataset = load_breast_cancer()
    X, y = dataset['data'], dataset['target_names'].take(dataset['target'])

    # Classifier to be used in the metaheuristic
    clf = SVC()

    for metaclass in METACLASSES:
        meta = metaclass(classifier=clf, random_state=0, verbose=False,
                        make_logbook=True, repeat=1, number_gen=2,
                        size_pop=2)

        print("Checking plotting: ", meta._name)

        # Fit the classifier
        meta.fit(X, y, normalize=True)

        # Transformed dataset
        X_1 = meta.transform(X)

        meta = metaclass(classifier=clf, random_state=0,
                        make_logbook=True, repeat=1, number_gen=2, size_pop=2)

        # Fit and Transform
        X_2 = meta.fit_transform(X=X, y=y, normalize=True)

        assert_array_equal(X_1, X_2)

        # Plot the results of each test
        meta.plot_results()

    ga = GeneticAlgorithm(classifier=clf, random_state=1,
                          make_logbook=False, repeat=1)

    # check for error in plot
    ga.fit(X, y, normalize=True)
    assert_raises(ValueError, ga.plot_results)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号