oracle / tribuo

Tribuo - A Java machine learning library
https://tribuo.org
Apache License 2.0
1.27k stars 175 forks source link

How do we unpack a DimensionTuple? #108

Closed neomatrix369 closed 3 years ago

neomatrix369 commented 3 years ago

Ask the question I'm trying to unpack the prediction results after calling model.predict(data), I get a ArrayList of Prediction items.

Each Prediction item in my case is of type Regressor.DimensionTuple, there is a getOutput() method and a getValues() on it but neither give me the prediction value (numeric). It seems there isn't an easy method/API to get this out.

When I call this xgbModel.predict(data).get(0).getOutput(), I get this (DIM-0,5.982707500457764) When I call this xgbModel.predict(data).get(0).getOutput().getValues(), I get this [D@6b788c95, the getDimensionNamesString() works but not the one to get the value corresponding to it.

What am I not doing? This I believe is an important function. I have been looking at the docs at https://tribuo.org/learn/4.0/javadoc/org/tribuo/regression/Regressor.DimensionTuple.html

Is your question about a specific Tribuo class? Class Regressor.DimensionTuple,

Additional context Using the prediciton results to do further analysis.

Craigacp commented 3 years ago

xgbModel.predict(data).get(0).getOutput().getValues() returns the array of regressed outputs from that prediction. As in your case it's a single dimensional regression then there is only one element and so xgbModel.predict(data).get(0).getOutput().getValues()[0] is the regressed value.

Craigacp commented 3 years ago

We could add a public DimensionTuple get(int idx) method to Regressor which would return the single dimension requested, and then you could call getValue() on that if you wanted, but it's about the same.

neomatrix369 commented 3 years ago

We could add a public DimensionTuple get(int idx) method to Regressor which would return the single dimension requested, and then you could call getValue() on that if you wanted, but it's about the same.

Yes that would be good to have, and a bit more intuitive as well.

Would also be good to show this in the notebooks, so it becomes obvious how to get the values out, its a bit of nested calls before we can get to the value(s). Maybe I'll do a pull request.

neomatrix369 commented 3 years ago

xgbModel.predict(data).get(0).getOutput().getValues() returns the array of regressed outputs from that prediction. As in your case it's a single dimensional regression then there is only one element and so xgbModel.predict(data).get(0).getOutput().getValues()[0] is the regressed value.

Thanks for this

Craigacp commented 3 years ago

We could add a public DimensionTuple get(int idx) method to Regressor which would return the single dimension requested, and then you could call getValue() on that if you wanted, but it's about the same.

Yes that would be good to have, and a bit more intuitive as well.

Would also be good to show this in the notebooks, so it becomes obvious how to get the values out, its a bit of nested calls before we can get to the value(s). Maybe I'll do a pull request.

Well it's only the getValues() and then indexing the regressed value that's different from accessing any other predicted output. But I'll expand the javadoc a little and add the extra accessor.

The regression tutorial should have a note about how the multidimensional nature affects the regression objects, I thought that was in there but it's probably elsewhere in the docs.

neomatrix369 commented 3 years ago

Nice work @Craigacp loving these new PRs and changes