Class MPNeuron, TypeError: unsupported operand type(s) for +: 'int' and 'str'

I did same as Pratyush Sir did in the videos. But unable to figure out why getting this error?
I am pretty sure there is some problem in return from model part. How the types are different? How to resolve it?

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

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

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

    def fit(self,X,Y):
        for b in range(X.shape[1]+1):
            Y_pred = self.predict(X)
        best_b=max(accuracy,key=accuracy.get)  # "key" argument gives max value among all keys of dictionary accuracy
        self.b = best_b
        print('Optimal value of b is',best_b)
        print('Highest accuracy is',accuracy[best_b])
TypeError                                 Traceback (most recent call last)
<ipython-input-74-2b7a9f6f4b30> in <module>()
      1 mp_neuron=MPNeuron()
----> 2,Y_train)

2 frames
<ipython-input-71-4271ceb4004c> in model(self, x)
      5     def model(self,x):
----> 6         return(sum(x) >= self.b)
      8     def predict(self,x):

TypeError: unsupported operand type(s) for +: 'int' and 'str'

What is the type of X_train_binarised? Is it dataframe or numpy array?
Try this before calling fit

X_train_binarised = X_train_binarised.values

If this works, remember you will have to do the same for X_test_binarised as well. (Look for notebook from lectures, where they do it)

If above doesn’t work, you can share google colab link to your code here.

type(X_train_binarised) is numpy.ndarray.
Link to code:

I cannot access it, its asking for permission. Can you make the link available to all for now?

As I am new to Google Colaboratory, can you tell me how to do it?

You click ‘Share’ (top right), then you choose Get link.
There you can choose Anyone with the link and then share the link.

This is the problem code:

def predict(self,x):
    for x in X:

In predict function, parameter is incorrectly specified as small x instead of capital X.
Try again, after changing to:

def predict(self, X)

Yeah it worked.
I don’t know how I got wrong there. I was wondering for so much time to catch a mistake.
Anyways, Thank You so much.

1 Like

Please help me out with the same problem :

I’m not able to open the notebook using this link

Convert X and Y to numpy arrays (from pandas dataframe/series) using following code.


You can insert it before call to function 'train_test_split'

Yes it worked , Thank you