def train(): global W,alpha, N, EPOCHS, MAX_TRAIN example = get_train() num_iter = 0 num_cor = 0 while True: if num_iter >= MAX_TRAIN * EPOCHS / 10: break num_iter += 1 [sentence, author] = example x = numpy.mat (get_feature_vector (sentence)) d = mat_author (author) Y = W * x W += alpha * (d - Y) * (x.transpose()) """ dawg = get_best (Y) if get_best (Y) == author: num_cor += 1 print dawg """ example = get_train()
def train_bayes(): global MAX_TRAIN, freq, word_count example = get_train() num_iter = 0 while True: if num_iter >= MAX_TRAIN: break num_iter += 1 [sentence, author] = example words = sentence for word in words: if word not in freq[author]: # this code is ugly freq[author][word] = 0 freq[author][word] += 1 example = get_train() for author in authors: word_count[author] = sum([freq[author][key] for key in freq[author]]) + 0.0
def train_bayes(): global MAX_TRAIN, freq, word_count example = get_train() num_iter = 0 while True: if num_iter >= MAX_TRAIN: break num_iter += 1 [sentence, author] = example for word in sentence: if word not in freq[author]: # there should be a better way to do this freq[author][word] = 0 freq[author][word] += 1 example = get_train() for author in authors: word_count[author] = sum([freq[author][key] for key in freq[author]]) + 0.0