Skip to content

Instantly share code, notes, and snippets.

@pplonski
Created October 2, 2017 15:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pplonski/05ff99985269200cdc4854ddc04fa6e9 to your computer and use it in GitHub Desktop.
Save pplonski/05ff99985269200cdc4854ddc04fa6e9 to your computer and use it in GitHub Desktop.
Reading models from mljar and using locally
import os
import numpy as np
import lightgbm as lgb
# directory with your models
dir_with_models = './tmp'
# 100 samples of random data (with 70 columns), just for testing
X = np.random.rand(100, 70)
pred = None
for f in os.listdir(dir_with_models):
print('Using {0}'.format(f))
# read model
model = lgb.Booster(model_file = os.path.join(dir_with_models,f))
# compute predictions
pred = model.predict(X) if pred is None else pred + model.predict(X)
# get average of predictions from all models
pred = pred/float(len(os.listdir(dir_with_models)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment