|
|
|
@ -81,7 +81,7 @@ class MultiClassPerceptron:
|
|
|
|
|
|
|
|
|
|
|
|
This model also shuffles the training data after each epoch.
|
|
|
|
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 epochs: int
|
|
|
|
:type learning_rate: float
|
|
|
|
: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)
|
|
|
|
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)
|
|
|
|
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
|
|
|
|
# Training Iterations
|
|
|
|
for epoch in range(self.epochs):
|
|
|
|
for epoch in range(self.epochs):
|
|
|
|
|
|
|
|
|
|
|
|
if epoch >= next_print:
|
|
|
|
print('Training Epoch :: (', (epoch+1), '/', self.epochs, ')')
|
|
|
|
print('Training Multi-Class Perceptron Classifier..... (', epoch, '/', self.epochs, ')')
|
|
|
|
|
|
|
|
next_print = next_print + int(self.epochs/10)
|
|
|
|
for i in range(train_len):
|
|
|
|
|
|
|
|
|
|
|
|
# Pick a number from random list
|
|
|
|
# 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
|
|
|
|
perceptron_scores = [] # list for storing perceptron scores for each label
|
|
|
|
for label, perceptron in self.perceptron_dict.items():
|
|
|
|
for label, perceptron in self.perceptron_dict.items():
|
|
|
|
|