示例#1
0
def qda(train_features, train_labels, test_featues, test_labels):
	from modshogun import QDA, MulticlassAccuracy

	qda = QDA(train_features, train_labels)
	qda.train()

	train_output = qda.apply()
	test_output = qda.apply(test_features)
	evaluator = MulticlassAccuracy()
	print 'QDA training error is %.4f' % ((1-evaluator.evaluate(train_output, train_labels))*100)
	print 'QDA test error is %.4f' % ((1-evaluator.evaluate(test_output, test_labels))*100)
示例#2
0
def qda(train_features, train_labels, test_featues, test_labels):
    from modshogun import QDA, MulticlassAccuracy

    qda = QDA(train_features, train_labels)
    qda.train()

    train_output = qda.apply()
    test_output = qda.apply(test_features)
    evaluator = MulticlassAccuracy()
    print 'QDA training error is %.4f' % (
        (1 - evaluator.evaluate(train_output, train_labels)) * 100)
    print 'QDA test error is %.4f' % (
        (1 - evaluator.evaluate(test_output, test_labels)) * 100)
def classifier_qda_modular (train_fname=traindat, test_fname=testdat, label_fname=label_traindat, tolerance=1e-4, store_covs=False):
	try:
		from modshogun import RealFeatures, MulticlassLabels, QDA, CSVFile
	except ImportError:
		return

	feats_train=RealFeatures(CSVFile(train_fname))
	feats_test=RealFeatures(CSVFile(test_fname))
	labels=MulticlassLabels(CSVFile(label_fname))

	qda = QDA(feats_train, labels, tolerance, store_covs)
	qda.train()

	qda.apply(feats_test).get_labels()
	qda.set_features(feats_test)
	return qda, qda.apply().get_labels()
示例#4
0
def classifier_qda_modular(train_fname=traindat,
                           test_fname=testdat,
                           label_fname=label_traindat,
                           tolerance=1e-4,
                           store_covs=False):
    try:
        from modshogun import RealFeatures, MulticlassLabels, QDA, CSVFile
    except ImportError:
        return

    feats_train = RealFeatures(CSVFile(train_fname))
    feats_test = RealFeatures(CSVFile(test_fname))
    labels = MulticlassLabels(CSVFile(label_fname))

    qda = QDA(feats_train, labels, tolerance, store_covs)
    qda.train()

    qda.apply(feats_test).get_labels()
    qda.set_features(feats_test)
    return qda, qda.apply().get_labels()
	pylab.contour(xx, yy, Z, linewidths = 3, colors = 'k')

# Number of classes
M = 3
# Number of samples of each class
N = 300
# Dimension of the data
dim = 2

cols = ['blue', 'green', 'red']

fig = pylab.figure()
ax  = fig.add_subplot(111)
pylab.title('Quadratic Discrimant Analysis')

X, y = gen_data()

labels = MulticlassLabels(y)
features = RealFeatures(X.T)
qda = QDA(features, labels, 1e-4, True)
qda.train()
ypred = qda.apply().get_labels()

plot_data(qda, X, y, ypred, ax)
for i in range(M):
	plot_cov(ax, qda.get_mean(i), qda.get_cov(i), cols[i])
plot_regions(qda)

pylab.connect('key_press_event', util.quit)
pylab.show()
示例#6
0
文件: qda.py 项目: zhqanddcy/shogun
qda.set_labels(labels)
qda.train(features)

# compute output plot iso-lines
xs = np.array(np.concatenate([x_pos, x_neg]))
ys = np.array(np.concatenate([y_pos, y_neg]))

x1_max = max(1.2*xs)
x1_min = min(1.2*xs)
x2_max = max(1.2*ys)
x2_min = min(1.2*ys)

x1 = np.linspace(x1_min, x1_max, size)
x2 = np.linspace(x2_min, x2_max, size)

x, y = np.meshgrid(x1, x2)

dense = RealFeatures( np.array((np.ravel(x), np.ravel(y))) )
dense_labels = qda.apply(dense).get_labels()

z = dense_labels.reshape((size, size))

pcolor(x, y, z)
contour(x, y, z, linewidths = 1, colors = 'black', hold = True)

axis([x1_min, x1_max, x2_min, x2_max])

connect('key_press_event', util.quit)

show()
示例#7
0

# Number of classes
M = 3
# Number of samples of each class
N = 300
# Dimension of the data
dim = 2

cols = ['blue', 'green', 'red']

fig = pylab.figure()
ax = fig.add_subplot(111)
pylab.title('Quadratic Discrimant Analysis')

X, y = gen_data()

labels = MulticlassLabels(y)
features = RealFeatures(X.T)
qda = QDA(features, labels, 1e-4, True)
qda.train()
ypred = qda.apply().get_labels()

plot_data(qda, X, y, ypred, ax)
for i in range(M):
    plot_cov(ax, qda.get_mean(i), qda.get_cov(i), cols[i])
plot_regions(qda)

pylab.connect('key_press_event', util.quit)
pylab.show()