Support instance weights for xgboost4j-spark (#2642)

* Support instance weights for xgboost4j-spark

* Use 0.001 instead of 0 for weights

* Address CR comments
This commit is contained in:
Yun Ni
2017-08-28 09:03:20 -07:00
committed by Nan Zhu
parent ba16475c3a
commit a00157543d
4 changed files with 42 additions and 11 deletions

View File

@@ -63,12 +63,14 @@ class DataBatch {
float[] label = new float[numRows];
int[] featureIndex = new int[numElem];
float[] featureValue = new float[numElem];
float[] weight = new float[numRows];
int offset = 0;
for (int i = 0; i < batch.size(); i++) {
LabeledPoint labeledPoint = batch.get(i);
rowOffset[i] = offset;
label[i] = labeledPoint.label();
weight[i] = labeledPoint.weight();
if (labeledPoint.indices() != null) {
System.arraycopy(labeledPoint.indices(), 0, featureIndex, offset,
labeledPoint.indices().length);
@@ -84,7 +86,7 @@ class DataBatch {
}
rowOffset[batch.size()] = offset;
return new DataBatch(rowOffset, null, label, featureIndex, featureValue);
return new DataBatch(rowOffset, weight, label, featureIndex, featureValue);
}
@Override