def main():
	X = []
	Xte = []
	#5485 is the number of unique words -1
	featureNo = 5485
	
	# step 1: processing the data.
	populateData(X,"trainingData.txt",featureNo)
	populateData(Xte,"testingData.txt",featureNo)
	Y =[]
	Yte = []
	# get the labels for the data
	getLabel(Y,"graphics-windows-train.megam","train.basebal.hockey.megam")
	getLabel(Yte,"graphics-windows-test.megam","test.baseball.hockey.megam")
	
	# test
	h = linear.LinearClassifier({'lossFunction': linear.SquaredLoss(), 'lambda': 0, 'numIter': 100, 'stepSize': 0.5})
	runClassifier.trainTest(h, X, Y, Xte, Yte)
	print h
# WU 2 ##########
f = lambda x: sin(pi*x) + x**2/2
derF = lambda x: pi*cos(pi*x) + x
# x = linspace(-5, 5, 500)
# plot(x, f(x), 'b-')
# plot(-0.4538, f(-0.4538), 'r*') #plot the global min
# title('f(x) = sin(x*pi) + x^2/2')

x_global, t = gd.gd(f, derF, 0, 10, 0.2)
x_local, t = gd.gd(f, derF, 1, 10, 0.2)

##########

#For linear
import linear
h = linear.LinearClassifier({'lossFunction': linear.SquaredLoss(), 'lambda': 0, 'numIter': 100, 'stepSize': 0.5})


runClassifier.trainTestSet(h, datasets.TwoDAxisAligned)

X = datasets.TwoDAxisAligned.X
Y = datasets.TwoDAxisAligned.Y

#mlGraphics.plotLinearClassifier(h, X, Y)

h = linear.LinearClassifier({'lossFunction': linear.SquaredLoss(), 'lambda': 10, 'numIter': 100, 'stepSize': 0.5})
runClassifier.trainTestSet(h, datasets.TwoDAxisAligned)


h = linear.LinearClassifier({'lossFunction': linear.SquaredLoss(), 'lambda': 10, 'numIter': 100, 'stepSize': 0.5})
runClassifier.trainTestSet(h, datasets.TwoDDiagonal)
Exemple #3
0
import runClassifier
import datasets
import linear

# ----------------------
# WU5 FIND TOP 5 weights
# ----------------------

print "SquaredLoss"
s = linear.LinearClassifier({
    'lossFunction': linear.SquaredLoss(),
    'lambda': 1,
    'numIter': 100,
    'stepSize': 0.5
})
runClassifier.trainTestSet(s, datasets.WineDataBinary)

print "\n----------------------------------------------------\n"
print "LogisticLoss"
l = linear.LinearClassifier({
    'lossFunction': linear.LogisticLoss(),
    'lambda': 1,
    'numIter': 100,
    'stepSize': 0.5
})
runClassifier.trainTestSet(l, datasets.WineDataBinary)

print "\n----------------------------------------------------\n"
print "HingeLoss"
h = linear.LinearClassifier({
    'lossFunction': linear.HingeLoss(),