Opened 6 hours ago

Closed 6 hours ago

#149 closed defect (invalid)

transform_to_stepfunction issue

Reported by: Isabelle Owned by: Olly Betts
Priority: major Milestone:
Component: Other Version:
Keywords: Cc:

Description

I am creating a custom explainer for a model I have develop. I have a predict function that returns a vector of survival times. See below. When entering the transform_to_stepfunction, the raw_prediction is simply a vector numeric values. When stepping into this function, I see where the function crashes:

transform_to_stepfunction <- function(predict_function, eval_times = NULL, ..., type = NULL, prediction_element = NULL, times_element = NULL) {

function(model, newdata, times) {

raw_prediction <- predict_function(model, newdata, ...) if (!is.null(times_element)) eval_times <- raw_predictiontimes_element? if (!is.null(prediction_element)) prediction <- raw_predictionprediction_element? n_rows <- ifelse(is.null(dim(prediction)), 1, nrow(prediction))

Since both times_element and prediction_element are null, the 'prediction' variable is null too, which creashes this function with the message:

"Error in explainer$predict_survival_function(explainer$model, newdata, :

object 'prediction' not found"

How to make this work with a function that returns a vector of survival lengths?

Thank you.

See below my prediction function:

pred_cbr <- function(model, newdata, eval_times) {

test <- newdata all <- alldata[rownames(test) %in% rownames(alldata)] test <- cbind('time' = all[,1], 'status' = all[,2], test) predictions <- CBR_predict(model, test) # list of survival predictions for all test_data samples survivals <- list() for (n in 1:length(predictions)) {

survivals <- c(survivals, list(mean(unlist(predictionsn?$survival times))))

} vsurv <- unlist(survivals) return(vsurv)

}

surv_pred_cbr <- transform_to_stepfunction(pred_cbr,

eval_times = times, type="survival")

Change History (1)

comment:1 Changed 6 hours ago by Olly Betts

Resolution: invalid
Status: newclosed

I think you're asking in the wrong place - this seems completely unrelated to Survex (which is software for mapping cave systems...)

Note: See TracTickets for help on using tickets.