5.2 Binning
# create a space to store our binning results and spearman
matrix(rep(NA,nrow(sausage.processed)),nrow =
bin_data <-nrow(sausage.processed), ncol = ncol(sausage.processed)
)colnames(bin_data) <- colnames(sausage.processed)
rownames(bin_data) <- wk0$Product
# we use this loop along with a try catch to skip the varibles that BinQuant cannot bin.
for (i in 1:19) {
tryCatch({
which(colnames(sausage.processed) == colnames(sausage.processed)[i])
var_clust =colnames(sausage.processed)[var_clust]] <- BinQuant(
bin_data[,nClass = 4, stem = '')
sausage.processed[,var_clust], error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
}, }
## ERROR : 'breaks' are not unique
## ERROR : 'breaks' are not unique
## ERROR : 'breaks' are not unique
Notice that we use a different binning method for the following variables. The process is largely manual by either changing the amount of Bin Class or manually assign bins.
# variable Bitter - works only when nclass = 1
sausage.processed[,6]
t <- as.matrix(ifelse(t == 0, 1, 2))
a <-6] <- a
bin_data[,
# variable Fatty - works when nclass = 3
which(colnames(sausage.processed) == colnames(sausage.processed)[13])
var_clust =colnames(sausage.processed)[var_clust]] <- BinQuant(
bin_data[,nClass = 3, stem = '')
sausage.processed[,var_clust],
# variable HVP - works when nclass = 3
which(colnames(sausage.processed) == colnames(sausage.processed)[14])
var_clust =colnames(sausage.processed)[var_clust]] <- BinQuant(
bin_data[,nClass = 3, stem = '') sausage.processed[,var_clust],