当前位置: 首页>>代码示例>>Python>>正文


Python ensemble.VotingClassifier方法代码示例

本文整理汇总了Python中sklearn.ensemble.VotingClassifier方法的典型用法代码示例。如果您正苦于以下问题:Python ensemble.VotingClassifier方法的具体用法?Python ensemble.VotingClassifier怎么用?Python ensemble.VotingClassifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.ensemble的用法示例。


在下文中一共展示了ensemble.VotingClassifier方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_notfitted

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import VotingClassifier [as 别名]
def test_notfitted():
    eclf = VotingClassifier(estimators=[('lr1', LogisticRegression()),
                                        ('lr2', LogisticRegression())],
                            voting='soft')
    ereg = VotingRegressor([('dr', DummyRegressor())])
    msg = ("This %s instance is not fitted yet. Call \'fit\'"
           " with appropriate arguments before using this method.")
    assert_raise_message(NotFittedError, msg % 'VotingClassifier',
                         eclf.predict, X)
    assert_raise_message(NotFittedError, msg % 'VotingClassifier',
                         eclf.predict_proba, X)
    assert_raise_message(NotFittedError, msg % 'VotingClassifier',
                         eclf.transform, X)
    assert_raise_message(NotFittedError, msg % 'VotingRegressor',
                         ereg.predict, X_r)
    assert_raise_message(NotFittedError, msg % 'VotingRegressor',
                         ereg.transform, X_r) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:19,代码来源:test_voting.py

示例2: test_parallel_fit

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import VotingClassifier [as 别名]
def test_parallel_fit():
    """Check parallel backend of VotingClassifier on toy dataset."""
    clf1 = LogisticRegression(random_state=123)
    clf2 = RandomForestClassifier(random_state=123)
    clf3 = GaussianNB()
    X = np.array([[-1.1, -1.5], [-1.2, -1.4], [-3.4, -2.2], [1.1, 1.2]])
    y = np.array([1, 1, 2, 2])

    eclf1 = VotingClassifier(estimators=[
        ('lr', clf1), ('rf', clf2), ('gnb', clf3)],
        voting='soft',
        n_jobs=1).fit(X, y)
    eclf2 = VotingClassifier(estimators=[
        ('lr', clf1), ('rf', clf2), ('gnb', clf3)],
        voting='soft',
        n_jobs=2).fit(X, y)

    assert_array_equal(eclf1.predict(X), eclf2.predict(X))
    assert_array_almost_equal(eclf1.predict_proba(X), eclf2.predict_proba(X)) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:21,代码来源:test_voting.py

示例3: __init__

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import VotingClassifier [as 别名]
def __init__(self, num_features, **kwargs):
        super(VotingClassifier, self).__init__()

        kwargs = {**constants.VOTING_CLASSIFIER_PARAMS, **kwargs}

        voting = kwargs.pop('voting')

        self.num_features = num_features

        estimators = []
        for clf in constants.CLASSIFIERS_FOR_ENSEMBLE:
            model = utils.init_model(clf, num_features=num_features, **kwargs)

            estimators.append((clf, model.kernel))

        # use as kernel the VotingClassifier coming from sklearn
        self.kernel = SKVotingClassifier(
            estimators=estimators, voting=voting, n_jobs=None
        ) 
开发者ID:Wikidata,项目名称:soweego,代码行数:21,代码来源:classifiers.py

示例4: __init__

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import VotingClassifier [as 别名]
def __init__(self, api, lobes=False):
        """
        lobes = a dict of classifiers to use in the VotingClassifier
            defaults to RandomForestClassifier and DecisionTreeClassifier
        """
        self.api = api
        if not lobes:
            lobes = {'rf': RandomForestClassifier(n_estimators=7,
                                                  random_state=666),
                     'dt': DecisionTreeClassifier()
                     }
        self.lobe = VotingClassifier(
            estimators=[(lobe, lobes[lobe]) for lobe in lobes],
            voting='hard',
            n_jobs=-1)
        self._trained = False
        self.split = splitTrainTestData
        self.prep = prepDataframe 
开发者ID:s4w3d0ff,项目名称:marconibot,代码行数:20,代码来源:__init__.py

示例5: test_voting_hard_binary

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import VotingClassifier [as 别名]
def test_voting_hard_binary(self):
        model = VotingClassifier(
            voting="hard",
            flatten_transform=False,
            estimators=[
                ("lr", LogisticRegression()),
                ("lr2", LogisticRegression(fit_intercept=False)),
            ],
        )
        # predict_proba is not defined when voting is hard.
        dump_binary_classification(
            model,
            suffix="Hard",
            comparable_outputs=[0],
            allow_failure="StrictVersion(onnxruntime.__version__)"
                          " <= StrictVersion('0.5.0')",
            target_opset=TARGET_OPSET
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:20,代码来源:test_sklearn_voting_classifier_converter.py

示例6: test_voting_hard_binary_weights

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import VotingClassifier [as 别名]
def test_voting_hard_binary_weights(self):
        model = VotingClassifier(
            voting="hard",
            flatten_transform=False,
            weights=numpy.array([1000, 1]),
            estimators=[
                ("lr", LogisticRegression()),
                ("lr2", LogisticRegression(fit_intercept=False)),
            ],
        )
        # predict_proba is not defined when voting is hard.
        dump_binary_classification(
            model,
            suffix="WeightsHard",
            comparable_outputs=[0],
            allow_failure="StrictVersion(onnxruntime.__version__)"
                          " <= StrictVersion('0.5.0')",
            target_opset=TARGET_OPSET
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:21,代码来源:test_sklearn_voting_classifier_converter.py

示例7: test_voting_soft_binary

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import VotingClassifier [as 别名]
def test_voting_soft_binary(self):
        model = VotingClassifier(
            voting="soft",
            flatten_transform=False,
            estimators=[
                ("lr", LogisticRegression()),
                ("lr2", LogisticRegression(fit_intercept=False)),
            ],
        )
        dump_binary_classification(
            model,
            suffix="Soft",
            comparable_outputs=[0, 1],
            allow_failure="StrictVersion(onnxruntime.__version__)"
                          " <= StrictVersion('0.2.1')",
            target_opset=TARGET_OPSET
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:19,代码来源:test_sklearn_voting_classifier_converter.py

示例8: test_voting_soft_binary_weighted

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import VotingClassifier [as 别名]
def test_voting_soft_binary_weighted(self):
        model = VotingClassifier(
            voting="soft",
            flatten_transform=False,
            weights=numpy.array([1.8, 0.2]),
            estimators=[
                ("lr", LogisticRegression()),
                ("lr2", LogisticRegression(fit_intercept=False)),
            ],
        )
        dump_binary_classification(
            model,
            suffix="WeightedSoft",
            allow_failure="StrictVersion(onnxruntime.__version__)"
                          " <= StrictVersion('0.2.1')",
            target_opset=TARGET_OPSET
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:19,代码来源:test_sklearn_voting_classifier_converter.py

示例9: test_voting_hard_multi

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import VotingClassifier [as 别名]
def test_voting_hard_multi(self):
        # predict_proba is not defined when voting is hard.
        model = VotingClassifier(
            voting="hard",
            flatten_transform=False,
            estimators=[
                ("lr", LogisticRegression()),
                ("lr2", DecisionTreeClassifier()),
            ],
        )
        dump_multiple_classification(
            model,
            suffix="Hard",
            comparable_outputs=[0],
            allow_failure="StrictVersion(onnxruntime.__version__)"
                          " <= StrictVersion('0.5.0')",
            target_opset=TARGET_OPSET
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:20,代码来源:test_sklearn_voting_classifier_converter.py

示例10: test_voting_soft_multi

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import VotingClassifier [as 别名]
def test_voting_soft_multi(self):
        model = VotingClassifier(
            voting="soft",
            flatten_transform=False,
            estimators=[
                ("lr", LogisticRegression()),
                ("lr2", LogisticRegression()),
            ],
        )
        dump_multiple_classification(
            model,
            suffix="Soft",
            allow_failure="StrictVersion(onnxruntime.__version__)"
                          " <= StrictVersion('0.2.1')",
            target_opset=TARGET_OPSET
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:18,代码来源:test_sklearn_voting_classifier_converter.py

示例11: test_voting_soft_multi_string

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import VotingClassifier [as 别名]
def test_voting_soft_multi_string(self):
        model = VotingClassifier(
            voting="soft",
            flatten_transform=False,
            estimators=[
                ("lr", LogisticRegression()),
                ("lr2", LogisticRegression()),
            ],
        )
        dump_multiple_classification(
            model, label_string=True,
            suffix="Soft",
            allow_failure="StrictVersion(onnxruntime.__version__)"
                          " <= StrictVersion('0.2.1')",
            target_opset=TARGET_OPSET
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:18,代码来源:test_sklearn_voting_classifier_converter.py

示例12: test_voting_soft_multi_weighted

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import VotingClassifier [as 别名]
def test_voting_soft_multi_weighted(self):
        model = VotingClassifier(
            voting="soft",
            flatten_transform=False,
            weights=numpy.array([1.8, 0.2]),
            estimators=[
                ("lr", LogisticRegression()),
                ("lr2", LogisticRegression()),
            ],
        )
        dump_multiple_classification(
            model,
            suffix="WeightedSoft",
            allow_failure="StrictVersion(onnxruntime.__version__)"
                          " <= StrictVersion('0.2.1')",
            target_opset=TARGET_OPSET
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:19,代码来源:test_sklearn_voting_classifier_converter.py

示例13: test_voting_soft_multi_weighted4

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import VotingClassifier [as 别名]
def test_voting_soft_multi_weighted4(self):
        model = VotingClassifier(
            voting="soft",
            flatten_transform=False,
            weights=numpy.array([2.7, 0.3, 0.5, 0.5]),
            estimators=[
                ("lr", LogisticRegression()),
                ("lra", LogisticRegression()),
                ("lrb", LogisticRegression()),
                ("lr2", LogisticRegression()),
            ],
        )
        dump_multiple_classification(
            model,
            suffix="Weighted4Soft",
            allow_failure="StrictVersion(onnxruntime.__version__)"
                          " <= StrictVersion('0.2.1')",
            target_opset=TARGET_OPSET
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:21,代码来源:test_sklearn_voting_classifier_converter.py

示例14: test_voting_soft_multi_weighted42

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import VotingClassifier [as 别名]
def test_voting_soft_multi_weighted42(self):
        model = VotingClassifier(
            voting="soft",
            flatten_transform=False,
            weights=numpy.array([27, 0.3, 0.5, 0.5]),
            estimators=[
                ("lr", LogisticRegression()),
                ("lra", LogisticRegression()),
                ("lrb", LogisticRegression()),
                ("lr2", LogisticRegression()),
            ],
        )
        dump_multiple_classification(
            model,
            suffix="Weighted42Soft",
            allow_failure="StrictVersion(onnxruntime.__version__)"
                          " <= StrictVersion('0.2.1')",
            target_opset=TARGET_OPSET
        ) 
开发者ID:onnx,项目名称:sklearn-onnx,代码行数:21,代码来源:test_sklearn_voting_classifier_converter.py

示例15: test_parallel_fit

# 需要导入模块: from sklearn import ensemble [as 别名]
# 或者: from sklearn.ensemble import VotingClassifier [as 别名]
def test_parallel_fit():
    """Check parallel backend of VotingClassifier on toy dataset."""
    clf1 = LogisticRegression(random_state=123)
    clf2 = RandomForestClassifier(random_state=123)
    clf3 = GaussianNB()
    X = np.array([[-1.1, -1.5], [-1.2, -1.4], [-3.4, -2.2], [1.1, 1.2]])
    y = np.array([1, 1, 2, 2])

    eclf1 = VotingClassifier(estimators=[
        ('lr', clf1), ('rf', clf2), ('gnb', clf3)],
        voting='soft',
        n_jobs=1).fit(X, y)
    eclf2 = VotingClassifier(estimators=[
        ('lr', clf1), ('rf', clf2), ('gnb', clf3)],
        voting='soft',
        n_jobs=2).fit(X, y)

    assert_array_equal(eclf1.predict(X), eclf2.predict(X))
    assert_array_equal(eclf1.predict_proba(X), eclf2.predict_proba(X)) 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:21,代码来源:test_voting_classifier.py


注:本文中的sklearn.ensemble.VotingClassifier方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。