Sci-kit Learn: Reshape Your Data Either Using X.reshape(-1, 1)
Solution 1:
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!
Solution 2:
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))
Solution 3:
2 solution: philosophy___make your data from 1D to 2D
Just add:
[]
vec = [vec]
Reshape your data
import numpy as npvec= np.array(vec).reshape(1, -1)
Solution 4:
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?
Solution 5:
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]);
Post a Comment for "Sci-kit Learn: Reshape Your Data Either Using X.reshape(-1, 1)"