Last answered:

11 Jan 2024

Posted on:

30 Dec 2022

0

ValueError: X has 1460 features, but MultinomialNB is expecting 3925 features as input

kindly help

7 answers ( 0 marked as helpful)
Instructor
Posted on:

03 Jan 2023

0

Hey Amira,

Thank you for reaching out!

Could you please share a screenshot of your code together with the error?

Kind regards,
365 Hristina

Posted on:

09 Jan 2024

0

img1

Posted on:

09 Jan 2024

0

img2

Posted on:

09 Jan 2024

0

img3

Posted on:

09 Jan 2024

0

Hey Hristina,

It worked for me before. But now it is also showing the same error. I looked for workaround, I didn't find any. I've attached 3 images of the code. I hope you can identify the reason. In my opinion, there is something to do with the version. Mine is latest version.

Thank you.

Instructor
Posted on:

10 Jan 2024

1

Hey Tulasi,


Thank you for reaching out.


Note that the following line of code

x_test_transf = vectorizer.fit_transform(x_test)

should instead read

x_test_transf = vectorizer.transform(x_test)

This should solve the problem, however, let me know if you encounter other issues.


Kind regards,

365 Hristina

 

 

Posted on:

11 Jan 2024

1

It solved the problem. I missed the point that we have to fit it only on training data. I really like the way you identify the mistakes. Thank you.!

Submit an answer