本文整理匯總了Python中sklearn.svm.NuSVR方法的典型用法代碼示例。如果您正苦於以下問題:Python svm.NuSVR方法的具體用法?Python svm.NuSVR怎麽用?Python svm.NuSVR使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sklearn.svm
的用法示例。
在下文中一共展示了svm.NuSVR方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_gradient_boosting_with_init_pipeline
# 需要導入模塊: from sklearn import svm [as 別名]
# 或者: from sklearn.svm import NuSVR [as 別名]
def test_gradient_boosting_with_init_pipeline():
# Check that the init estimator can be a pipeline (see issue #13466)
X, y = make_regression(random_state=0)
init = make_pipeline(LinearRegression())
gb = GradientBoostingRegressor(init=init)
gb.fit(X, y) # pipeline without sample_weight works fine
with pytest.raises(
ValueError,
match='The initial estimator Pipeline does not support sample '
'weights'):
gb.fit(X, y, sample_weight=np.ones(X.shape[0]))
# Passing sample_weight to a pipeline raises a ValueError. This test makes
# sure we make the distinction between ValueError raised by a pipeline that
# was passed sample_weight, and a ValueError raised by a regular estimator
# whose input checking failed.
with pytest.raises(
ValueError,
match='nu <= 0 or nu > 1'):
# Note that NuSVR properly supports sample_weight
init = NuSVR(gamma='auto', nu=1.5)
gb = GradientBoostingRegressor(init=init)
gb.fit(X, y, sample_weight=np.ones(X.shape[0]))
示例2: test_sample_weights
# 需要導入模塊: from sklearn import svm [as 別名]
# 或者: from sklearn.svm import NuSVR [as 別名]
def test_sample_weights():
# Test weights on individual samples
# TODO: check on NuSVR, OneClass, etc.
clf = svm.SVC(gamma="scale")
clf.fit(X, Y)
assert_array_equal(clf.predict([X[2]]), [1.])
sample_weight = [.1] * 3 + [10] * 3
clf.fit(X, Y, sample_weight=sample_weight)
assert_array_equal(clf.predict([X[2]]), [2.])
# test that rescaling all samples is the same as changing C
clf = svm.SVC(gamma="scale")
clf.fit(X, Y)
dual_coef_no_weight = clf.dual_coef_
clf.set_params(C=100)
clf.fit(X, Y, sample_weight=np.repeat(0.01, len(X)))
assert_array_almost_equal(dual_coef_no_weight, clf.dual_coef_)
示例3: convert
# 需要導入模塊: from sklearn import svm [as 別名]
# 或者: from sklearn.svm import NuSVR [as 別名]
def convert(model, feature_names, target):
"""Convert a Nu Support Vector Regression (NuSVR) model to the protobuf spec.
Parameters
----------
model: NuSVR
A trained NuSVR encoder model.
feature_names: [str]
Name of the input columns.
target: str
Name of the output column.
Returns
-------
model_spec: An object of type Model_pb.
Protobuf representation of the model
"""
if not (_HAS_SKLEARN):
raise RuntimeError(
"scikit-learn not found. scikit-learn conversion API is disabled."
)
_sklearn_util.check_expected_type(model, _NuSVR)
return _SVR.convert(model, feature_names, target)
示例4: test_convert_nusvr
# 需要導入模塊: from sklearn import svm [as 別名]
# 或者: from sklearn.svm import NuSVR [as 別名]
def test_convert_nusvr(self):
model, X = self._fit_binary_classification(NuSVR())
model_onnx = convert_sklearn(
model, "SVR", [("input", FloatTensorType([None, X.shape[1]]))])
node = model_onnx.graph.node[0]
self.assertIsNotNone(node)
self._check_attributes(
node,
{
"coefficients": None,
"kernel_params": None,
"kernel_type": "RBF",
"post_transform": None,
"rho": None,
"support_vectors": None,
},
)
dump_data_and_model(X, model, model_onnx,
basename="SklearnRegNuSVR")
示例5: test_convert_nusvr_int
# 需要導入模塊: from sklearn import svm [as 別名]
# 或者: from sklearn.svm import NuSVR [as 別名]
def test_convert_nusvr_int(self):
model, X = fit_regression_model(
NuSVR(), is_int=True)
model_onnx = convert_sklearn(
model,
"NuSVR",
[("input", Int64TensorType([None, X.shape[1]]))],
)
self.assertIsNotNone(model_onnx)
dump_data_and_model(
X,
model,
model_onnx,
basename="SklearnNuSVRInt-Dec4",
allow_failure="StrictVersion(onnxruntime.__version__)"
" <= StrictVersion('0.2.1')"
)
示例6: test_convert_nusvr_bool
# 需要導入模塊: from sklearn import svm [as 別名]
# 或者: from sklearn.svm import NuSVR [as 別名]
def test_convert_nusvr_bool(self):
model, X = fit_regression_model(
NuSVR(), is_bool=True)
model_onnx = convert_sklearn(
model,
"NuSVR",
[("input", BooleanTensorType([None, X.shape[1]]))],
)
self.assertIsNotNone(model_onnx)
dump_data_and_model(
X,
model,
model_onnx,
basename="SklearnNuSVRBool",
allow_failure="StrictVersion(onnxruntime.__version__)"
" <= StrictVersion('0.2.1')"
)
示例7: test_svr
# 需要導入模塊: from sklearn import svm [as 別名]
# 或者: from sklearn.svm import NuSVR [as 別名]
def test_svr():
# Test Support Vector Regression
diabetes = datasets.load_diabetes()
for clf in (svm.NuSVR(kernel='linear', nu=.4, C=1.0),
svm.NuSVR(kernel='linear', nu=.4, C=10.),
svm.SVR(kernel='linear', C=10.),
svm.LinearSVR(C=10.),
svm.LinearSVR(C=10.),
):
clf.fit(diabetes.data, diabetes.target)
assert_greater(clf.score(diabetes.data, diabetes.target), 0.02)
# non-regression test; previously, BaseLibSVM would check that
# len(np.unique(y)) < 2, which must only be done for SVC
svm.SVR().fit(diabetes.data, np.ones(len(diabetes.data)))
svm.LinearSVR().fit(diabetes.data, np.ones(len(diabetes.data)))
示例8: test_sample_weights
# 需要導入模塊: from sklearn import svm [as 別名]
# 或者: from sklearn.svm import NuSVR [as 別名]
def test_sample_weights():
# Test weights on individual samples
# TODO: check on NuSVR, OneClass, etc.
clf = svm.SVC()
clf.fit(X, Y)
assert_array_equal(clf.predict([X[2]]), [1.])
sample_weight = [.1] * 3 + [10] * 3
clf.fit(X, Y, sample_weight=sample_weight)
assert_array_equal(clf.predict([X[2]]), [2.])
# test that rescaling all samples is the same as changing C
clf = svm.SVC()
clf.fit(X, Y)
dual_coef_no_weight = clf.dual_coef_
clf.set_params(C=100)
clf.fit(X, Y, sample_weight=np.repeat(0.01, len(X)))
assert_array_almost_equal(dual_coef_no_weight, clf.dual_coef_)
示例9: test_svr
# 需要導入模塊: from sklearn import svm [as 別名]
# 或者: from sklearn.svm import NuSVR [as 別名]
def test_svr():
# Test Support Vector Regression
diabetes = datasets.load_diabetes()
for clf in (svm.NuSVR(kernel='linear', nu=.4, C=1.0),
svm.NuSVR(kernel='linear', nu=.4, C=10.),
svm.SVR(kernel='linear', C=10.),
svm.LinearSVR(C=10.),
svm.LinearSVR(C=10.),
):
clf.fit(diabetes.data, diabetes.target)
assert_greater(clf.score(diabetes.data, diabetes.target), 0.02)
# non-regression test; previously, BaseLibSVM would check that
# len(np.unique(y)) < 2, which must only be done for SVC
svm.SVR(gamma='scale').fit(diabetes.data, np.ones(len(diabetes.data)))
svm.LinearSVR().fit(diabetes.data, np.ones(len(diabetes.data)))
示例10: test_immutable_coef_property
# 需要導入模塊: from sklearn import svm [as 別名]
# 或者: from sklearn.svm import NuSVR [as 別名]
def test_immutable_coef_property():
# Check that primal coef modification are not silently ignored
svms = [
svm.SVC(kernel='linear').fit(iris.data, iris.target),
svm.NuSVC(kernel='linear').fit(iris.data, iris.target),
svm.SVR(kernel='linear').fit(iris.data, iris.target),
svm.NuSVR(kernel='linear').fit(iris.data, iris.target),
svm.OneClassSVM(kernel='linear').fit(iris.data),
]
for clf in svms:
assert_raises(AttributeError, clf.__setattr__, 'coef_', np.arange(3))
assert_raises((RuntimeError, ValueError),
clf.coef_.__setitem__, (0, 0), 0)
示例11: test_unfitted
# 需要導入模塊: from sklearn import svm [as 別名]
# 或者: from sklearn.svm import NuSVR [as 別名]
def test_unfitted():
X = "foo!" # input validation not required when SVM not fitted
clf = svm.SVC(gamma="scale")
assert_raises_regexp(Exception, r".*\bSVC\b.*\bnot\b.*\bfitted\b",
clf.predict, X)
clf = svm.NuSVR(gamma='scale')
assert_raises_regexp(Exception, r".*\bNuSVR\b.*\bnot\b.*\bfitted\b",
clf.predict, X)
# ignore convergence warnings from max_iter=1
示例12: setUpClass
# 需要導入模塊: from sklearn import svm [as 別名]
# 或者: from sklearn.svm import NuSVR [as 別名]
def setUpClass(self):
"""
Set up the unit test by loading the dataset and training a model.
"""
if not _HAS_SKLEARN:
return
self.scikit_model = NuSVR(kernel="linear")
self.data = load_boston()
self.scikit_model.fit(self.data["data"], self.data["target"])
示例13: test_conversion_bad_inputs
# 需要導入模塊: from sklearn import svm [as 別名]
# 或者: from sklearn.svm import NuSVR [as 別名]
def test_conversion_bad_inputs(self):
# Error on converting an untrained model
with self.assertRaises(TypeError):
model = NuSVR()
spec = scikit_converter.convert(model, "data", "out")
# Check the expected class during covnersion.
with self.assertRaises(TypeError):
model = OneHotEncoder()
spec = scikit_converter.convert(model, "data", "out")
示例14: test_convert_nusvr_default
# 需要導入模塊: from sklearn import svm [as 別名]
# 或者: from sklearn.svm import NuSVR [as 別名]
def test_convert_nusvr_default(self):
model, X = self._fit_binary_classification(NuSVR())
model_onnx = convert_sklearn(
model, "SVR", [("input", FloatTensorType([None, X.shape[1]]))])
self.assertIsNotNone(model_onnx)
dump_data_and_model(X, model, model_onnx, basename="SklearnRegNuSVR2")
示例15: test_objectmapper
# 需要導入模塊: from sklearn import svm [as 別名]
# 或者: from sklearn.svm import NuSVR [as 別名]
def test_objectmapper(self):
df = pdml.ModelFrame([])
self.assertIs(df.svm.SVC, svm.SVC)
self.assertIs(df.svm.LinearSVC, svm.LinearSVC)
self.assertIs(df.svm.NuSVC, svm.NuSVC)
self.assertIs(df.svm.SVR, svm.SVR)
self.assertIs(df.svm.NuSVR, svm.NuSVR)
self.assertIs(df.svm.OneClassSVM, svm.OneClassSVM)