I have already done the 5* project of Machine learning where you have to create a model to predict if the messages are spam or are ham. I have created, and fit the Dense model. And it is working properly but now I have to create the function that passing the sms as a parameter , predict if it is spam or ham.
I will need your help because I am stuck without moving and I do not know how to solve the error.
Basically, when I create the method it is called passing just one message, and it is working, but the problem appears when I try to run the last cell with the test, because in that occasion, The message passed as a parameter are a tuple, and it is when the error shows.
These are my 2 last cells:
function to predict messages based on model
(should return list containing prediction and label, ex. [0.008318834938108921, ‘ham’])
padded =pad_sequences(new_sequences,maxlen=50, padding=“post”, truncating=“post”)
return (pred, var)
pred_text=[“how are you doing today?”]
When I run the cell, this is the output. But, later on, I have the issue in the next cell.
(array([[0.00122303]], dtype=float32), ‘ham’)
In this last cell, that I suposse to do not change is when I find the error:
Run this cell to test your function and model. Do not modify contents.
test_messages = [“how are you doing today”,
“sale today! to stop texts call 98912460324”,
“i dont want to go. can we try it a different day? available sat”,
“our new mobile video service is live. just install on your phone to start watching.”,
“you have won £1000 cash! call to claim your prize.”,
“i’ll bring it tomorrow. don’t forget the milk.”,
“wow, is your arm alright. that happened to me one time to” ]
test_answers = [“ham”, “spam”, “ham”, “spam”, “spam”, “ham”, “ham”]
passed = True
for msg, ans in zip(test_messages, test_answers):
prediction = predict_message(msg)
if prediction != ans:
passed = False
print(“You passed the challenge. Great job!”)
print(“You haven’t passed yet. Keep trying.”)
And I do not know how to solve this error without changing this last cell:
ValueError Traceback (most recent call last)
23 print(“You haven’t passed yet. Keep trying.”)
—> 25 test_predictions()
7 pred= np.array(model.predict(padded))
----> 8 if pred>=0.5:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()