Skip to content

Instantly share code, notes, and snippets.

@ngmars
Last active November 22, 2020 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngmars/b0f639ca25bf93ee7a7812d9d2837833 to your computer and use it in GitHub Desktop.
Save ngmars/b0f639ca25bf93ee7a7812d9d2837833 to your computer and use it in GitHub Desktop.
import joblib
import multiprocessing as mp
clf.fit(y_train, X_train)
weight = 'new_model.sav'
joblib.dump(clf, weight)
#define a function and pass your parameters
def predict(A):
y_test=A
y_test=np.asarray(y_test)
X_pred_prob = loaded_model.predict_proba(y_test)
prediction= loaded_binarizer.inverse_transform(X_pred_new)
print(prediction)
#make sure you return the vaule, this would help you create the API
return(A,prediction)
def mainPredict(Arr):
# if Arr =[1,2,3,4,5,6] and each value is an input parameter to predict
#initialize pool
pool = mp.Pool(mp.cpu_count())
#map array elements to the predict function
result = pool.map(predict, Arr)
#close the pool
pool.close()
return(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment