6分钟
数据格式
1. xgboost 的数据存储在DMatrix 对象中
2. xgboost 支持直接从下列格式的文件中加载数据:
libsvm文本格式的文件。其格式为:
[label] [index1]:[value1] [index2]:[value2] ...
[label] [index1]:[value1] [index2]:[value2] ...
...dtrain = xgb.DMatrix('train.svm.txt') #libsvm 格式
dtest = xgb.DMatrix('test.svm.buffer') # xgboost binary buffer 文件3. xgboost 也支持从二维的numpy array 中加载数据
data = np.random.rand(5, 10)
label = np.random.randint(2, size=5)
dtrain = xgb.DMatrix(data, label=label)#从 numpy array 中加载4. 你也可以从scipy.sparse array 中加载数据
csr = scipy.sparse.csr_matrix((dat, (row, col)))
dtrain = xgb.DMatrix(csr)
学员评价