I have a model that I've trained using a sklearn Pipeline and the OneVsRestClassifier that I'm trying to deploy to Cloud ML Engine, however when I use the command:
gcloud ml-engine predict --model $MODEL_NAME --version $VERSION_NAME --json-instances $INPUT_FILE
I receive the error:
{
"error": "Prediction failed: Bad output type returned.The predict function should return either a numpy ndarray or a list."
}
This leads me to believe it is the fact that the OneVsRestClassifier's predict method output is a sparse matrix, when it should be a numpy array. How can I convert it's output to a dense array in my Pipeline?
The pipeline's architecture looks like this:
Pipeline([('tfidf', tfidf), ('clf', OneVsRestClassifier(XGBClassifier())])
Thanks!
I've tried using the methods here (Google Cloud ML-engine scikit-learn prediction probability 'predict_proba()') to overwrite the OneVsRestClassifier's predict method with it's predict_proba method, however this results in the following error when I try and pickle the new pipeline:
PicklingError: Can't pickle <function OneVsRestClassifier.predict_proba at 0x10a8f9d08>: it's not the same object as sklearn.multiclass.OneVsRestClassifier.predict_proba