Skip to content

Instantly share code, notes, and snippets.

@braz
Created February 28, 2019 15:40
Show Gist options
  • Save braz/8e9b2c8bf25319260b2c2893949dae19 to your computer and use it in GitHub Desktop.
Save braz/8e9b2c8bf25319260b2c2893949dae19 to your computer and use it in GitHub Desktop.
Simple example for saving the model to GridFS
import datetime
import gridfs
import pickle
import pymongo
from bson.binary import Binary
# Copy and paste the model here from https://gist.github.com/braz/8a65ffc359fd9f208c1e8ca64b7dfac3
model_name = str(type(model))
model_name = model_name[8:-2]
model_created_at = datetime.datetime.utcnow()
mongo = pymongo.MongoClient("localhost:27017")
grid_db = mongo.grid
fs = gridfs.GridFS(grid_db)
model_id = fs.put(pickle.dumps(model), model_type=model_name, model_created_at=model_created_at, model_param=model.get_xgb_params(), accuracy=accuracy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment