Created
November 22, 2016 06:42
-
-
Save obrl-soil/3c42f074ffa48ae0e62e461bf293a657 to your computer and use it in GitHub Desktop.
pull out attribute usage stats from c5.0 objects in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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