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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user