Skip to content

Instantly share code, notes, and snippets.

@obrl-soil
Created November 22, 2016 06:42
Show Gist options
  • Save obrl-soil/3c42f074ffa48ae0e62e461bf293a657 to your computer and use it in GitHub Desktop.
Save obrl-soil/3c42f074ffa48ae0e62e461bf293a657 to your computer and use it in GitHub Desktop.
pull out attribute usage stats from c5.0 objects in R
c5_usage_df <- function(x) {
library(stringr)
xt <- substr(x$output,
str_locate(x$output, "usage:")[2] + 4,
str_locate(x$output, 'Time')[1] - 1)
xt <- gsub('\\n', '', xt)
xt <- gsub('\\t', ', ', xt)
xu <- as.data.frame(matrix(unlist(strsplit(xt, ", ")),
ncol =2, byrow=T),
stringsAsFactors = FALSE)
names(xu) <- c('use_percentage', 'covariate_name')
xu$use_percentage <- gsub('%', "", xu$use_percentage)
xu$use_percentage <- gsub(' ', "", xu$use_percentage)
xu$use_percentage <- as.numeric(xu$use_percentage)
return(xu)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment