Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with given features matrices #13

Open
dripp1 opened this issue Dec 30, 2016 · 3 comments
Open

Usage with given features matrices #13

dripp1 opened this issue Dec 30, 2016 · 3 comments
Labels

Comments

@dripp1
Copy link

dripp1 commented Dec 30, 2016

Hi,

Your implementation looks promising, but I am not sure how to use it.
Suppose we have age, gender and height(in cm) and we need to predict the weight (in kg) of people.

So we have for training set the following csv:
age,gender,height,weight
18,m,180,80
40,m,175,85
25,f,165,50

and we load it into a feature matrix:

float[][] trainFeatures =  new float[][] {
 { 18, 1, 180 },
 { 40, 1, 175 },
 { 25, 0, 165 }
}

and into a vector of target values:
float[] targets = new float[] { 80, 85, 50 }

and we also have a test set for which we need to predict the target values:
22,m,175
30,f,160

which we load into a feature matrix:

float[][] testFeatures =  new float[][] {
 { 22, 1, 175 },
 { 30, 0, 160 }
}

Can you please give an example of how the xgboost-predictor can be applied to such data to train on the first set and predict on the second set?

Thank you

Doron

@komiya-atsushi
Copy link
Owner

Hi,

You cannot use xgboost-predictor to build a model but you can use to predict.
xgboost-predictor provides only prediction functions.

If you want to build a model on JVM, you should use XGBoost4J.

To predict weight using xgboost-predictor, you should:

  • Load XGBoost model using Predictor class.
  • Represent a feature vector using FVec interface.
Predictor predictor = new Predictor(
  new java.io.FileInputStream("/path/to/xgboost-model-file"));

for (float[] f : testFeatures) {
  FVec fv = FVec.Transformer.fromArray(f, false /* do not treat zero element as N/A */);
  double[] prediction = predictor.predict(fv);
  double predictedWeight = prediction[0];
}

@dripp1
Copy link
Author

dripp1 commented Feb 6, 2017

Thank you for your answer.
I was hoping to use this project INSTEAD of XGBoost4J and not depending on it...

@WokoLiu
Copy link

WokoLiu commented Jun 28, 2020

@komiya-atsushi hi, I'm interested in this api. Why this library use for loop to predict each feature instead of just predicting once with a matrix? Will this be faster? If true, will it keep faster if the size of testFeatures is very big?
I'm new about this library, just for interesting, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants