python - faster way to use the scikit-learn trained model -
i have trained prediction model using scikit-learn, , used pickle
save hard drive. pickle
file 58m, quite sizable.
to use model, wrote this:
def loadmodel(pkl_fn): open(pkl_fn, 'r') f: return pickle.load(f) if __name__ == "__main__": import sys feature_vals = read_features(sys.argv[1]) model = loadmodel("./model.pkl") # predict # model.predict(feature_vals)
i wondering efficiency when running program many times in command line.
pickle files supposed fast load, there way speed up? can compile whole thing binary executable?
if worried loading time, can use joblib.dump
, joblib.load
, more efficient pickle in case of scikit-learn.
for full (pretty straightforward) example see the docs or related answer ogrisel: save classifier disk in scikit-learn
Comments
Post a Comment