当前位置: 首页>>代码示例>>Python>>正文


Python NSlackSSVM.predict方法代码示例

本文整理汇总了Python中pystruct.learners.NSlackSSVM.predict方法的典型用法代码示例。如果您正苦于以下问题:Python NSlackSSVM.predict方法的具体用法?Python NSlackSSVM.predict怎么用?Python NSlackSSVM.predict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pystruct.learners.NSlackSSVM的用法示例。


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

示例1: test_binary_blocks_cutting_plane

# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import predict [as 别名]
def test_binary_blocks_cutting_plane():
    #testing cutting plane ssvm on easy binary dataset
    # generate graphs explicitly for each example
    for inference_method in get_installed(["lp", "qpbo", "ad3", 'ogm']):
        X, Y = generate_blocks(n_samples=3)
        crf = GraphCRF(inference_method=inference_method)
        clf = NSlackSSVM(model=crf, max_iter=20, C=100, check_constraints=True,
                         break_on_bad=False, n_jobs=1)
        x1, x2, x3 = X
        y1, y2, y3 = Y
        n_states = len(np.unique(Y))
        # delete some rows to make it more fun
        x1, y1 = x1[:, :-1], y1[:, :-1]
        x2, y2 = x2[:-1], y2[:-1]
        # generate graphs
        X_ = [x1, x2, x3]
        G = [make_grid_edges(x) for x in X_]

        # reshape / flatten x and y
        X_ = [x.reshape(-1, n_states) for x in X_]
        Y = [y.ravel() for y in [y1, y2, y3]]

        X = list(zip(X_, G))

        clf.fit(X, Y)
        Y_pred = clf.predict(X)
        for y, y_pred in zip(Y, Y_pred):
            assert_array_equal(y, y_pred)
开发者ID:DATAQC,项目名称:pystruct,代码行数:30,代码来源:test_graph_svm.py

示例2: test_binary_blocks_batches_n_slack

# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import predict [as 别名]
def test_binary_blocks_batches_n_slack():
    #testing cutting plane ssvm on easy binary dataset
    X, Y = generate_blocks(n_samples=5)
    crf = GridCRF(inference_method=inference_method)
    clf = NSlackSSVM(model=crf, max_iter=20, batch_size=1, C=100)
    clf.fit(X, Y)
    Y_pred = clf.predict(X)
    assert_array_equal(Y, Y_pred)
开发者ID:DATAQC,项目名称:pystruct,代码行数:10,代码来源:test_n_slack_ssvm.py

示例3: test_multinomial_checker_cutting_plane

# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import predict [as 别名]
def test_multinomial_checker_cutting_plane():
    X, Y = generate_checker_multinomial(n_samples=10, noise=.1)
    n_labels = len(np.unique(Y))
    crf = GridCRF(n_states=n_labels, inference_method=inference_method)
    clf = NSlackSSVM(model=crf, max_iter=20, C=100000, check_constraints=True)
    clf.fit(X, Y)
    Y_pred = clf.predict(X)
    assert_array_equal(Y, Y_pred)
开发者ID:DATAQC,项目名称:pystruct,代码行数:10,代码来源:test_n_slack_ssvm.py

示例4: test_binary_blocks_batches_n_slack

# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import predict [as 别名]
def test_binary_blocks_batches_n_slack():
    #testing cutting plane ssvm on easy binary dataset
    X, Y = toy.generate_blocks(n_samples=5)
    crf = GridCRF()
    clf = NSlackSSVM(model=crf, max_iter=20, C=100, check_constraints=True,
                     break_on_bad=False, n_jobs=1, batch_size=1)
    clf.fit(X, Y)
    Y_pred = clf.predict(X)
    assert_array_equal(Y, Y_pred)
开发者ID:abhijitbendale,项目名称:pystruct,代码行数:11,代码来源:test_binary_grid.py

示例5: test_binary_blocks_cutting_plane

# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import predict [as 别名]
def test_binary_blocks_cutting_plane():
    #testing cutting plane ssvm on easy binary dataset
    X, Y = generate_blocks(n_samples=5)
    crf = GridCRF(inference_method=inference_method)
    clf = NSlackSSVM(model=crf, max_iter=20, C=100,
                     check_constraints=True, break_on_bad=False)
    clf.fit(X, Y)
    Y_pred = clf.predict(X)
    assert_array_equal(Y, Y_pred)
开发者ID:DATAQC,项目名称:pystruct,代码行数:11,代码来源:test_n_slack_ssvm.py

示例6: test_simple_1d_dataset_cutting_plane

# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import predict [as 别名]
def test_simple_1d_dataset_cutting_plane():
    # 10 1d datapoints between 0 and 1
    X = np.random.uniform(size=(30, 1))
    Y = (X.ravel() > 0.5).astype(np.int)
    # we have to add a constant 1 feature by hand :-/
    X = np.hstack([X, np.ones((X.shape[0], 1))])
    pbl = MultiClassClf(n_features=2)
    svm = NSlackSSVM(pbl, check_constraints=True, C=10000)
    svm.fit(X, Y)
    assert_array_equal(Y, np.hstack(svm.predict(X)))
开发者ID:DerThorsten,项目名称:pystruct,代码行数:12,代码来源:test_crammer_singer_svm.py

示例7: test_multinomial_blocks_cutting_plane

# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import predict [as 别名]
def test_multinomial_blocks_cutting_plane():
    #testing cutting plane ssvm on easy multinomial dataset
    X, Y = generate_blocks_multinomial(n_samples=40, noise=0.5, seed=0)
    n_labels = len(np.unique(Y))
    crf = GridCRF(n_states=n_labels, inference_method=inference_method)
    clf = NSlackSSVM(model=crf, max_iter=100, C=100, check_constraints=False,
                     batch_size=1)
    clf.fit(X, Y)
    Y_pred = clf.predict(X)
    assert_array_equal(Y, Y_pred)
开发者ID:DATAQC,项目名称:pystruct,代码行数:12,代码来源:test_n_slack_ssvm.py

示例8: test_binary_ssvm_attractive_potentials

# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import predict [as 别名]
def test_binary_ssvm_attractive_potentials():
    # test that submodular SSVM can learn the block dataset
    X, Y = generate_blocks(n_samples=10)
    crf = GridCRF(inference_method=inference_method)
    submodular_clf = NSlackSSVM(model=crf, max_iter=200, C=100,
                                check_constraints=True,
                                negativity_constraint=[5])
    submodular_clf.fit(X, Y)
    Y_pred = submodular_clf.predict(X)
    assert_array_equal(Y, Y_pred)
    assert_true(submodular_clf.w[5] < 0)
开发者ID:DATAQC,项目名称:pystruct,代码行数:13,代码来源:test_n_slack_ssvm.py

示例9: test_multinomial_blocks_directional

# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import predict [as 别名]
def test_multinomial_blocks_directional():
    # testing cutting plane ssvm with directional CRF on easy multinomial
    # dataset
    X, Y = toy.generate_blocks_multinomial(n_samples=10, noise=0.3, seed=0)
    n_labels = len(np.unique(Y))
    crf = DirectionalGridCRF(n_states=n_labels)
    clf = NSlackSSVM(model=crf, max_iter=100, C=100, verbose=0,
                     check_constraints=True, batch_size=1)
    clf.fit(X, Y)
    Y_pred = clf.predict(X)
    assert_array_equal(Y, Y_pred)
开发者ID:abhijitbendale,项目名称:pystruct,代码行数:13,代码来源:test_n_slack_ssvm.py

示例10: test_binary_ssvm_attractive_potentials

# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import predict [as 别名]
def test_binary_ssvm_attractive_potentials():
    # test that submodular SSVM can learn the block dataset
    X, Y = toy.generate_blocks(n_samples=10)
    crf = GridCRF()
    submodular_clf = NSlackSSVM(model=crf, max_iter=200, C=100,
                                check_constraints=True,
                                positive_constraint=[5])
    submodular_clf.fit(X, Y)
    Y_pred = submodular_clf.predict(X)
    assert_array_equal(Y, Y_pred)
    assert_true(submodular_clf.w[5] < 0)  # don't ask me about signs
开发者ID:abhijitbendale,项目名称:pystruct,代码行数:13,代码来源:test_binary_grid.py

示例11: CRF_oneNode

# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import predict [as 别名]
def CRF_oneNode(x_train, x_test, y_train, y_test):
    pbl = GraphCRF(n_states = 4,n_features=20)
    svm = NSlackSSVM(pbl,max_iter=200, C=10,n_jobs=2)
    
    svm.fit(x_train,y_train)
    y_pred = svm.predict(x_test)
    target_names = ['Start','Mid','End','Others']
    #eclf = EnsembleClassifier(clfs=[pipe1, pipe2],voting='soft',weights=[0.5,0.2])
    #eclf.fit(x_train,y_train)
    #y_pred = eclf.predict(x_test)
    print classification_report(y_test, y_pred, target_names=target_names)
开发者ID:wingsrc,项目名称:newsReports,代码行数:13,代码来源:model.py

示例12: test_multinomial_blocks_cutting_plane

# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import predict [as 别名]
def test_multinomial_blocks_cutting_plane():
    #testing cutting plane ssvm on easy multinomial dataset
    X, Y = toy.generate_blocks_multinomial(n_samples=10, noise=0.3,
                                           seed=0)
    n_labels = len(np.unique(Y))
    for inference_method in get_installed(['lp', 'qpbo', 'ad3']):
        crf = GridCRF(n_states=n_labels, inference_method=inference_method)
        clf = NSlackSSVM(model=crf, max_iter=10, C=100,
                         check_constraints=False)
        clf.fit(X, Y)
        Y_pred = clf.predict(X)
        assert_array_equal(Y, Y_pred)
开发者ID:aurora1625,项目名称:pystruct,代码行数:14,代码来源:test_multinomial_grid.py

示例13: test_simple_1d_dataset_cutting_plane

# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import predict [as 别名]
def test_simple_1d_dataset_cutting_plane():
    # 10 1d datapoints between 0 and 1
    X = np.random.uniform(size=(30, 1))
    # linearly separable labels
    Y = 1 - 2 * (X.ravel() < .5)
    # we have to add a constant 1 feature by hand :-/
    X = np.hstack([X, np.ones((X.shape[0], 1))])

    pbl = BinaryClf(n_features=2)
    svm = NSlackSSVM(pbl, check_constraints=True, C=1000)
    svm.fit(X, Y)
    assert_array_equal(Y, np.hstack(svm.predict(X)))
开发者ID:DerThorsten,项目名称:pystruct,代码行数:14,代码来源:test_binary_svm.py

示例14: test_binary_ssvm_repellent_potentials

# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import predict [as 别名]
def test_binary_ssvm_repellent_potentials():
    # test non-submodular problem with and without submodularity constraint
    # dataset is checkerboard
    X, Y = generate_checker()
    crf = GridCRF(inference_method=inference_method)
    clf = NSlackSSVM(model=crf, max_iter=10, C=100,
                     check_constraints=True)
    clf.fit(X, Y)
    Y_pred = clf.predict(X)
    # standard crf can predict perfectly
    assert_array_equal(Y, Y_pred)

    submodular_clf = NSlackSSVM(model=crf, max_iter=10, C=100,
                                check_constraints=True,
                                negativity_constraint=[4, 5, 6])
    submodular_clf.fit(X, Y)
    Y_pred = submodular_clf.predict(X)
    # submodular crf can not do better than unaries
    for i, x in enumerate(X):
        y_pred_unaries = crf.inference(x, np.array([1, 0, 0, 1, 0, 0, 0]))
        assert_array_equal(y_pred_unaries, Y_pred[i])
开发者ID:DATAQC,项目名称:pystruct,代码行数:23,代码来源:test_n_slack_ssvm.py

示例15: test_blobs_2d_cutting_plane

# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import predict [as 别名]
def test_blobs_2d_cutting_plane():
    # make two gaussian blobs
    X, Y = make_blobs(n_samples=80, centers=2, random_state=1)
    Y = 2 * Y - 1
    # we have to add a constant 1 feature by hand :-/
    X = np.hstack([X, np.ones((X.shape[0], 1))])
    X_train, X_test, Y_train, Y_test = X[:40], X[40:], Y[:40], Y[40:]

    pbl = BinaryClf(n_features=3)
    svm = NSlackSSVM(pbl, check_constraints=True, C=1000)

    svm.fit(X_train, Y_train)
    assert_array_equal(Y_test, np.hstack(svm.predict(X_test)))
开发者ID:DerThorsten,项目名称:pystruct,代码行数:15,代码来源:test_binary_svm.py


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