def findNuMuLinearClass(self, batchsize, k):

		k=5

		data = Data(k, 0, 0)
		data.importDataFromMat()
		data.normalize()

		error_fig = plt.figure()
		ax1 = error_fig.add_subplot(111)

		for nu in [0.05, 0.1] :
			for mu in [0.05, 0.1] :
				lg = LogisticLinearClassifier(nu, mu, 576, k, data)
				err_train, miss_train, err_val, miss_val = lg.train(30)
				label1 = "validation error mu="+str(mu)+" nu="+str(nu)
				label2 = "training error mu="+str(mu)+" nu="+str(nu)
				ax1.plot(err_train, label=label1)
				ax1.plot(err_val, label=label2)
		
		
		ax1.set_ylabel('error')
		ax1.set_xlabel('epoch')

		title = "Validation and training errors"
		error_fig.suptitle(title)

		plt.legend()
예제 #2
0
def testLogisticError():
    k = 5

    data = Data(k, 0, 0)
    data.importDataFromMat()
    data.normalize()

    lg = LogisticLinearClassifier(0.03, 0.03, 576, k, data)
    err_train, miss_train, err_val, miss_val = lg.train(30)
    mis_fig = plt.figure()
    ax2 = mis_fig.add_subplot(111)
    ax2.plot(err_val, label="error (validation)")
    ax2.plot(err_train, label="error (training)")
    title = "std(val)=%f std(err)=%f" % (sp.std(err_val), sp.std(err_train))
    mis_fig.suptitle(title)
    ax2.set_ylabel("error")
    ax2.set_xlabel("epoch")
    plt.legend()

    mis_fig = plt.figure()
    ax2 = mis_fig.add_subplot(111)
    ax2.plot(miss_val, label="misclassification ratio (validation)")
    ax2.plot(miss_train, label="misclassification ratio (training)")
    mis_fig.suptitle(title)
    ax2.set_ylabel("misclassification ratio")
    ax2.set_xlabel("epoch")
    plt.legend()

    results, cat = lg.classify(data.test_left, data.test_right)
    lg.confusion_matrix(cat, data.test_cat.argmax(axis=0))

    err = Error()
    err, misclass = err.norm_total_error(results.T, data.test_cat, k)
    print "Error on the test set " + str(err)
    print "Misclassification ratio on the test set " + str(misclass)