0

i am trying to find a predicted Y value (output is numerical) with x inputs using strings (eg. Business type, Department and Region). After using this :

print(model.predict([['Finance and Control'], ['EMEA'], ['Professional Services']]))

it returned this error : AttributeError: 'numpy.ndarray' object has no attribute 'predict'

import pickle
model = pickle.load(open('model3.pkl','rb'))
print(model.predict([['Finance and Control'], ['EMEA'], ['Professional Services']]))

Sample array after OHE

pppery
  • 3,731
  • 22
  • 33
  • 46
Vincent Teo
  • 43
  • 1
  • 9
  • potentially useful : https://datascience.stackexchange.com/questions/25673/attributeerror-numpy-ndarray-object-has-no-attribute-predict – Derek Eden Sep 09 '19 at 02:59

1 Answers1

0

I ran into a similar issue as this, though without additional context, I'm not sure our errors derive from the same problem. However, the resolution I arrived at may help someone in the future as they go down the SO rabbit hole.

Using sklearn-0.20,

import joblib
model = joblib.load('model.pkl')
model.predict(previously_loaded_data)

Resulted in

AttributeError: 'numpy.ndarray' object has no attribute 'predict'

However, the following allowed me to load the actual model and use its predict method:

from sklearn.externals import joblib
model = joblib.load('model.pkl')
model.predict(previously_loaded_data)

sklearn.externals.joblib is deprecated since sklearn-0.23+, but my use case required sklearn-0.20.

Dharman
  • 30,962
  • 25
  • 85
  • 135