Ejemplo n.º 1
0
def lda ():
	print 'LDA'

	from shogun.Features import RealFeatures, Labels
	from shogun.Classifier import LDA

	feats_train=RealFeatures(fm_train_real)
	feats_test=RealFeatures(fm_test_real)

	gamma=3
	num_threads=1
	labels=Labels(label_train_twoclass)

	lda=LDA(gamma, feats_train, labels)
	lda.train()	

	lda.get_bias()
	lda.get_w()
	
	#lda.set_features(feats_train)
	result = lda.classify()
	prediction_labels = result.get_labels()
	print prediction_labels>0
	
	lda.set_features(feats_test)
	result = lda.classify()
	prediction_labels = result.get_labels()
	print prediction_labels>0
Ejemplo n.º 2
0
def classifier_lda_modular (fm_train_real=traindat,fm_test_real=testdat,label_train_twoclass=label_traindat,gamma=3,num_threads=1):
	from shogun.Features import RealFeatures, Labels
	from shogun.Classifier import LDA

	feats_train=RealFeatures(fm_train_real)
	feats_test=RealFeatures(fm_test_real)

	labels=Labels(label_train_twoclass)

	lda=LDA(gamma, feats_train, labels)
	lda.train()

	lda.get_bias()
	lda.get_w()
	lda.set_features(feats_test)
	lda.apply().get_labels()
	return lda,lda.apply().get_labels()
Ejemplo n.º 3
0
def classifier_lda_modular(fm_train_real=traindat,
                           fm_test_real=testdat,
                           label_train_twoclass=label_traindat,
                           gamma=3,
                           num_threads=1):
    from shogun.Features import RealFeatures, Labels
    from shogun.Classifier import LDA

    feats_train = RealFeatures(fm_train_real)
    feats_test = RealFeatures(fm_test_real)

    labels = Labels(label_train_twoclass)

    lda = LDA(gamma, feats_train, labels)
    lda.train()

    lda.get_bias()
    lda.get_w()
    lda.set_features(feats_test)
    lda.classify().get_labels()
    return lda, lda.classify().get_labels()
Ejemplo n.º 4
0
Archivo: prc.py Proyecto: frx/shogun
util.set_title('PRC example')
util.DISTANCE=0.5
subplots_adjust(hspace=0.3)

pos=util.get_realdata(True)
neg=util.get_realdata(False)
features=util.get_realfeatures(pos, neg)
labels=util.get_labels()

# classifiers
gk=GaussianKernel(features, features, 1.0)
svm = LibSVM(1000.0, gk, labels)
svm.train()
lda=LDA(1,features,labels)
lda.train()

## plot points
subplot(211)
plot(pos[0,:], pos[1,:], "r.")
plot(neg[0,:], neg[1,:], "b.")
grid(True)
title('Data',size=10)

# plot PRC for SVM
subplot(223)
PRC_evaluation=PRCEvaluation()
PRC_evaluation.evaluate(svm.classify(),labels)
PRC = PRC_evaluation.get_PRC()
plot(PRC[:,0], PRC[:,1])
fill_between(PRC[:,0],PRC[:,1],0,alpha=0.1)