本文整理匯總了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))
示例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))
示例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,