epochs logic changed - old commit

isaac
Pavan Mandava 6 years ago
parent d888673d00
commit 05ccf02bb2

@ -81,7 +81,7 @@ class MultiClassPerceptron:
This model also shuffles the training data after each epoch.
"""
def __init__(self, epochs: int = 5000, learning_rate: float = 1.0, random_state: int = 42):
def __init__(self, epochs: int = 5, learning_rate: float = 1.0, random_state: int = 42):
"""
:type epochs: int
:type learning_rate: float
@ -127,20 +127,15 @@ class MultiClassPerceptron:
sample_weights = get_sample_weights_with_features(theta_bias=-0.25, random_state=self.random_state)
self.perceptron_dict[label] = Perceptron(label, sample_weights, theta_bias=-0.25)
next_print = int(self.epochs/10)
random.seed(self.random_state)
random_list = [random.randint(0, train_len-1) for i in range(self.epochs)]
# Training Iterations
for epoch in range(self.epochs):
if epoch >= next_print:
print('Training Multi-Class Perceptron Classifier..... (', epoch, '/', self.epochs, ')')
next_print = next_print + int(self.epochs/10)
print('Training Epoch :: (', (epoch+1), '/', self.epochs, ')')
for i in range(train_len):
# Pick a number from random list
inst = X_train[random_list[epoch]]
inst = X_train[i]
perceptron_scores = [] # list for storing perceptron scores for each label
for label, perceptron in self.perceptron_dict.items():

@ -18,10 +18,10 @@ labels = set([inst.true_label for inst in X_train_inst])
X_test_inst = read_csv_file(test_file_path, '\t')
# number of training iterations
epochs = int(len(X_train_inst)*1.5)
epochs = 50
# create MultiClassPerceptron classifier object
clf = MultiClassPerceptron(epochs=epochs, learning_rate=0.75, random_state=101)
clf = MultiClassPerceptron(epochs=epochs, learning_rate=0.5, random_state=101)
# train the model
clf.fit(X_train=X_train_inst, labels=list(labels))

Loading…
Cancel
Save