GUVI
Back

ERROR while running code

Created 2 years ago
44 Views
2 Comments
SatwikAgrawal
@SatwikAgrawal
SatwikAgrawal
@SatwikAgrawalProfile is locked. Login

i tried to copy lectures code but after that also it is showing the error

my code -

class perceptron:

  def init(self):

    self.b=None

    self.w=None


  def model(self,x):    return 1 if (np.dot(self.w,x)>=self.b) else 0 
  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,epochs=2):    

self.w= np.ones(X.shape[1])   

 self.b=0   

 accuracy=dict({})  

  for i in range(epochs):

for x,y in zip(X,Y):

        y_pred=self.model(x)

        if y==1 and y_pred==0:

          self.w+=x# earlier self.w+=x 

          self.b+=1 #earlier self.b+=1

        if y==0 and y_pred==1:

          self.w-=x 

          self.b-=1

      accuracy[i] = acc_s(self.predict(X) ,Y)



    plt.plot(accuracy.values())    

plt.show() 

TypeError                                 Traceback (most recent call last)
<ipython-input-69-5fbd7b440ee5> in <module>()
----> 1 Perceptron.fit(x_train,y_train,5)


8 frames


/usr/local/lib/python3.7/dist-packages/numpy/core/_asarray.py in asarray(a, dtype, order)
     81 
     82     """
---> 83     return array(a, dtype, copy=False, order=order)
     84 
     85 

TypeError: float() argument must be a string or a number, not 'dict_values'

SEARCH STACK OVERFLOW


Comments (2)
Please login to comment.
 
Powered by habitate.io Habitate