Customized objective Function for Regression (not Classification!)


#1

There are helpful examples on here for using customized objective function for Classification but not Regression. I tried to adapt these examples but for a Regression example and kept on getting an error about the ‘labels’ not being integers.
Error in (function (cl, name, valueClass) :

assignment of an object of class “numeric” is not valid for @‘Dim’ in an object of class “ngTMatrix”; is(value, “integer”) is not TRUE

I could not see now to explicitly change the type of data ‘labels’ was expecting (e.g. float). I did not explicitly set the data type anywhere.

Has anyone managed to get custom objective functions working with XGBoost for Regression (rather than Classification)?


#2

Can you post your script?


#3

Hi Thanks for getting back to me. It is essentially the same as the code recommended for the conditional logit on here, except that instead of 0’s and 1’s as targets, I want to train on probabilities.

In fact, we might pretend it is the same as the ordinary classification problem… suppose we wanted to fit a classification model to predicted outcome (i.e., probabilities), instead of 0’s and 1’s, using the same logarithmic scoring rule as we would use in the classification problem (this would be equivalent to Maximum Likelihood Estimation for the Beta distribution, or for the Dirichlet in the multi-class problem).

Do you follow my question. I suppose, all I am asking, really, is how to explicitly change or set the ‘label’ type to allow(expect) floating-point numbers instead of just integers, without changing anything else.

Thanks!

PS Maybe my impression from the error message is not right.
I did a trackback:

Error in (function (cl, name, valueClass) :
assignment of an object of class “numeric” is not valid for @‘Dim’ in an object of class “ngTMatrix”; is(value, “integer”) is not TRUE
8.
stop(gettextf(“assignment of an object of class %s is not valid for @%s in an object of class %s; is(value, “%s”) is not TRUE”,
dQuote(valueClass), sQuote(name), dQuote(cl), slotClass),
domain = NA)
7.
(function (cl, name, valueClass)
{
ClassDef <- getClass(cl)
slotClass <- ClassDef@slots[[name]] …

%%%% FLASH !! I may have solved it… %%%%
Could it be as simple as specifying class=‘r’ (regression) in the parameters?
[This seemed to fix it for my example]