Skip to content

Instantly share code, notes, and snippets.

@ngmars
Last active November 22, 2020 09:08
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/d05bc7f3dd3f143acddf12003676c1d9 to your computer and use it in GitHub Desktop.
Save ngmars/d05bc7f3dd3f143acddf12003676c1d9 to your computer and use it in GitHub Desktop.
import joblib
import multiprocessing as mp
from joblib import load
#add the path of the file you wish to load
filename= './new_model.sav'
#your models weights are now stored in the variable loaded model
loaded_model = load("new_model.sav")
#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.apply(predict, args=(A))for A in 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