def fit(self, trainingData, trainingLabels):
"""
Trains the classifier by collecting counts over the training data, and
stores the Laplace smoothed estimates so that they can be used to classify.
trainingData is a list of feature dictionaries. The corresponding
label lists contain the correct label for each instance.
To get the list of all possible features or labels, use self.features and self.legalLabels.
"""
self.features = trainingData[0].keys() # the names of the features in the dataset
self.prior = util.Counter() # probability over labels
self.conditionalProb = util.Counter() # Conditional probability of feature feat for a given class having value v
# HINT: could be indexed by (feat, label, value)
# TODO:
# construct (and store) the normalized smoothed priors and conditional probabilities
"*** YOUR CODE HERE ***"
评论列表
文章目录