# Baking perfect cookies: methods or techniques for determining optimal ranges of x variables in classification models

This is probably best explained via an analogy: let’s assume we’re baking cookies because cookies are awesome! Let’s also assume we can only control three variables in our cooking process:

1. time (x1)
2. temperature (x2)
3. humidity (x3)

There’s an obvious interaction between time and temperature, but let’s also assume there are additional interactions among the other variables.

Our outcome variable (y) is “cookie goodness” – for the sake of argument, let’s force it to be binary – we have “good cookies” and “bad cookies”.

There are plenty of methods and models for classifying and understanding how to determine and predict good cookies vs. bad cookies, but let’s assume we want the best “settings” for time, temperature, and humidity. Since these are settings, we can assume they must be continuous “ranges” for their settings (for example, one possible rule for settings would be: keep time between 15-25 minutes, temperature between 350 and 375, and humidity above 50…there is no other cross section of variables that will yield more “good cookies”).

Questions

• Are there methods or techniques for approaching a classification model with these constraints? Initially we may think tree-based models, but a decision tree will likely return several interactions and since I need one ideal “setting” for each variable, how do we know we're not missing some subset of “settings” down a different branch of the tree?
• Is this just an exercise of optimizing/pruning the tree parameters and selecting the best branch?
• Is there some method or way to force a decision tree to only include one set of continuous ranges for each variable or to collapse/summarize the output of the tree to continuous rulesets for each variable?

Aside: This almost feels like a reverse Design of Experiments (DOE)?

Practical Considerations

Then there’s the problem when the tree suggests too “tight” of a range (e.g. keep temperature between 400 and 401 – my oven’s not that accurate)? I suppose we could check branches with high support and high confidence and then see if they have implementable ranges. I suppose "best/optimal" is subjective, so let's say we need to have at least 10% support (50 trials) and 75% confidence.

In case anyone wants to explain with some fake data, here is some R code:

library(tidyverse)

n <- 500
time <- runif(n, 15, 40)
temp <- runif(n, 300, 450)
humidity <- runif(n, 35, 60)

cookie_goodness <- (2*time + 3*time*temp + 4*humidity*temp  + 5*humidity + rnorm(n)) / 10000

df <- data_frame(
trial = 1:n,
time = time,
temp = temp,
humidity = humidity,
1, 0)
)
)

# # A tibble: 500 x 5
#    trial  time  temp humidity good_cookie
#    <int> <dbl> <dbl>    <dbl> <fctr>
# 1      1  40.0   377     54.5 0
# 2      2  39.0   384     53.4 0
# 3      3  30.9   325     38.4 0
# 4      4  25.5   447     35.1 1
# 5      5  19.0   348     44.7 0
# 6      6  37.1   431     42.7 0
# 7      7  34.8   400     43.5 1
# 8      8  26.2   346     36.9 0
# 9      9  19.2   409     38.0 0
# 10    10  38.0   408     46.9 0
# # ... with 490 more rows