本文整理汇总了Python中sklearn.utils.estimator_checks.check_estimator函数的典型用法代码示例。如果您正苦于以下问题:Python check_estimator函数的具体用法?Python check_estimator怎么用?Python check_estimator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_estimator函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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))
示例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')
示例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)
示例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)
示例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)
示例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_)
示例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_)
示例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)
示例12: test_enn_sk_estimator
def test_enn_sk_estimator():
"""Test the sklearn estimator compatibility"""
check_estimator(RepeatedEditedNearestNeighbours)
示例13: test_sklearn_estimator
def test_sklearn_estimator(self):
check_estimator(self.clf)
示例14: test_ncr_sk_estimator
def test_ncr_sk_estimator():
"""Test the sklearn estimator compatibility"""
check_estimator(NeighbourhoodCleaningRule)
示例15: test_estimator_interface
def test_estimator_interface(self):
estimator_checks.check_estimator(LogitNet)