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


Python SubgradientSSVM.score方法代码示例

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


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

示例1: test_subgradient_svm_as_crf_pickling

# 需要导入模块: from pystruct.learners import SubgradientSSVM [as 别名]
# 或者: from pystruct.learners.SubgradientSSVM import score [as 别名]
def test_subgradient_svm_as_crf_pickling():

    iris = load_iris()
    X, y = iris.data, iris.target

    X_ = [(np.atleast_2d(x), np.empty((0, 2), dtype=np.int)) for x in X]
    Y = y.reshape(-1, 1)

    X_train, X_test, y_train, y_test = train_test_split(X_, Y, random_state=1)
    _, file_name = mkstemp()

    pbl = GraphCRF(n_features=4, n_states=3, inference_method='unary')
    logger = SaveLogger(file_name)
    svm = SubgradientSSVM(pbl, logger=logger, max_iter=100)
    svm.fit(X_train, y_train)

    assert_less(.97, svm.score(X_test, y_test))
    assert_less(.97, logger.load().score(X_test, y_test))
开发者ID:martinsch,项目名称:coulomb_ssvm,代码行数:20,代码来源:test_subgradient_svm.py

示例2: make_random_trees

# 需要导入模块: from pystruct.learners import SubgradientSSVM [as 别名]
# 或者: from pystruct.learners.SubgradientSSVM import score [as 别名]
def make_random_trees(n_samples=50, n_nodes=100, n_states=7, n_features=10):
    crf = GraphCRF(inference_method='max-product', n_states=n_states,
                   n_features=n_features)
    weights = np.random.randn(crf.size_joint_feature)
    X, y = [], []
    for i in range(n_samples):
        distances = np.random.randn(n_nodes, n_nodes)
        features = np.random.randn(n_nodes, n_features)
        tree = minimum_spanning_tree(sparse.csr_matrix(distances))
        edges = np.c_[tree.nonzero()]
        X.append((features, edges))
        y.append(crf.inference(X[-1], weights))

    return X, y, weights


X, y, weights = make_random_trees(n_nodes=1000)

X_train, X_test, y_train, y_test = train_test_split(X, y)

#tree_model = MultiLabelClf(edges=tree, inference_method=('ogm', {'alg': 'dyn'}))
tree_model = GraphCRF(inference_method='max-product')

tree_ssvm = SubgradientSSVM(tree_model, max_iter=4, C=1, verbose=10)

print("fitting tree model...")
tree_ssvm.fit(X_train, y_train)

print("Training loss tree model: %f" % tree_ssvm.score(X_train, y_train))
print("Test loss tree model: %f" % tree_ssvm.score(X_test, y_test))
开发者ID:DATAQC,项目名称:pystruct,代码行数:32,代码来源:random_tree_crf.py

示例3: print

# 需要导入模块: from pystruct.learners import SubgradientSSVM [as 别名]
# 或者: from pystruct.learners.SubgradientSSVM import score [as 别名]
print("Score with pystruct n-slack ssvm: %f (took %f seconds)"
      % (acc_n_slack, time_n_slack_svm))

## 1-slack cutting plane ssvm
start = time()
one_slack_svm.fit(X_train_bias, y_train)
time_one_slack_svm = time() - start
acc_one_slack = one_slack_svm.score(X_test_bias, y_test)
print("Score with pystruct 1-slack ssvm: %f (took %f seconds)"
      % (acc_one_slack, time_one_slack_svm))

# online subgradient ssvm
start = time()
subgradient_svm.fit(X_train_bias, y_train)
time_subgradient_svm = time() - start
acc_subgradient = subgradient_svm.score(X_test_bias, y_test)

print("Score with pystruct subgradient ssvm: %f (took %f seconds)"
      % (acc_subgradient, time_subgradient_svm))

libsvm = SVC(kernel='linear', C=10)
start = time()
libsvm.fit(X_train, y_train)
time_libsvm = time() - start
acc_libsvm = libsvm.score(X_test, y_test)
print("Score with sklearn and libsvm: %f (took %f seconds)"
      % (acc_libsvm, time_libsvm))

# plot the results
fig, ax = plt.subplots(1, 2, figsize=(10, 5))
ax[0].bar(range(4), [time_n_slack_svm, time_one_slack_svm,
开发者ID:DATAQC,项目名称:pystruct,代码行数:33,代码来源:plot_binary_svm.py


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