#!/usr/bin/python
import numpy as np
import scipy.sparse
import pickle
import xgboost as xgb

### simple example
# load file from text file, also binary buffer generated by xgboost
dtrain = xgb.DMatrix('./data/train_20min_att_libsvm.txt')
dtest = xgb.DMatrix('./data/test_20min_att_libsvm.txt')
dsubmit = xgb.DMatrix('./data/submit_20min_att_libsvm.txt')
comb_data = xgb.DMatrix('./data/comb_20min_att_linsvm.txt')

# specify parameters via map, definition are same as c++ version
param = {'max_depth':5, 'eta':0.021, 'silent':1, 'objective':'reg:linear', 'colsample_bytree':0.9}

# specify validations set to watch performance
watchlist  = [(dtest,'eval'), (dtrain,'train')]
num_round = 105
bst = xgb.train(param, dtrain, num_round, watchlist)
# this is prediction
#preds = bst.predict(dtest)
preds = bst.predict(dsubmit)
np.savetxt('preds425.csv', preds, delimiter = ',') 
#labels = dtest.get_label()
#mape = 0
#for i in range(len(preds)):
#    mape+=abs((preds[i]-labels[i])/labels[i]) 
#mape = mape/float(len(preds)) 
#print ('mape=%f' % mape)