1

I am trying predict the output of test and train data using X_trainT and X_testT using predict() function. I'm getting below listed error -

yPredTrain = predict(X_trainT, parameters)   
yPredTest = predict(X_testT, parameters)    # This function is throwing the error

Predict function

def predict(X, parameters):
  W = parameters["W"]
  b = parameters["b"]
  W = W.reshape(X.shape[0], 1)
  #Z = np.dot(W.T,X) + b
  Z = np.dot(W.T,X) + b
  Y = np.array([1 if y > 0.5 else 0 for y in sigmoid(Z[0])]).reshape(1,len(Z[0]))
  #Y = np.array([1 if y > 0.5 else 0 for y in Z[0]]).reshape(1,len(Z[0]))
  return Y

Error

ValueError                                Traceback (most recent call last)
<ipython-input-20-a5c2d40ef32d> in <module>()
      1 yPredTrain = predict(X_trainT, parameters)   
----> 2 yPredTest = predict(X_testT, parameters)    

<ipython-input-9-dfb2f70a0c07> in predict(X, parameters)
      4   W = W.reshape(X.shape[0], 1)
      5   #Z = np.dot(W.T,X) + b
----> 6   Z = np.dot(W.T,X) + b
      7   Y = np.array([1 if y > 0.5 else 0 for y in sigmoid(Z[0])]).reshape(1,len(Z[0]))
      8   #Y = np.array([1 if y > 0.5 else 0 for y in Z[0]]).reshape(1,len(Z[0]))

ValueError: operands could not be broadcast together with shapes (1,143) (426,) ```
Community
  • 1
  • 1
  • Look at [that](https://stackoverflow.com/questions/22053050/difference-between-numpy-array-shape-r-1-and-r), I am pretty sure that this is the problem. – Yonlif May 31 '20 at 16:44

0 Answers0