Closed paullemmens closed 6 years ago
A few other parts would need to be modified to make that note. If you were interested in doing a PR:
y
to determine the value of model
. (see the code for glm
, earth
and a few other models)predict
module would similarly require adaptation to work with class predictions. The same is also true of the probability module. I'm going to have a look at the glmnet code (which I've used successfully for both regression and classification) and build upon that to get penalized
working. Will let you know the progress. Thanks for your suggestion and feedback!
I looked into this and unfortunately this is going to be very messy.
I think that as odd as it sounds a fitted object from a penalized
logistic regression model does not have the original labels associated with the logistic regression. For example:
fit_penali <- penalized(penalized = nki70[ ,c("DIAPH3", "NUSAP1")], response = nki70[, "ER"],
model= "logistic" )
returns an object of class penfit
which has no mention to classnames
, labels
any other classification related point (the nki70
is a dataset in penalized
). In addition as the penfit
is an S4 class we cannot just append another attribute $classnames
, it needs a formal slot. Response-wise the fitted object contains only the logistic and the linear predictor values. The package is orphaned in CRAN so we cannot probably just ask for a newer version... I really struggle to see how functions like confusionMatrix
will ever work without some extensive re-writing.
I will be very happy to be proven wrong here!
I have written a wrapper but it is incomplete as it cannot get class labels. @paullemmens, if you want, e-mail the original authors of the package and ask for this change (through a relevant package update).
I have done the fit
but without the change mentioned the predict
is going to be a problem.
fit = function(x, y, wts, param, lev, last, classProbs, ...) {
if(is.factor(y)) {
modeltype <- "logistic"
} else {
modeltype <- "linear"
}
modelArgs <- list(response = y,
penalized = x,
lambda1 = param$lambda1,
lambda2 = param$lambda2)
inArgs <- list(...)
if(!any(names(inArgs) == "model")){
modelArgs$model <- modeltype
}
modelArgs <- c(modelArgs, inArgs)
out <- do.call(penalized::penalized, modelArgs)
out
}
If it is orphaned, I'm not sure that we should go to the trouble, especially of there are other implementations or regularized logistic regression.
About the S4 model and class levels... yeah there are a bunch of packages that (astoundingly) don't use the class levels (must. not. start. rant). The potential solution is to encapsulate the model in a list that also contains the class levels. The predict
and others can work off if the sub-element of the list. That's a hack but ¯_(ツ)_/¯
I considered this workaround too but I was uncertain if you would be OK with it as it is a bit dodgy... I will look this up in the next couple of weeks.
Sorry for the late reply. Agreed. Let's close/drop this one.
Currently the way that the penalized fit is built prohibits using the packages optional logistic regression because the fit function fixes the
model
parameter ofpenalized::penalized()
at'linear'
.With custom models (as described in the manual) this should be fixable.
This seems to run fine, but apparently the results that
caret
expects are not delivered:The warnings in this case seem to be fairly innocuous. I've check that the error is in
caret
's code.I'm aware the
plr
(also) implements penalized logistic regression but acts a bit wonky (on my data?) so I wanted to double check usingpenalized
.Am I missing something in coding the custom model?