sci-kit learn: Reshape your data either using X.reshape(-1, 1)

后端 未结 6 1438
再見小時候
再見小時候 2021-02-04 20:56

I\'m training a python (2.7.11) classifier for text classification and while running I\'m getting a deprecated warning message that I don\'t know which line in my code is causin

相关标签:
6条回答
  • 2021-02-04 21:13

    If you want to find out where the Warning is coming from you can temporarly promote Warnings to Exceptions. This will give you a full Traceback and thus the lines where your program encountered the warning.

    with warnings.catch_warnings():
        warnings.simplefilter("error")
        main()
    

    If you run the program from the commandline you can also use the -W flag. More information on Warning-handling can be found in the python documentation.

    I know it is only one part of your question I answered but did you debug your code?

    0 讨论(0)
  • 2021-02-04 21:15

    Your 'vec' input into your clf.fit(vec,l).fit needs to be of type [[]], not just []. This is a quirk that I always forget when I fit models.

    Just adding an extra set of square brackets should do the trick!

    0 讨论(0)
  • 2021-02-04 21:15

    Predict method expects 2-d array , you can watch this video , i have also located the exact time https://youtu.be/KjJ7WzEL-es?t=2602 .You have to change from [] to [[]].

    0 讨论(0)
  • 2021-02-04 21:20

    It's:

    pred = clf.predict(vec);
    

    I used this in my code and it worked:

    #This makes it into a 2d array
    temp =  [2 ,70 ,90 ,1] #an instance
    temp = np.array(temp).reshape((1, -1))
    print(model.predict(temp))
    
    0 讨论(0)
  • 2021-02-04 21:29

    2 solution: philosophy___make your data from 1D to 2D

    1. Just add: []

      vec = [vec]
      
    2. Reshape your data

      import numpy as np
      vec = np.array(vec).reshape(1, -1)
      
    0 讨论(0)
  • 2021-02-04 21:32

    Since 1D array would be deprecated. Try passing 2D array as a parameter. This might help.

    clf = joblib.load('model.pkl') 
    pred = clf.predict([vec]);
    
    0 讨论(0)
提交回复
热议问题