本文整理汇总了Python中shogun.Features.SparseRealFeatures.obtain_from_simple方法的典型用法代码示例。如果您正苦于以下问题:Python SparseRealFeatures.obtain_from_simple方法的具体用法?Python SparseRealFeatures.obtain_from_simple怎么用?Python SparseRealFeatures.obtain_from_simple使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shogun.Features.SparseRealFeatures
的用法示例。
在下文中一共展示了SparseRealFeatures.obtain_from_simple方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: classifier_svmlin_modular
# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def classifier_svmlin_modular (fm_train_real=traindat,fm_test_real=testdat,label_train_twoclass=label_traindat,C=0.9,epsilon=1e-5,num_threads=1):
from shogun.Features import RealFeatures, SparseRealFeatures, BinaryLabels
from shogun.Classifier import SVMLin
realfeat=RealFeatures(fm_train_real)
feats_train=SparseRealFeatures()
feats_train.obtain_from_simple(realfeat)
realfeat=RealFeatures(fm_test_real)
feats_test=SparseRealFeatures()
feats_test.obtain_from_simple(realfeat)
labels=BinaryLabels(label_train_twoclass)
svm=SVMLin(C, feats_train, labels)
svm.set_epsilon(epsilon)
svm.parallel.set_num_threads(num_threads)
svm.set_bias_enabled(True)
svm.train()
svm.set_features(feats_test)
svm.get_bias()
svm.get_w()
svm.apply().get_labels()
predictions = svm.apply()
return predictions, svm, predictions.get_labels()
示例2: svmlin
# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def svmlin ():
print 'SVMLin'
from shogun.Features import RealFeatures, SparseRealFeatures, Labels
from shogun.Classifier import SVMLin
realfeat=RealFeatures(fm_train_real)
feats_train=SparseRealFeatures()
feats_train.obtain_from_simple(realfeat)
realfeat=RealFeatures(fm_test_real)
feats_test=SparseRealFeatures()
feats_test.obtain_from_simple(realfeat)
C=0.9
epsilon=1e-5
num_threads=1
labels=Labels(label_train_twoclass)
svm=SVMLin(C, feats_train, labels)
svm.set_epsilon(epsilon)
svm.parallel.set_num_threads(num_threads)
svm.set_bias_enabled(True)
svm.train()
svm.set_features(feats_test)
svm.get_bias()
svm.get_w()
svm.classify().get_labels()
示例3: compute_output_plot_isolines
# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def compute_output_plot_isolines(classifier, kernel=None, train=None, sparse=False, pos=None, neg=None, regression=False):
size=100
if pos is not None and neg is not None:
x1_max=max(1.2*pos[0,:])
x1_min=min(1.2*neg[0,:])
x2_min=min(1.2*neg[1,:])
x2_max=max(1.2*pos[1,:])
x1=linspace(x1_min, x1_max, size)
x2=linspace(x2_min, x2_max, size)
else:
x1=linspace(-5, 5, size)
x2=linspace(-5, 5, size)
x, y=meshgrid(x1, x2)
dense=RealFeatures(array((ravel(x), ravel(y))))
if sparse:
test=SparseRealFeatures()
test.obtain_from_simple(dense)
else:
test=dense
if kernel and train:
kernel.init(train, test)
else:
classifier.set_features(test)
labels = None
if regression:
labels=classifier.apply().get_labels()
else:
labels=classifier.apply().get_confidences()
z=labels.reshape((size, size))
return x, y, z
示例4: subgradient_svm
# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def subgradient_svm ():
print 'SubGradientSVM'
from shogun.Features import RealFeatures, SparseRealFeatures, Labels
from shogun.Classifier import SubGradientSVM
realfeat=RealFeatures(fm_train_real)
feats_train=SparseRealFeatures()
feats_train.obtain_from_simple(realfeat)
realfeat=RealFeatures(fm_test_real)
feats_test=SparseRealFeatures()
feats_test.obtain_from_simple(realfeat)
C=0.9
epsilon=1e-3
num_threads=1
max_train_time=1.
labels=Labels(label_train_twoclass)
svm=SubGradientSVM(C, feats_train, labels)
svm.set_epsilon(epsilon)
svm.parallel.set_num_threads(num_threads)
svm.set_bias_enabled(False)
svm.set_max_train_time(max_train_time)
svm.train()
svm.set_features(feats_test)
svm.classify().get_labels()
示例5: classify
# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def classify (true_labels):
num_feats=2
num_vec=true_labels.get_num_labels()
data_train=numpy.concatenate(
(numpy.random.randn(num_feats, num_vec/2)-1,
numpy.random.randn(num_feats, num_vec/2)+1),
axis=1)
realfeat=RealFeatures(data_train)
feats_train=SparseRealFeatures()
feats_train.obtain_from_simple(realfeat)
C=3.
svm=SVMOcas(C, feats_train, true_labels)
svm.train()
data_test=numpy.concatenate(
(numpy.random.randn(num_feats, num_vec/2)-1,
numpy.random.randn(num_feats, num_vec/2)+1),
axis=1)
realfeat=RealFeatures(data_test)
feats_test=SparseRealFeatures()
feats_test.obtain_from_simple(realfeat)
svm.set_features(feats_test)
return numpy.array(svm.classify().get_labels())
示例6: svmsgd
# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def svmsgd ():
print 'SVMSGD'
from shogun.Features import RealFeatures, SparseRealFeatures, Labels
from shogun.Classifier import SVMSGD
realfeat=RealFeatures(fm_train_real)
feats_train=SparseRealFeatures()
feats_train.obtain_from_simple(realfeat)
realfeat=RealFeatures(fm_test_real)
feats_test=SparseRealFeatures()
feats_test.obtain_from_simple(realfeat)
C=0.9
num_threads=1
num_iter=5
labels=Labels(label_train_twoclass)
svm=SVMSGD(C, feats_train, labels)
svm.set_epochs(num_iter)
#svm.io.set_loglevel(0)
svm.train()
svm.set_features(feats_test)
labelPrediction = svm.classify().get_labels()
print labelPrediction>0
示例7: distance_sparseeuclidean_modular
# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def distance_sparseeuclidean_modular (fm_train_real=traindat,fm_test_real=testdat):
from shogun.Features import RealFeatures, SparseRealFeatures
from shogun.Distance import SparseEuclidianDistance
realfeat=RealFeatures(fm_train_real)
feats_train=SparseRealFeatures()
feats_train.obtain_from_simple(realfeat)
realfeat=RealFeatures(fm_test_real)
feats_test=SparseRealFeatures()
feats_test.obtain_from_simple(realfeat)
distance=SparseEuclidianDistance(feats_train, feats_train)
dm_train=distance.get_distance_matrix()
distance.init(feats_train, feats_test)
dm_test=distance.get_distance_matrix()
return distance,dm_train,dm_test
示例8: sparse_euclidian_distance
# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def sparse_euclidian_distance ():
print 'SparseEuclidianDistance'
from shogun.Features import RealFeatures, SparseRealFeatures
from shogun.Distance import SparseEuclidianDistance
realfeat=RealFeatures(fm_train_real)
feats_train=SparseRealFeatures()
feats_train.obtain_from_simple(realfeat)
realfeat=RealFeatures(fm_test_real)
feats_test=SparseRealFeatures()
feats_test.obtain_from_simple(realfeat)
distance=SparseEuclidianDistance(feats_train, feats_train)
dm_train=distance.get_distance_matrix()
distance.init(feats_train, feats_test)
dm_test=distance.get_distance_matrix()
示例9: classifier_svmsgd_modular
# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def classifier_svmsgd_modular (fm_train_real=traindat,fm_test_real=testdat,label_train_twoclass=label_traindat,C=0.9,num_threads=1,num_iter=5):
from shogun.Features import RealFeatures, SparseRealFeatures, Labels
from shogun.Classifier import SVMSGD
realfeat=RealFeatures(fm_train_real)
feats_train=SparseRealFeatures()
feats_train.obtain_from_simple(realfeat)
realfeat=RealFeatures(fm_test_real)
feats_test=SparseRealFeatures()
feats_test.obtain_from_simple(realfeat)
labels=Labels(label_train_twoclass)
svm=SVMSGD(C, feats_train, labels)
svm.set_epochs(num_iter)
#svm.io.set_loglevel(0)
svm.train()
svm.set_features(feats_test)
svm.apply().get_labels()
predictions = svm.apply()
return predictions, svm, predictions.get_labels()
示例10: classifier_subgradientsvm_modular
# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def classifier_subgradientsvm_modular(fm_train_real, fm_test_real, label_train_twoclass, C, epsilon, max_train_time):
from shogun.Features import RealFeatures, SparseRealFeatures, Labels
from shogun.Classifier import SubGradientSVM
realfeat = RealFeatures(fm_train_real)
feats_train = SparseRealFeatures()
feats_train.obtain_from_simple(realfeat)
realfeat = RealFeatures(fm_test_real)
feats_test = SparseRealFeatures()
feats_test.obtain_from_simple(realfeat)
labels = Labels(label_train_twoclass)
svm = SubGradientSVM(C, feats_train, labels)
svm.set_epsilon(epsilon)
svm.set_max_train_time(max_train_time)
svm.train()
svm.set_features(feats_test)
labels = svm.apply().get_labels()
return labels, svm
示例11: svmsgd
# 需要导入模块: from shogun.Features import SparseRealFeatures [as 别名]
# 或者: from shogun.Features.SparseRealFeatures import obtain_from_simple [as 别名]
def svmsgd ():
print 'SVMSGD'
from shogun.Features import RealFeatures, SparseRealFeatures, Labels
from shogun.Classifier import SVMSGD
realfeat=RealFeatures(fm_train_real)
feats_train=SparseRealFeatures()
feats_train.obtain_from_simple(realfeat)
realfeat=RealFeatures(fm_test_real)
feats_test=SparseRealFeatures()
feats_test.obtain_from_simple(realfeat)
C=0.9
epsilon=1e-5
num_threads=1
labels=Labels(label_train_twoclass)
svm=SVMSGD(C, feats_train, labels)
#svm.io.set_loglevel(0)
svm.train()
svm.set_features(feats_test)
svm.classify().get_labels()