本文整理汇总了Python中sklearn.utils.testing.assert_raises方法的典型用法代码示例。如果您正苦于以下问题:Python testing.assert_raises方法的具体用法?Python testing.assert_raises怎么用?Python testing.assert_raises使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.utils.testing
的用法示例。
在下文中一共展示了testing.assert_raises方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fit_predict_score
# 需要导入模块: from sklearn.utils import testing [as 别名]
# 或者: from sklearn.utils.testing import assert_raises [as 别名]
def test_fit_predict_score(self):
self.clf.fit_predict_score(self.X_test, self.y_test)
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='roc_auc_score')
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='prc_n_score')
with assert_raises(NotImplementedError):
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='something')
# def test_score(self):
# self.clf.score(self.X_test, self.y_test)
# self.clf.score(self.X_test, self.y_test, scoring='roc_auc_score')
# self.clf.score(self.X_test, self.y_test, scoring='prc_n_score')
# with assert_raises(NotImplementedError):
# self.clf.score(self.X_test, self.y_test, scoring='something')
示例2: test_check_parameters
# 需要导入模块: from sklearn.utils import testing [as 别名]
# 或者: from sklearn.utils.testing import assert_raises [as 别名]
def test_check_parameters(self):
with assert_raises(ValueError):
SOD(n_neighbors=None, ref_set=10, alpha=0.8)
with assert_raises(ValueError):
SOD(n_neighbors=20, ref_set=None, alpha=0.8)
with assert_raises(ValueError):
SOD(n_neighbors=20, ref_set=10, alpha=None)
with assert_raises(ValueError):
SOD(n_neighbors=-1, ref_set=10, alpha=0.8)
with assert_raises(ValueError):
SOD(n_neighbors=20, ref_set=-1, alpha=0.8)
with assert_raises(ValueError):
SOD(n_neighbors=20, ref_set=10, alpha=-1)
with assert_raises(ValueError):
SOD(n_neighbors=20, ref_set=25, alpha=0.8)
with assert_raises(ValueError):
SOD(n_neighbors='not int', ref_set=25, alpha=0.8)
with assert_raises(ValueError):
SOD(n_neighbors=20, ref_set='not int', alpha=0.8)
with assert_raises(ValueError):
SOD(n_neighbors=20, ref_set=25, alpha='not float')
示例3: test_stratified_shuffle_split_init
# 需要导入模块: from sklearn.utils import testing [as 别名]
# 或者: from sklearn.utils.testing import assert_raises [as 别名]
def test_stratified_shuffle_split_init():
X = np.arange(7)
y = np.asarray([0, 1, 1, 1, 2, 2, 2])
# Check that error is raised if there is a class with only one sample
assert_raises(ValueError, next,
StratifiedShuffleSplit(3, 0.2).split(X, y))
# Check that error is raised if the test set size is smaller than n_classes
assert_raises(ValueError, next, StratifiedShuffleSplit(3, 2).split(X, y))
# Check that error is raised if the train set size is smaller than
# n_classes
assert_raises(ValueError, next,
StratifiedShuffleSplit(3, 3, 2).split(X, y))
X = np.arange(9)
y = np.asarray([0, 0, 0, 1, 1, 1, 2, 2, 2])
# Train size or test size too small
assert_raises(ValueError, next,
StratifiedShuffleSplit(train_size=2).split(X, y))
assert_raises(ValueError, next,
StratifiedShuffleSplit(test_size=2).split(X, y))
示例4: test_lasso_lars_ic
# 需要导入模块: from sklearn.utils import testing [as 别名]
# 或者: from sklearn.utils.testing import assert_raises [as 别名]
def test_lasso_lars_ic():
# Test the LassoLarsIC object by checking that
# - some good features are selected.
# - alpha_bic > alpha_aic
# - n_nonzero_bic < n_nonzero_aic
lars_bic = linear_model.LassoLarsIC('bic')
lars_aic = linear_model.LassoLarsIC('aic')
rng = np.random.RandomState(42)
X = diabetes.data
X = np.c_[X, rng.randn(X.shape[0], 5)] # add 5 bad features
lars_bic.fit(X, y)
lars_aic.fit(X, y)
nonzero_bic = np.where(lars_bic.coef_)[0]
nonzero_aic = np.where(lars_aic.coef_)[0]
assert_greater(lars_bic.alpha_, lars_aic.alpha_)
assert_less(len(nonzero_bic), len(nonzero_aic))
assert_less(np.max(nonzero_bic), diabetes.data.shape[1])
# test error on unknown IC
lars_broken = linear_model.LassoLarsIC('<unknown>')
assert_raises(ValueError, lars_broken.fit, X, y)
示例5: test_init
# 需要导入模块: from sklearn.utils import testing [as 别名]
# 或者: from sklearn.utils.testing import assert_raises [as 别名]
def test_init(self):
"""
Test base class initialization
:return:
"""
self.dummy_clf = Dummy1()
self.dummy_clf = Dummy1(base_estimators=[DecisionTreeClassifier(),
DecisionTreeClassifier()])
# assert_equal(self.dummy_clf.base_estimators,
# [DecisionTreeClassifier(), LogisticRegression()])
#
# self.dummy_clf = Dummy1(
# base_estimators=[LogisticRegression(), DecisionTreeClassifier()])
# assert_equal(self.dummy_clf.base_estimators,
# [LogisticRegression(), DecisionTreeClassifier()])
# with assert_raises(ValueError):
# Dummy1(base_estimators=[LogisticRegression()])
#
# with assert_raises(ValueError):
# Dummy1(base_estimators=0)
#
# with assert_raises(ValueError):
# Dummy1(base_estimators=-0.5)
示例6: test_prediction_proba_parameter
# 需要导入模块: from sklearn.utils import testing [as 别名]
# 或者: from sklearn.utils.testing import assert_raises [as 别名]
def test_prediction_proba_parameter(self):
with assert_raises(ValueError):
self.clf.predict_proba(self.X_test, method='something')
示例7: test_fit_predict_score
# 需要导入模块: from sklearn.utils import testing [as 别名]
# 或者: from sklearn.utils.testing import assert_raises [as 别名]
def test_fit_predict_score(self):
self.clf.fit_predict_score(self.X_test, self.y_test)
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='roc_auc_score')
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='prc_n_score')
with assert_raises(NotImplementedError):
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='something')
示例8: test_aom_static_n_buckets
# 需要导入模块: from sklearn.utils import testing [as 别名]
# 或者: from sklearn.utils.testing import assert_raises [as 别名]
def test_aom_static_n_buckets(self):
with assert_raises(ValueError):
aom(self.scores, 5, method='static', bootstrap_estimators=False,
random_state=42)
# TODO: add more complicated testcases
示例9: test_moa_static_n_buckets
# 需要导入模块: from sklearn.utils import testing [as 别名]
# 或者: from sklearn.utils.testing import assert_raises [as 别名]
def test_moa_static_n_buckets(self):
with assert_raises(ValueError):
moa(self.scores, 5, method='static', bootstrap_estimators=False,
random_state=42)
# TODO: add more complicated testcases
示例10: test_get_params
# 需要导入模块: from sklearn.utils import testing [as 别名]
# 或者: from sklearn.utils.testing import assert_raises [as 别名]
def test_get_params(self):
test = T(K(), K())
assert ('a__d' in test.get_params(deep=True))
assert ('a__d' not in test.get_params(deep=False))
test.set_params(a__d=2)
assert (test.a.d == 2)
assert_raises(ValueError, test.set_params, a__a=2)
示例11: test_check_consistent_shape
# 需要导入模块: from sklearn.utils import testing [as 别名]
# 或者: from sklearn.utils.testing import assert_raises [as 别名]
def test_check_consistent_shape(self):
X_train, y_train, X_test, y_test = generate_data(
n_train=self.n_train,
n_test=self.n_test,
contamination=self.contamination)
X_train_n, y_train_n, X_test_n, y_test_n, y_train_pred_n, y_test_pred_n \
= check_consistent_shape(X_train, y_train, X_test, y_test,
y_train, y_test)
assert_allclose(X_train_n, X_train)
assert_allclose(y_train_n, y_train)
assert_allclose(X_test_n, X_test)
assert_allclose(y_test_n, y_test)
assert_allclose(y_train_pred_n, y_train)
assert_allclose(y_test_pred_n, y_test)
# test shape difference
with assert_raises(ValueError):
check_consistent_shape(X_train, y_train, y_train, y_test,
y_train, y_test)
# test shape difference between X_train and X_test
X_test = np.hstack((X_test, np.zeros(
(X_test.shape[0], 1)))) # add extra column/feature
with assert_raises(ValueError):
check_consistent_shape(X_train, y_train, X_test, y_test,
y_train_pred_n, y_test_pred_n)