I want to insert the string into the machine learning model, but it keeps saying this:
prediction = model.predict(email_features_array)
^^^^^^^^^^^^^
AttributeError: 'numpy.ndarray' object has no attribute 'predict'
I don’t know what the problem is, I changed the decoding method several times.
This is the function I’m using after I do vectorzation:
def predict():
email_text ="hello world"
cv = CountVectorizer()
email_features_array = cv.fit_transform([email_text])
# email_features_array = fit_count_vectorizer(email_text)
print(email_features_array)
# Assume `model` is already defined and trained
prediction = model.predict(email_features_array)
# Apply the pre-trained model to predict the probability of the email being phishing
probability = model.predict_proba(email_features_array)
if prediction[0] == 1:
result = 'Phishing'
probability_score = probability[0][1] * 100
print(result, probability_score)
else:
result = 'Legitimate'
probability_score = probability[0][0] * 100
print(result, probability_score)
I expect that there is a problem with how I decode it but not sure.
1