sklearn LinearSVC - X has 1 features per sample; expecting 5

后端 未结 1 1117
悲哀的现实
悲哀的现实 2021-01-05 04:02

I\'m trying to predict the class of a test array, but I\'m getting the below error, along with the stack trace:

Traceback (most recent call last):
  File \"/         


        
相关标签:
1条回答
  • 2021-01-05 04:29

    The variable test is a string - the SVC needs a feature vector with the same number of dimensions as X. You have to transform the test string to a feature vector using the same vectorizer instance, before you feed it to the SVC:

    X_test=tvect.transform(test)
    classifier.predict(X_test)
    
    0 讨论(0)
提交回复
热议问题