Skip to content

Instantly share code, notes, and snippets.

@spencercarter
Last active January 28, 2018 18:21
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 spencercarter/7f3ddcb4cbb11e73e14ecad6f62a5f8d to your computer and use it in GitHub Desktop.
Save spencercarter/7f3ddcb4cbb11e73e14ecad6f62a5f8d to your computer and use it in GitHub Desktop.
Sample code to create silent permission failure in xgboost 0.4
import xgboost as xgb
import numpy as np
from subprocess import call
# Initialize
X = np.random.normal(size=[10, 5])
y = np.random.randint(0,2,10)
dtrain = xgb.DMatrix(X, label=y)
# Model
param = {'max_depth':2, 'eta':1, 'silent':1, 'objective':'binary:logistic' }
num_round = 2
bst = xgb.train(param, dtrain, num_round)
print("Original Predictions: {}".format(bst.predict(dtrain)))
# Save and remove permissions
bst.save_model('my_booster.model')
call(['chmod','000', 'my_booster.model'])
# Load model into a new booster
bst2 = xgb.Booster()
bst2.load_model('my_booster.model')
print("Predictions reading from 000 mod file: {}".format(bst2.predict(dtrain)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment