Last active
November 22, 2020 09:08
-
-
Save ngmars/d05bc7f3dd3f143acddf12003676c1d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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