Solve project 5 question 5.
parent
8f80129f4e
commit
17ff044b6d
|
@ -42,12 +42,18 @@ class PerceptronClassifierPacman(PerceptronClassifier):
|
|||
|
||||
|
||||
def train( self, trainingData, trainingLabels, validationData, validationLabels ):
|
||||
self.features = trainingData[0][0]['Stop'].keys() # could be useful later
|
||||
# DO NOT ZERO OUT YOUR WEIGHTS BEFORE STARTING TRAINING, OR
|
||||
# THE AUTOGRADER WILL LIKELY DEDUCT POINTS.
|
||||
self.features = trainingData[0][0]['Stop'].keys()
|
||||
|
||||
for iteration in range(self.max_iterations):
|
||||
print "Starting iteration ", iteration, "..."
|
||||
for i in range(len(trainingData)):
|
||||
"*** YOUR CODE HERE ***"
|
||||
util.raiseNotDefined()
|
||||
datum, legalMoves = trainingData[i]
|
||||
expectedLabel = trainingLabels[i]
|
||||
vectors = util.Counter()
|
||||
for l in legalMoves:
|
||||
vectors[l] = self.weights * datum[l] #changed from datum to datum[l]
|
||||
guessedLabel = vectors.argMax()
|
||||
if expectedLabel != guessedLabel:
|
||||
self.weights += datum[expectedLabel]
|
||||
self.weights -= datum[guessedLabel]
|
||||
|
||||
|
|
Loading…
Reference in New Issue