Merge pull request #106 from tqchen/master

pull master into unity
This commit is contained in:
Tianqi Chen
2014-11-21 08:56:01 -08:00
11 changed files with 106 additions and 23 deletions

View File

@@ -7,6 +7,10 @@ Python
* To make the python module, type ```make``` in the root directory of project
* Refer also to the walk through example in [demo folder](../demo/guide-python)
R
R
=====
* See [R-package](../R-package)
Julia
=====
* See [XGBoost.jl](https://github.com/antinucleon/XGBoost.jl)

View File

@@ -436,7 +436,11 @@ def train(params, dtrain, num_boost_round = 10, evals = [], obj=None, feval=None
for i in range(num_boost_round):
bst.update( dtrain, i, obj )
if len(evals) != 0:
sys.stderr.write(bst.eval_set(evals, i, feval).decode()+'\n')
bst_eval_set=bst.eval_set(evals, i, feval)
if isinstance(bst_eval_set,str):
sys.stderr.write(bst_eval_set+'\n')
else:
sys.stderr.write(bst_eval_set.decode()+'\n')
return bst
class CVPack:
@@ -467,7 +471,7 @@ def mknfold(dall, nfold, param, seed, evals=[], fpreproc = None):
dtrain, dtest, tparam = fpreproc(dtrain, dtest, param.copy())
else:
tparam = param
plst = tparam.items() + [('eval_metric', itm) for itm in evals]
plst = list(tparam.items()) + [('eval_metric', itm) for itm in evals]
ret.append(CVPack(dtrain, dtest, plst))
return ret
@@ -481,12 +485,16 @@ def aggcv(rlist, show_stdv=True):
arr = line.split()
assert ret == arr[0]
for it in arr[1:]:
if not isinstance(it,str):
it=it.decode()
k, v = it.split(':')
if k not in cvmap:
cvmap[k] = []
cvmap[k].append(float(v))
for k, v in sorted(cvmap.items(), key = lambda x:x[0]):
v = np.array(v)
if not isinstance(ret,str):
ret = ret.decode()
if show_stdv:
ret += '\tcv-%s:%f+%f' % (k, np.mean(v), np.std(v))
else:

View File

@@ -132,6 +132,7 @@ extern "C"{
bst_ulong nrow,
bst_ulong ncol,
float missing) {
bool nan_missing = std::isnan(missing);
DMatrixSimple *p_mat = new DMatrixSimple();
DMatrixSimple &mat = *p_mat;
mat.info.info.num_row = nrow;
@@ -139,9 +140,13 @@ extern "C"{
for (bst_ulong i = 0; i < nrow; ++i, data += ncol) {
bst_ulong nelem = 0;
for (bst_ulong j = 0; j < ncol; ++j) {
if (data[j] != missing) {
mat.row_data_.push_back(RowBatch::Entry(j, data[j]));
++nelem;
if (std::isnan(data[j])) {
utils::Check(nan_missing, "There are NAN in the matrix, however, you did not set missing=NAN");
} else {
if (nan_missing || data[j] != missing) {
mat.row_data_.push_back(RowBatch::Entry(j, data[j]));
++nelem;
}
}
}
mat.row_ptr_.push_back(mat.row_ptr_.back() + nelem);

View File

@@ -6,7 +6,6 @@
* \brief a C style wrapper of xgboost
* can be used to create wrapper of other languages
*/
#include <cstdio>
#ifdef _MSC_VER
#define XGB_DLL __declspec(dllexport)
#else
@@ -15,8 +14,9 @@
// manually define unsign long
typedef unsigned long bst_ulong;
#ifdef __cplusplus
extern "C" {
#endif
/*!
* \brief load a data matrix
* \return a loaded data matrix
@@ -205,5 +205,7 @@ extern "C" {
*/
XGB_DLL const char **XGBoosterDumpModel(void *handle, const char *fmap,
bst_ulong *out_len);
#ifdef __cplusplus
}
#endif
#endif // XGBOOST_WRAPPER_H_