komiya-atsushi / xgboost-predictor-java

Pure Java implementation of XGBoost predictor for online prediction tasks.
Apache License 2.0
339 stars 108 forks source link

When creating feature vector from dense representation by array, do you use the first element as the first feature or the label? #8

Open alaeddinms opened 8 years ago

alaeddinms commented 8 years ago

Hi,

When creating feature vector from dense representation by array, do you use the first element in the array for the first feature and the second for the second and so on or is the first element for the label as a placeholder?

Thanks,

komiya-atsushi commented 8 years ago

Hi,

This library don't provide any functions to handle labeled feature vector, so you should write & use code like below:

public class FVecFloatArrayWithLabel implements FVec {
    private final float[] values;
    private final boolean treatsZeroAsNA;

    FVecFloatArrayWithLabel(float[] values, boolean treatsZeroAsNA) {
        this.values = values;
        this.treatsZeroAsNA = treatsZeroAsNA;
    }

    @Override
    public double fvalue(int index) {
        if (values.length <= index + 1) {
            return Double.NaN;
        }

        double result = values[index + 1];
        if (treatsZeroAsNA && result == 0) {
            return Double.NaN;
        }

        return result;
    }
}