本文整理汇总了Python中pystruct.learners.NSlackSSVM.fit方法的典型用法代码示例。如果您正苦于以下问题:Python NSlackSSVM.fit方法的具体用法?Python NSlackSSVM.fit怎么用?Python NSlackSSVM.fit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pystruct.learners.NSlackSSVM
的用法示例。
在下文中一共展示了NSlackSSVM.fit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_binary_blocks_cutting_plane
# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import fit [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)
示例2: test_logging
# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import fit [as 别名]
def test_logging():
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=inference_method)
logger = SaveLogger(file_name)
svm = NSlackSSVM(pbl, C=100, n_jobs=1, logger=logger)
svm.fit(X_train, y_train)
score_current = svm.score(X_test, y_test)
score_auto_saved = logger.load().score(X_test, y_test)
alt_file_name = file_name + "alt"
logger.save(svm, alt_file_name)
logger.file_name = alt_file_name
logger.load()
score_manual_saved = logger.load().score(X_test, y_test)
assert_less(.97, score_current)
assert_less(.97, score_auto_saved)
assert_less(.97, score_manual_saved)
assert_almost_equal(score_auto_saved, score_manual_saved)
示例3: test_binary_blocks_batches_n_slack
# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import fit [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)
示例4: test_multinomial_checker_cutting_plane
# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import fit [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)
示例5: test_binary_blocks_batches_n_slack
# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import fit [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)
示例6: test_binary_blocks_cutting_plane
# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import fit [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)
示例7: test_simple_1d_dataset_cutting_plane
# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import fit [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)))
示例8: test_multinomial_blocks_cutting_plane
# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import fit [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)
示例9: test_binary_ssvm_attractive_potentials
# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import fit [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)
示例10: test_multinomial_blocks_directional
# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import fit [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)
示例11: test_binary_ssvm_attractive_potentials
# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import fit [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
示例12: CRF_oneNode
# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import fit [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)
示例13: test_simple_1d_dataset_cutting_plane
# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import fit [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)))
示例14: test_multinomial_blocks_cutting_plane
# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import fit [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)
示例15: test_blobs_2d_cutting_plane
# 需要导入模块: from pystruct.learners import NSlackSSVM [as 别名]
# 或者: from pystruct.learners.NSlackSSVM import fit [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)))