|
|
|
@ -126,9 +126,15 @@ class MultiClassPerceptron:
|
|
|
|
for label in labels:
|
|
|
|
for label in labels:
|
|
|
|
self.perceptron_dict[label] = Perceptron(label, get_sample_weights_with_features(-0.5), -0.5)
|
|
|
|
self.perceptron_dict[label] = Perceptron(label, get_sample_weights_with_features(-0.5), -0.5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next_print = int(self.epochs/10)
|
|
|
|
|
|
|
|
|
|
|
|
# Training Iterations
|
|
|
|
# Training Iterations
|
|
|
|
for epoch in range(self.epochs):
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
# get a random number within the size of training set
|
|
|
|
# get a random number within the size of training set
|
|
|
|
rand_num = random.randint(0, train_len-1)
|
|
|
|
rand_num = random.randint(0, train_len-1)
|
|
|
|
# pick a random data instance with the generated random number
|
|
|
|
# pick a random data instance with the generated random number
|
|
|
|
@ -169,6 +175,8 @@ class MultiClassPerceptron:
|
|
|
|
if X_test is None or len(X_test) <= 0:
|
|
|
|
if X_test is None or len(X_test) <= 0:
|
|
|
|
raise Exception('Testing Data cannot be empty')
|
|
|
|
raise Exception('Testing Data cannot be empty')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print('Predicting..... ')
|
|
|
|
|
|
|
|
|
|
|
|
y_test = []
|
|
|
|
y_test = []
|
|
|
|
labels = list(self.perceptron_dict.keys())
|
|
|
|
labels = list(self.perceptron_dict.keys())
|
|
|
|
for test_inst in X_test:
|
|
|
|
for test_inst in X_test:
|
|
|
|
|