<commit_before>#!/usr/bin/python
import sys
import numpy as np
import scipy.sparse
# append the path to xgboost, you may need to change the following line
sys.path.append('../')
import xgboost as xgb

### simple example
# load file from text file, also binary buffer generated by xgboost
dtrain = xgb.DMatrix('agaricus.txt.train')
dtest = xgb.DMatrix('agaricus.txt.test')

# specify parameters via map, definition are same as c++ version
param = {'bst:max_depth':2, 'bst:eta':1, 'silent':1, 'objective':'binary:logistic' }

# specify validations set to watch performance
evallist  = [(dtest,'eval'), (dtrain,'train')]
num_round = 2
bst = xgb.train( param, dtrain, num_round, evallist )

# this is prediction
preds = bst.predict( dtest )
labels = dtest.get_label()
print 'error=%f' % (  sum(1 for i in xrange(len(preds)) if int(preds[i]>0.5)!=labels[i]) /float(len(preds)))
bst.save_model('0001.model')
# dump model
bst.dump_model('dump.raw.txt')
# dump model with feature map
bst.dump_model('dump.raw.txt','featmap.txt')

# beta: interact mode
bst.set_param('bst:interact:expand',4)
bst.update_interact( dtrain, 'update', 0)
bst.dump_model('dump.raw2.txt')

###
# build dmatrix in python iteratively
#
print 'start running example of build DMatrix in python'
dtrain = xgb.DMatrix()
labels = []<commit_msg>Update demo.py<commit_after>#!/usr/bin/python
import sys
import numpy as np
import scipy.sparse
# append the path to xgboost, you may need to change the following line
sys.path.append('../')
import xgboost as xgb

### simple example
# load file from text file, also binary buffer generated by xgboost
dtrain = xgb.DMatrix('agaricus.txt.train')
dtest = xgb.DMatrix('agaricus.txt.test')

# specify parameters via map, definition are same as c++ version
param = {'bst:max_depth':2, 'bst:eta':1, 'silent':1, 'objective':'binary:logistic' }

# specify validations set to watch performance
evallist  = [(dtest,'eval'), (dtrain,'train')]
num_round = 2
bst = xgb.train( param, dtrain, num_round, evallist )

# this is prediction
preds = bst.predict( dtest )
labels = dtest.get_label()
print 'error=%f' % (  sum(1 for i in xrange(len(preds)) if int(preds[i]>0.5)!=labels[i]) /float(len(preds)))
bst.save_model('0001.model')
# dump model
bst.dump_model('dump.raw.txt')
# dump model with feature map
bst.dump_model('dump.raw.txt','featmap.txt')

###
# build dmatrix in python iteratively
#
print 'start running example of build DMatrix in python'
dtrain = xgb.DMatrix()
labels = []
{'fraction_non_alphanumeric': 0.14585858585858585, 'fraction_numerical': 0.010101010101010102, 'mean_word_length': 5.397932816537468, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5287866', 'n_tokens_mistral': 874, 'n_tokens_neox': 852, 'n_words': 252}