Functions in MP Neuron Class

Hello,

The video in which Pratyush Sir had made a class for MP Neuron Model, he used many functions which i couldn’t understand.

The class is given below:

class MPNeuron:
 
def __init__(self):
 self.b = None

def model(self, x):
 return(sum(x) >= self.b)

def predict(self, X):
Y = []
for x in X:
  result = self.model(x)
  Y.append(result)
return np.array(Y)

def fit(self, X, Y):
accuracy = {}

for b in range(X.shape[1] + 1):
  self.b = b
  Y_pred = self.predict(X)
  accuracy[b] = accuracy_score(Y_pred, Y)
  
best_b = max(accuracy, key = accuracy.get)
self.b = best_b

print('Optimal value of b is', best_b)
print('Highest accuracy is', accuracy[best_b])

Please explain the functions.

–Bilal

init is constructor which initializes bias.

model method is our learning model (MP Neuron) which gives output for given input.

fit method is used to fit parameter values of the model by training it with training data features X and its corresponding label Y.

predict method is used to make predictions preferably on test data set X (It uses model method on each data point.).

1 Like

Took me a bit of digging trying to understand that.

Thanks :slight_smile:

1 Like