K.Sudha Snigdha
K.Sudha Snigdha

Reputation: 19

Updating list of lists is happening for just one iteration but not in further iterations in Perceptron algorithm ML

Below is my code of multi-class perceptron algorithm. Here I am trying to update the weight vector given by list of lists - weights.

The logic is correct, it executes correctly for 1 iteration. The weights list of lists is initialized with all 0's. In the first iteration, the weights list is updated, but however in the further iterations, the list is not getting updated. I don't understand what am I doing it wrongly? Please help. Thanks

Code: **

import numpy as np
data = open("mnist_data_training.csv",'r')
weights = [[0 for _ in range(784)] for _ in range(10)]
for _ in range(0,3):
    for row in data:
        lst_row = (row.rstrip('\n').split(','))
        list_row = lst_row[:-1]
        if (max_weight_index != (lst_row[784])):
            weights[lst_row[784]] = np.add(weights[lst_row[784]],list_row) **# Updating weight vector here**
            weights[max_weight_index] = numpy.subtract(weights[max_weight_index],list_row) **#Updating weight vector here**

GitHub link - https://github.com/sudhakosuri/Multi-Class-Perceptron.git

Upvotes: 0

Views: 57

Answers (1)

K.Sudha Snigdha
K.Sudha Snigdha

Reputation: 19

Using filepointer.seek() at the beginning of the iteration has solved the issue.

Upvotes: 0

Related Questions