當前位置: 首頁>>代碼示例>>Python>>正文


Python svm.NuSVR方法代碼示例

本文整理匯總了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])) 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:27,代碼來源:test_gradient_boosting.py

示例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_) 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:20,代碼來源:test_svm.py

示例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) 
開發者ID:apple,項目名稱:coremltools,代碼行數:27,代碼來源:_NuSVR.py

示例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") 
開發者ID:onnx,項目名稱:sklearn-onnx,代碼行數:21,代碼來源:test_sklearn_svm_converters.py

示例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')"
        ) 
開發者ID:onnx,項目名稱:sklearn-onnx,代碼行數:19,代碼來源:test_sklearn_svm_converters.py

示例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')"
        ) 
開發者ID:onnx,項目名稱:sklearn-onnx,代碼行數:19,代碼來源:test_sklearn_svm_converters.py

示例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))) 
開發者ID:alvarobartt,項目名稱:twitter-stock-recommendation,代碼行數:19,代碼來源:test_svm.py

示例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_) 
開發者ID:alvarobartt,項目名稱:twitter-stock-recommendation,代碼行數:20,代碼來源:test_svm.py

示例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))) 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:19,代碼來源:test_svm.py

示例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) 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:15,代碼來源:test_svm.py

示例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 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:15,代碼來源:test_svm.py

示例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"]) 
開發者ID:apple,項目名稱:coremltools,代碼行數:12,代碼來源:test_NuSVR.py

示例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") 
開發者ID:apple,項目名稱:coremltools,代碼行數:12,代碼來源:test_NuSVR.py

示例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") 
開發者ID:onnx,項目名稱:sklearn-onnx,代碼行數:8,代碼來源:test_sklearn_svm_converters.py

示例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) 
開發者ID:pandas-ml,項目名稱:pandas-ml,代碼行數:10,代碼來源:test_svm.py


注:本文中的sklearn.svm.NuSVR方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。