• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python estimator_checks.check_estimator函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sklearn.utils.estimator_checks.check_estimator函数的典型用法代码示例。如果您正苦于以下问题:Python check_estimator函数的具体用法?Python check_estimator怎么用?Python check_estimator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_check_estimator

def test_check_estimator():
    # tests that the estimator actually fails on "bad" estimators.
    # not a complete test of all checks, which are very extensive.

    # check that we have a set_params and can clone
    msg = "it does not implement a 'get_params' methods"
    assert_raises_regex(TypeError, msg, check_estimator, object)
    # check that we have a fit method
    msg = "object has no attribute 'fit'"
    assert_raises_regex(AttributeError, msg, check_estimator, BaseEstimator)
    # check that fit does input validation
    msg = "TypeError not raised by fit"
    assert_raises_regex(AssertionError, msg, check_estimator, BaseBadClassifier)
    # check that predict does input validation (doesn't accept dicts in input)
    msg = "Estimator doesn't check for NaN and inf in predict"
    assert_raises_regex(AssertionError, msg, check_estimator, NoCheckinPredict)
    # check for sparse matrix input handling
    msg = "Estimator type doesn't seem to fail gracefully on sparse data"
    # the check for sparse input handling prints to the stdout,
    # instead of raising an error, so as not to remove the original traceback.
    # that means we need to jump through some hoops to catch it.
    old_stdout = sys.stdout
    string_buffer = StringIO()
    sys.stdout = string_buffer
    try:
        check_estimator(NoSparseClassifier)
    except:
        pass
    finally:
        sys.stdout = old_stdout
    assert_true(msg in string_buffer.getvalue())

    # doesn't error on actual estimator
    check_estimator(AdaBoostClassifier)
开发者ID:DjalelBBZ,项目名称:scikit-learn,代码行数:34,代码来源:test_estimator_checks.py


示例2: test_sklearn_estimator

 def test_sklearn_estimator(self):
     '''
     Tests each regression / classification model by invoking extensive
     sklearn test suite
     '''        
     for estimator in ESTIMATORS:
         check_estimator(estimator)
开发者ID:AmazaspShumik,项目名称:sklearn-bayes,代码行数:7,代码来源:tester.py


示例3: __test_estimator_checks

def __test_estimator_checks():
    try:
        from sklearn.utils.estimator_checks import check_estimator
    except ImportError:
        raise SkipTest("need scikit-learn 0.17+ for check_estimator()")

    check_estimator(MSTClustering)
开发者ID:SerialDev,项目名称:mst_clustering,代码行数:7,代码来源:test_mst_clustering.py


示例4: test_check_estimator_clones

def test_check_estimator_clones():
    # check that check_estimator doesn't modify the estimator it receives
    from sklearn.datasets import load_iris
    iris = load_iris()

    for Estimator in [GaussianMixture, LinearRegression,
                      RandomForestClassifier, NMF, SGDClassifier,
                      MiniBatchKMeans]:
        with ignore_warnings(category=FutureWarning):
            # when 'est = SGDClassifier()'
            est = Estimator()
        set_checking_parameters(est)
        set_random_state(est)
        # without fitting
        old_hash = joblib.hash(est)
        check_estimator(est)
        assert_equal(old_hash, joblib.hash(est))

        with ignore_warnings(category=FutureWarning):
            # when 'est = SGDClassifier()'
            est = Estimator()
        set_checking_parameters(est)
        set_random_state(est)
        # with fitting
        est.fit(iris.data + 10, iris.target)
        old_hash = joblib.hash(est)
        check_estimator(est)
        assert_equal(old_hash, joblib.hash(est))
开发者ID:ZIP97,项目名称:scikit-learn,代码行数:28,代码来源:test_estimator_checks.py


示例5: test_valid_estimator_syl

def test_valid_estimator_syl():
    """Test whether ovk.OVKRidge is a valid sklearn estimator."""
    from sklearn import __version__
    # Adding patch revision number causes crash
    if LooseVersion(__version__) >= LooseVersion('0.18'):
        check_estimator(ovk.OVKRidge)
    else:
        warn('sklearn\'s check_estimator seems to be broken in __version__ <='
             ' 0.17.x... skipping')
开发者ID:operalib,项目名称:operalib,代码行数:9,代码来源:test_KernelRidge_dec.py


示例6: test_rca

 def test_rca(self):
   def stable_init(self, num_dims=None, pca_comps=None,
                   chunk_size=2, preprocessor=None):
     # this init makes RCA stable for scikit-learn examples.
     RCA_Supervised.__init__(self, num_chunks=2, num_dims=num_dims,
                             pca_comps=pca_comps, chunk_size=chunk_size,
                             preprocessor=preprocessor)
   dRCA.__init__ = stable_init
   check_estimator(dRCA)
开发者ID:all-umass,项目名称:metric-learn,代码行数:9,代码来源:test_sklearn_compat.py


示例7: test_check_estimator_pairwise

def test_check_estimator_pairwise():
    # check that check_estimator() works on estimator with _pairwise
    # kernel or  metric

    # test precomputed kernel
    est = SVC(kernel='precomputed')
    check_estimator(est)

    # test precomputed metric
    est = KNeighborsRegressor(metric='precomputed')
    check_estimator(est)
开发者ID:ZIP97,项目名称:scikit-learn,代码行数:11,代码来源:test_estimator_checks.py


示例8: test_sdml

 def test_sdml(self):
   def stable_init(self, sparsity_param=0.01, num_labeled='deprecated',
                   num_constraints=None, verbose=False, preprocessor=None):
     # this init makes SDML stable for scikit-learn examples.
     SDML_Supervised.__init__(self, sparsity_param=sparsity_param,
                              num_labeled=num_labeled,
                              num_constraints=num_constraints,
                              verbose=verbose,
                              preprocessor=preprocessor,
                              balance_param=1e-5, use_cov=False)
   dSDML.__init__ = stable_init
   check_estimator(dSDML)
开发者ID:all-umass,项目名称:metric-learn,代码行数:12,代码来源:test_sklearn_compat.py


示例9: _validate_estimator

    def _validate_estimator(self, default=None):
        """Check the value of alpha and beta and clustering algorithm.
        """

        check_parameter(self.alpha, low=0, high=1, param_name='alpha',
                        include_left=False, include_right=False)

        check_parameter(self.beta, low=1, param_name='beta',
                        include_left=False)

        if self.clustering_estimator is not None:
            self.clustering_estimator_ = self.clustering_estimator
        else:
            self.clustering_estimator_ = default

        # make sure the base clustering algorithm is valid
        if self.clustering_estimator_ is None:
            raise ValueError("clustering algorithm cannot be None")

        if self.check_estimator:
            check_estimator(self.clustering_estimator_)
开发者ID:flaviassantos,项目名称:pyod,代码行数:21,代码来源:cblof.py


示例10: _validate_estimator

    def _validate_estimator(self, default=None):
        """Check the estimator and the n_estimator attribute, set the
        `base_estimator_` attribute."""
        if not isinstance(self.n_estimators, (numbers.Integral, np.integer)):
            raise ValueError("n_estimators must be an integer, "
                             "got {0}.".format(type(self.n_estimators)))

        if self.n_estimators <= 0:
            raise ValueError("n_estimators must be greater than zero, "
                             "got {0}.".format(self.n_estimators))

        if self.base_estimator is not None:
            self.base_estimator_ = self.base_estimator
        else:
            self.base_estimator_ = default

        if self.base_estimator_ is None:
            raise ValueError("base_estimator cannot be None")

        # make sure estimator is consistent with sklearn
        if self.check_estimator:
            check_estimator(self.base_estimator_)
开发者ID:flaviassantos,项目名称:pyod,代码行数:22,代码来源:feature_bagging.py


示例11: test_check_estimator

def test_check_estimator():
    # tests that the estimator actually fails on "bad" estimators.
    # not a complete test of all checks, which are very extensive.

    # check that we have a set_params and can clone
    msg = "it does not implement a 'get_params' methods"
    assert_raises_regex(TypeError, msg, check_estimator, object)
    # check that we have a fit method
    msg = "object has no attribute 'fit'"
    assert_raises_regex(AttributeError, msg, check_estimator, BaseEstimator)
    # check that fit does input validation
    msg = "TypeError not raised"
    assert_raises_regex(AssertionError, msg, check_estimator, BaseBadClassifier)
    # check that sample_weights in fit accepts pandas.Series type
    try:
        from pandas import Series  # noqa

        msg = (
            "Estimator NoSampleWeightPandasSeriesType raises error if "
            "'sample_weight' parameter is of type pandas.Series"
        )
        assert_raises_regex(ValueError, msg, check_estimator, NoSampleWeightPandasSeriesType)
    except ImportError:
        pass
    # check that predict does input validation (doesn't accept dicts in input)
    msg = "Estimator doesn't check for NaN and inf in predict"
    assert_raises_regex(AssertionError, msg, check_estimator, NoCheckinPredict)
    # check that estimator state does not change
    # at transform/predict/predict_proba time
    msg = "Estimator changes __dict__ during predict"
    assert_raises_regex(AssertionError, msg, check_estimator, ChangesDict)

    # check for sparse matrix input handling
    name = NoSparseClassifier.__name__
    msg = "Estimator " + name + " doesn't seem to fail gracefully on sparse data"
    # the check for sparse input handling prints to the stdout,
    # instead of raising an error, so as not to remove the original traceback.
    # that means we need to jump through some hoops to catch it.
    old_stdout = sys.stdout
    string_buffer = StringIO()
    sys.stdout = string_buffer
    try:
        check_estimator(NoSparseClassifier)
    except:
        pass
    finally:
        sys.stdout = old_stdout
    assert_true(msg in string_buffer.getvalue())

    # doesn't error on actual estimator
    check_estimator(AdaBoostClassifier)
    check_estimator(MultiTaskElasticNet)
开发者ID:nelson-liu,项目名称:scikit-learn,代码行数:52,代码来源:test_estimator_checks.py


示例12: test_enn_sk_estimator

def test_enn_sk_estimator():
    """Test the sklearn estimator compatibility"""
    check_estimator(RepeatedEditedNearestNeighbours)
开发者ID:kellyhennigan,项目名称:cueexp_scripts,代码行数:3,代码来源:test_repeated_edited_nearest_neighbours.py


示例13: test_sklearn_estimator

 def test_sklearn_estimator(self):
     check_estimator(self.clf)
开发者ID:flaviassantos,项目名称:pyod,代码行数:2,代码来源:test_lof.py


示例14: test_ncr_sk_estimator

def test_ncr_sk_estimator():
    """Test the sklearn estimator compatibility"""
    check_estimator(NeighbourhoodCleaningRule)
开发者ID:kellyhennigan,项目名称:cueexp_scripts,代码行数:3,代码来源:test_neighbourhood_cleaning_rule.py


示例15: test_estimator_interface

 def test_estimator_interface(self):
     estimator_checks.check_estimator(LogitNet)
开发者ID:civisanalytics,项目名称:python-glmnet,代码行数:2,代码来源:test_logistic.py


示例16: test_novelty_true_common_tests

def test_novelty_true_common_tests():

    # the common tests are run for the default LOF (novelty=False).
    # here we run these common tests for LOF when novelty=True
    check_estimator(neighbors.LocalOutlierFactor(novelty=True))
开发者ID:feiniao1696,项目名称:scikit-learn,代码行数:5,代码来源:test_lof.py


示例17: test_itml

 def test_itml(self):
   check_estimator(dITML)
开发者ID:svecon,项目名称:metric-learn,代码行数:2,代码来源:test_sklearn_compat.py


示例18: test_estimator

def test_estimator():
    from sklearn.utils.estimator_checks import check_estimator
    check_estimator(FlexibleLinearRegression)
开发者ID:mkliegl,项目名称:custom-sklearn,代码行数:3,代码来源:flexible_linear.py


示例19: test_mlkr

 def test_mlkr(self):
   check_estimator(MLKR)
开发者ID:svecon,项目名称:metric-learn,代码行数:2,代码来源:test_sklearn_compat.py


示例20: test_common

def test_common():
    return check_estimator(TemplateEstimator)
开发者ID:MechCoder,项目名称:project-template,代码行数:2,代码来源:test_common.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python extmath._incremental_mean_and_var函数代码示例发布时间:2022-05-27
下一篇:
Python utils.shuffle函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap