<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/the-tidy-caret-interface-in-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://poissonisfish.wordpress.com/2018/11/16/the-all-new-caret-interface-in-r/"> poissonisfish</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<figure data-shortcode="caption" class="wp-caption"><img data-orig-file="https://poissonisfish.files.wordpress.com/2018/11/1-s2-0-s2095881115300202-gr21.jpg?w=456" data-orig-size="371,227" data-medium-file="https://poissonisfish.files.wordpress.com/2018/11/1-s2-0-s2095881115300202-gr21.jpg?w=456?w=300" data-attachment-id="4689" data-image-meta="{" data-image-description="" src="https://poissonisfish.files.wordpress.com/2018/11/1-s2-0-s2095881115300202-gr21.jpg?w=456" data-permalink="https://poissonisfish.wordpress.com/2018/11/16/the-all-new-caret-interface-in-r/1-s2-0-s2095881115300202-gr2-2/" data-large-file="https://poissonisfish.files.wordpress.com/2018/11/1-s2-0-s2095881115300202-gr21.jpg?w=456?w=371" alt="1-s2.0-S2095881115300202-gr2" data-image-title="1-s2.0-S2095881115300202-gr2" sizes="(max-width: 371px) 100vw, 371px" data-comments-opened="1" class="wp-image-4689" data-recalc-dims="1"><figcaption class="wp-caption-text">Can human experience and chemoinformatics unravel the chemistry of smell? We are about to find out in the new world of caret [<a rel="nofollow" href="https://www.sciencedaily.com/releases/2017/09/170906170126.htm" target="_blank">source</a>]</figcaption></figure>
<p>Among most popular off-the-shelf machine learning packages available to R, <code>caret</code> ought to stand out for its consistency. It reaches out to a wide range of dependencies that deploy and support model building using a uniform, simple syntax. I have been using <code>caret</code> extensively for the past three years, with a precious <a rel="nofollow" href="https://poissonisfish.wordpress.com/2017/06/17/partial-least-squares-in-r/" target="_blank">partial least squares (PLS) tutorial</a> in my track record.</p>
<p>A couple of years ago, the creator and maintainer of <code>caret</code> Max Kuhn joined RStudio where he has contributing new packages to the ongoing tidy-paranoia – the supporting <code>recipes</code>, <code>yardstick</code>, <code>rsample</code> and many other packages that are part of the <code>tidyverse</code> paradigm and I knew little about. As it happens, <code>caret</code> is now best used with some of these. As an aspiring data scientist with fashionable <a rel="nofollow" href="https://www.redbubble.com/shop/rstudio+stickers" target="_blank">hex-stickers</a> on my laptop cover and a tendency to start any sentence with ‘big data’, I set to learn <code>tidyverse</code> and going Super Mario using <a rel="nofollow" href="https://www.datacamp.com/community/tutorials/pipe-r-tutorial?tap_a=5644-dce66f&tap_s=10907-287229" target="_blank">pipes</a> (<code>%>%</code>, Ctrl + Shift + M).</p>
<p>Overall, I found the ‘tidy’ approach quite enjoyable and efficient. Besides streamlining model design in a sequential manner, <code>recipes</code> and the accompanying ‘tidy’ packages fix a common problem in the statistical learning realm that curtails predictive accuracy, <a rel="nofollow" href="https://www.kaggle.com/dansbecker/data-leakage" target="_blank">data leakage</a>. You can now generate a ‘recipe’ that lays out the plan for all the feature engineering (or data pre-processing, depending on how many hex-stickers you have) and execute it separately for validation and resampling splits (i.e. split first, process later), thus providing a more robust validation scheme. It also enables recycling any previous computations afterwards.</p>
<p>I drew a lot of inspiration from a <a rel="nofollow" href="https://www.rstudio.com/resources/webinars/creating-and-preprocessing-a-design-matrix-with-recipes/" target="_blank">webinar</a> and a <a rel="nofollow" href="https://github.com/topepo/user2018/blob/master/slides/Recipes_for_Data_Processing.pdf" target="_blank">presentation</a> from Max himself to come up with this tutorial. Max is now hands-on writing a new book, entitled <em><a rel="nofollow" href="http://www.feat.engineering/" target="_blank">Feature Engineering and Selection: A Practical Approach for Predictive Models</a></em> that will include applications of <code>caret</code> supported by <code>recipes</code>. I very much look forward to read it considering he did a fantastic job with <em><a rel="nofollow" href="http://appliedpredictivemodeling.com/" target="_blank">Applied Predictive Modeling</a></em>.</p>
<p>The aim here is to test this new <code>caret</code> framework on the <a rel="nofollow" href="http://dreamchallenges.org/project/dream-odor-classification-challenge/" target="_blank">DREAM Olfaction Prediction Challenge</a>, a crowd-sourced initiative launched in January 2015. This challenge demonstrated predictive models can identify perceptual attributes (e.g. coffee-like, spicy and sweet notes) in a collection of fragrant compounds from physicochemical features (e.g. atom types). Results and conclusions were condensed into a <a rel="nofollow" href="https://www.ncbi.nlm.nih.gov/pubmed/28219971" target="_blank">research article</a> [1] that reports an impressive predictive accuracy for a large number of models and teams, over various perceptive attributes. Perhaps more impressive yet, is the fact it anticipates the very scarce knowledge of human odour receptors and their molecular activation mechanisms. Our task, more concretely, will be to predict population-level pleasantness of hundreds of compounds from physicochemical features, using the training set of the competition.</p>
<p>Finally, a short announcement. Many people have been raising reproducibility issues with previous entries, due to either package archiving (e.g. <code>GenABEL</code>, for <a rel="nofollow" href="https://poissonisfish.wordpress.com/2017/10/09/genome-wide-association-studies-in-r/" target="_blank">genetic mapping</a>) or cross-incompatibility (e.g. <code>caret</code>, for <a rel="nofollow" href="https://poissonisfish.wordpress.com/2017/06/17/partial-least-squares-in-r/" target="_blank">PLS</a>). There were easy fixes for the most part, but I have nevertheless decided to start packing scripts together with <code>sessionInfo()</code> reports in unique GitHub repositories. The bundle for this tutorial is available under <a rel="nofollow" href="https://github.com/monogenea/olfactionPrediction" target="_blank">https://github.com/monogenea/olfactionPrediction</a>. I hope this will help track down the exact package versions and system configurations I use, so that anyone can anytime fully reproduce these results. No hex-stickers required!</p>
<p><strong>NOTE that most code chunks containing pipes are corrupted. PLEASE refer to the <a rel="nofollow" href="https://github.com/monogenea/olfactionPrediction" target="_blank">materials from the repo</a>.</strong></p>
<h2>The DREAM Olfaction Prediction Challenge</h2>
<p>The DREAM Olfaction Prediction Challenge training set consists of 338 compounds characterised by 4,884 physicochemical features (the design matrix), and profiled by 49 subjects with respect to 19 semantic descriptors, such as ‘flower’, ‘sweet’ and ‘garlic’, together with intensity and pleasantness (all perceptual attributes). Two different dilutions were used per compound. The perceptual attributes were given scores in the 0-100 range. The two major goals of the competition were to use the physicochemical features in modelling <em>i</em>) the perceptual attributes at the subject-level and <em>ii</em>) both the mean and standard deviation of the perceptual attributes at the population-level. How ingenious it was to model the standard deviation, the variability in how something tastes to different people! In the end, the organisers garnered important insights about the biochemical basis of flavour, from teams all over the world. The resulting models were additionally used to reverse-engineer nonexistent compounds from target sensory profiles – an economically exciting prospect.</p>
<p>According to the publication, the top-five best predicted perceptual attributes at the population-level (i.e. mean values across all 49 subjects) were ‘garlic’, ‘fish’, ‘intensity’, pleasantness and ‘sweet’ (cf. Fig. 3A in [1]), all exhibiting average prediction correlations of <img alt="r ge 0.5" title="r ge 0.5" src="https://s0.wp.com/latex.php?latex=r+%5Cge+0.5&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex">, far greater than the average subject-level predictions (cf. Fig. 2D in [1]). This should come as no surprise since averaging over subjects is more likely to flesh out universal mechanisms. This averaging also helps stabilising the subject-level variance – no subject will necessarily utilise the full 0-100 scoring range; some will tend to use narrow intervals (low variance) while some will use the whole range instead (high variance).</p>
<p>Since pleasantness is one of the most general olfactory properties, I propose modelling the population-level median pleasantness of all compounds, from all physicochemical features. The median, as opposed to the mean, is less sensitive to outliers and an interesting departure from the original approach we can later compare against.</p>
<h1>Let’s get started with R</h1>
<p>We can start off by loading all the necessary packages and pulling the data directly from the <a rel="nofollow" href="https://github.com/dream-olfaction/olfaction-prediction/tree/master/data" target="_blank">DREAM Olfaction Prediction GitHub repository</a>. More specifically, we will create a directory called <code>data</code><strong> </strong>and import both the profiled perceptual attributes (<code>TrainSet.txt</code>) and the physicochemical features that comprise our design matrix (<code>molecular_descriptors_data.txt</code>). Because we are tidy people, we will use <code>readr</code> to parse these as tab-separated values (TSV). I also suggest re-writing the column name <code>Compound Identifier</code> in the sensory profiles into <code>CID</code>, to match with that from the design matrix <code>molFeats</code>.</p>
<pre>
# Mon Oct 29 13:17:55 2018 ------------------------------
## DREAM olfaction prediction challenge
library(caret)
library(rsample)
library(tidyverse)
library(recipes)
library(magrittr)
library(doMC)

# Create directory and download files
dir.create(&quot;data/&quot;)
ghurl &lt;- &quot;https://github.com/dream-olfaction/olfaction-prediction/raw/master/data/&quot;
download.file(paste0(ghurl, &quot;TrainSet.txt&quot;),
destfile = &quot;data/trainSet.txt&quot;)
download.file(paste0(ghurl, &quot;molecular_descriptors_data.txt&quot;),
destfile = &quot;data/molFeats.txt&quot;)

# Read files with readr, select least diluted compounds
responses %
rename(CID = `Compound Identifier`)

molFeats &lt;- read_tsv(&quot;data/molFeats.txt&quot;) # molecular features
</pre>
<p>Next, we filter compounds that are common to both datasets and reorder them accordingly. The profiled perceptual attributes span a total of 49 subjects, two different dilutions and some replications (cf. Fig. 1A in [1]). Determine the median pleasantness (i.e. <code>VALENCE/PLEASANTNESS</code>) per compound, across all subjects and dilutions while ignoring missingness with <code>na.rm = T</code>. The last line will ensure the order of the compounds is identical between this new dataset and the design matrix, so that we can subsequently introduce population-level pleasantness as a new column termed <code>Y</code> in the new design matrix <code>X</code>. We no longer need <code>CID</code> so we can discard it.</p>
<p>Regarding missingness, I found maxima of 0.006% and 23% NA content over all columns and rows, respectively. A couple of compounds could be excluded but I would move on.</p>
<pre>
# Determine intersection of compounds in features and responses
commonMols %
dplyr::summarise(pleasantness = median(`VALENCE/PLEASANTNESS`, na.rm = T))
all(medianPlsnt$CID == molFeats$CID) # TRUE - rownames match

# Concatenate predictors (molFeats) and population pleasantness
X %
select(-CID)
</pre>
<p>In examining the structure of the design matrix, you will see there are many skewed binary variables. In the most extreme case, if a binary predictor is either all zeros or all ones throughout it is said to be a zero-variance predictor that if anything, will harm the model training process. There is still the risk of having near-zero-variance predictors, which can be controlled based on various criteria (e.g. number of samples, size of splits). Of course, this can also impact quantitative, continuous variables. Here we will use <code>nearZeroVar</code> from <code>caret</code> to identify faulty predictors that are either zero-variance or display values whose frequency exceeds a predefined threshold. Having a 5x repeated 5-fold cross-validation in mind, I suggest setting <code>freqCut = 4</code>, which will rule out <em>i</em>) binary variables with <img alt="|f(0) - f(1)| ge 0.80 " title="|f(0) - f(1)| ge 0.80 " src="https://s0.wp.com/latex.php?latex=%7Cf%280%29+-+f%281%29%7C+%5Cge+0.80+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex">, and <em>ii</em>) continuous variables with <img alt="frac{# most common value}{# second most common value} ge 4 " title="frac{# most common value}{# second most common value} ge 4 " src="https://s0.wp.com/latex.php?latex=%5Cfrac%7B%5C%23+most+common+value%7D%7B%5C%23+second+most+common+value%7D+%5Cge+4+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex">. See <code>?nearZeroVar</code> for more information. From 4,870 features we are left with 2,554 – a massive reduction by almost a half.</p>
<pre>
# Filter nzv
X &lt;- X[,-nearZeroVar(X, freqCut = 4)] # == 80/20
</pre>
<p>Now we will use <code>rsample</code> to define the train-test and cross-validation splits. Please use <code>set.seed</code><strong> </strong>as it is, to ensure you will generate the same partitions and arrive to the same results. Here I have allocated 10% of the data to the test set; by additionally requesting stratification based on the target <code>Y</code>, we are sure to have a representative subset. We can next pass the new objects to <code>training</code> and <code>testing</code> to effectively split the design matrix into train and test sets, respectively. The following steps consist of setting up a 5x repeated 5-fold cross-validation for the training set. Use <code>vfold_cv</code> and convert the output to a <code>caret</code>-like object via <code>rsample2caret</code>. Next, initialise a <code>trainControl</code> object and overwrite <code>index</code> and <code>indexOut</code> using the corresponding elements in the newly converted <code>vfold_cv</code> output.</p>
<pre>
# Split train/test with rsample
set.seed(100)
initSplit &lt;- initial_split(X, prop = .9,
strata = &quot;Y&quot;)
trainSet &lt;- training(initSplit)
testSet &lt;- testing(initSplit)

# Create 5-fold cross-validation, convert to caret class
set.seed(100)
myFolds %
rsample2caret()
ctrl &lt;- trainControl(method = &quot;cv&quot;,
selectionFunction = &quot;oneSE&quot;)
ctrl$index &lt;- myFolds$index
ctrl$indexOut &lt;- myFolds$indexOut
</pre>
<p>Prior to modelling, I will create two reference variables – <code>binVars</code>, to identify binary variables, and <code>missingVars</code>, to identify any variables containing missing values. These will help with <em>i</em>) excluding binary variables from mean-centering and unit-variance scaling, and <em>ii</em>) restricting mean-based imputation to variables that do contain missing values, respectively.</p>
<pre>
# binary vars
binVars &lt;- which(sapply(X, function(x){all(x %in% 0:1)}))
missingVars &lt;- which(apply(X, 2, function(k){any(is.na(k))}))
</pre>
<p>Recipes are very simple in design. The call to <code>recipe</code> is first given the data it is supposed to be applied on, as well as a <a rel="nofollow" href="https://poissonisfish.wordpress.com/2017/12/11/linear-mixed-effect-models-in-r/" target="_blank"><code>lm</code>-style formula</a>. The <code>recipes</code> <strong> </strong>package contains a family of functions with a <code>step_...</code> prefix, involved in encodings, date conversions, filters, imputation, normalisation, dimension reduction and a lot more. These can be linked using pipes, forming a logic sequence of operations that starts with the <code>recipe</code> call. Supporting functions such as <code>all_predictors</code>, <code>all_outcomes</code> and <code>all_nominal</code> delineate specific groups of variables at any stage in the sequence. One can also use the names of the variables, akin to my usage of <code>binVars</code> and <code>missingVars</code>.</p>
<p>I propose writing a basic recipe <code>myRep</code> that does the following:</p>
<ul>
<li>Yeo-Johnson [2] transformation of all quantitative predictors;</li>
<li>Mean-center all quantitative predictors;</li>
<li>Unit-variance scale all quantitative predictors;</li>
<li>Impute missing values with the mean of the incident variables.</li>
</ul>
<pre>
# Design recipe
myRec %
step_YeoJohnson(all_predictors(), -binVars) %>%
step_center(all_predictors(), -binVars) %>%
step_scale(all_predictors(), -binVars) %>%
step_meanimpute(missingVars)
</pre>
<p>In brief, the Yeo-Johnson procedure transforms variables to be distributed as Gaussian-like as possible. Before delving into the models let us tweak the recipe and assign it to <code>pcaRep</code>, conduct a <a rel="nofollow" href="https://poissonisfish.wordpress.com/2017/01/23/principal-component-analysis-in-r/" target="_blank">principal component analysis</a> and examine how different compounds distribute along the first two principal components. Colour them based on their population-level pleasantness – red for very pleasant, blue for very unpleasant and the gradient in between, via <code>colGrad</code>.</p>
<pre>
# simple PCA, plot
pcaRec %
step_pca(all_predictors())

myPCA %
juice()
colGrad &lt;- trainSet$Y/100 # add color

plot(myPCA$PC1, myPCA$PC2,
col = rgb(1 - colGrad, 0, colGrad,.5),
pch = 16, xlab = &quot;PC1&quot;, ylab = &quot;PC2&quot;)
legend(&quot;topleft&quot;, pch = 16,
col = rgb(c(0,.5,1), 0, c(1,.5,0), alpha = .5),
legend = c(&quot;Pleasant&quot;, &quot;Neutral&quot;, &quot;Unpleasant&quot;), bty = &quot;n&quot;)
</pre>
<p><img data-orig-file="https://poissonisfish.files.wordpress.com/2018/11/pcaplot2.png?w=456" data-orig-size="616,586" data-medium-file="https://poissonisfish.files.wordpress.com/2018/11/pcaplot2.png?w=456?w=300" data-attachment-id="4712" data-image-meta="{" data-image-description="" src="https://poissonisfish.files.wordpress.com/2018/11/pcaplot2.png?w=456" data-permalink="https://poissonisfish.wordpress.com/2018/11/16/the-all-new-caret-interface-in-r/pcaplot/" data-large-file="https://poissonisfish.files.wordpress.com/2018/11/pcaplot2.png?w=456?w=616" alt="pcaPlot" data-image-title="pcaPlot" sizes="(max-width: 616px) 100vw, 616px" data-comments-opened="1" class="wp-image-4712" data-recalc-dims="1"></p>
<p>The compounds do not seem to cluster into groups, nor do they clearly separate with respect to pleasantness.</p>
<p> </p>
<p>Note that <code>pcaRep</code> itself is just a recipe on wait. Except for recipes passed to <code>caret::train</code>, to process and extract the data as instructed you need to either ‘bake’ or ‘juice’ the recipe. The difference between the two is that ‘juicing’ outputs the data associated to the recipe (e.g. the training set), whereas ‘baking’ can be applied to process any other dataset. ‘Baking’ is done with <code>bake</code>, provided the recipe was trained using <code>prep</code>. I hope this explains why I used <code>juice</code> above!</p>
<p>Next we have the model training. I propose training five regression models – <em>k</em>-nearest neighbours (KNN), elastic net (ENET), support vector machine with a radial basis function kernel (SVM), random forests (RF), extreme gradient boosting (XGB) and Quinlan’s Cubist (CUB) – aiming at minimising the root mean squared error (RMSE). Note I am using <code>tuneGrid</code> and <code>tuneLength</code> interchangeably. I rather supply predefined hyper-parameters to simple models I am more familiar with, and run the rest with a number of defaults via <code>tuneLength</code>.</p>
<p>Parallelise the computations if possible. With macOS, I can use <code>registerDoMC</code> from the <code>doMC</code> package to harness multi-threading of the training procedure. If you are running a different OS, please use a different library if necessary. To the best of my knowledge, <code>doMC</code> will also work in Linux but Windows users might need to use the <code>doParallel</code> package instead.</p>
<pre>
# Train
doMC::registerDoMC(10)
knnMod &lt;- train(myRec, data = trainSet,
method = &quot;knn&quot;,
tuneGrid = data.frame(k = seq(5, 25, by = 4)),
trControl = ctrl)

enetMod &lt;- train(myRec, data = trainSet,
method = &quot;glmnet&quot;,
tuneGrid = expand.grid(alpha = seq(0, 1, length.out = 5),
lambda = seq(.5, 2, length.out = 5)),
trControl = ctrl)

svmMod &lt;- train(myRec, data = trainSet,
method = &quot;svmRadial&quot;,
tuneLength = 8,
trControl = ctrl)

rfMod &lt;- train(myRec, data = trainSet,
method = &quot;ranger&quot;,
tuneLength = 8,
num.trees = 5000,
trControl = ctrl)

xgbMod &lt;- train(myRec, data = trainSet,
method = &quot;xgbTree&quot;,
tuneLength = 8,
trControl = ctrl)

cubMod &lt;- train(myRec, data = trainSet,
method = &quot;cubist&quot;,
tuneLength = 8,
trControl = ctrl)

modelList &lt;- list(&quot;KNN&quot; = knnMod,
&quot;ENET&quot; = enetMod,
&quot;SVM&quot; = svmMod,
&quot;RF&quot; = rfMod,
&quot;XGB&quot; = xgbMod,
&quot;CUB&quot; = cubMod)
</pre>
<p>Once the training is over, we can compare the optimal five cross-validated models based on their RMSE across all <img alt="5 times 5 = 25 " title="5 times 5 = 25 " src="https://s0.wp.com/latex.php?latex=5+%5Ctimes+5+%3D+25+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex"> resamples, using some <code>bwplot</code> magic sponsored by <code>lattice</code>. In my case the runtime was unusually long (>2 hours) compared to previous releases.</p>
<pre>
bwplot(resamples(modelList),
metric = &quot;RMSE&quot;)
</pre>
<p><img data-orig-file="https://poissonisfish.files.wordpress.com/2018/11/rmseall2.png?w=456" data-orig-size="476,306" data-medium-file="https://poissonisfish.files.wordpress.com/2018/11/rmseall2.png?w=456?w=300" data-attachment-id="4716" data-image-meta="{" data-image-description="" src="https://poissonisfish.files.wordpress.com/2018/11/rmseall2.png?w=456" data-permalink="https://poissonisfish.wordpress.com/2018/11/16/the-all-new-caret-interface-in-r/rmseall/" data-large-file="https://poissonisfish.files.wordpress.com/2018/11/rmseall2.png?w=456?w=476" alt="rmseAll" data-image-title="rmseAll" sizes="(max-width: 476px) 100vw, 476px" data-comments-opened="1" class="wp-image-4716" data-recalc-dims="1"></p>
<p>The cross-validated RSME does not vary considerably across the six optimal models. To conclude, I propose creating a model ensemble by simply taking the average predictions of all six optimal models on the test set, to compare observed and predicted population-level pleasantness in this hold-out subset of compounds.</p>
<pre>
# Validate on test set with ensemble
allPreds &lt;- sapply(modelList, predict, newdata = testSet)
ensemblePred &lt;- rowSums(allPreds) / length(modelList)

# Plot predicted vs. observed; create PNG
plot(ensemblePred, testSet$Y,
xlim = c(0,100), ylim = c(0,100),
xlab = &quot;Predicted&quot;, ylab = &quot;Observed&quot;,
pch = 16, col = rgb(0, 0, 0, .25))
abline(a=0, b=1)

writeLines(capture.output(sessionInfo()), &quot;sessionInfo&quot;)
</pre>
<p><img data-orig-file="https://poissonisfish.files.wordpress.com/2018/11/ensemble.png?w=456" data-orig-size="489,417" data-medium-file="https://poissonisfish.files.wordpress.com/2018/11/ensemble.png?w=456?w=300" data-attachment-id="4714" data-image-meta="{" data-image-description="" src="https://poissonisfish.files.wordpress.com/2018/11/ensemble.png?w=456" data-permalink="https://poissonisfish.wordpress.com/2018/11/16/the-all-new-caret-interface-in-r/ensemble/" data-large-file="https://poissonisfish.files.wordpress.com/2018/11/ensemble.png?w=456?w=489" alt="ensemble" data-image-title="ensemble" sizes="(max-width: 489px) 100vw, 489px" data-comments-opened="1" class="wp-image-4714" data-recalc-dims="1"></p>
<p>The ensemble fit on the test set is not terrible – slightly underfit, predicting the poorest in the two extremes of the pleasantness range. All in all, it attained a prediction correlation of <img alt="r approx 0.73 " title="r approx 0.73 " src="https://s0.wp.com/latex.php?latex=r+%5Capprox+0.73+&bg=f9f9f9&%23038;fg=555555&%23038;s=1" class="latex">, which is slightly larger than the mean reported (cf. Fig. 3A in [1]). However, note that there are only 31 compounds in the test set. A model like this could be easily moved into production stage or repurposed to solve a molecular structure from a sensory profile of interest, as mentioned earlier.</p>
<h2>Wrap-up</h2>
<p>The revamped <code>caret</code> framework is still under development, but it seems to offer</p>
<ul>
<li>A substantially expanded, unified syntax for models and utils. Keep an eye on <code>textrecipes</code>, an upcoming <a rel="nofollow" href="https://github.com/topepo/textrecipes" target="_blank">complementary package</a> for processing textual data;</li>
<li>A sequential streamlining of extraction, processing and modelling, enabling recycling of previous computations;</li>
<li>Executing-after-splitting, thereby precluding leaky validation strategies.</li>
</ul>
<p>On the other hand, I hope to see improvements in</p>
<ul>
<li>Decoupling from proprietary frameworks in the likes of <code>tidyverse</code>, although there are alternatives;</li>
<li>The runtime. I suspect the recipes themselves are the culprit, not the models. Future updates will certainly fix this.</li>
</ul>
<p>Regarding the DREAM Olfaction Prediction Challenge, we were able to predict population-level perceived pleasantness from physicochemical features with an accuracy as good as that achieved, in average, by the competing teams. Our model ensemble seems underfit, judging from the narrow range of predicted values. Maybe we could be less restrictive about the near-zero-variance predictors and use a repeated 3-fold cross-validation.</p>
<p>I hope you had as much fun as I did in dissecting a fascinating problem while unveiling a bit of the new <code>caret</code>. You can use this code as a template for exploring different recipes and models. If you encounter any problems or have any questions do not hesitate to post a comment underneath – we all learn from each other!</p>
<h2>References</h2>
<p>[1] Keller, Andreas <em>et al</em>. (2017). Predicting human olfactory perception from chemical features of odor molecules. <em>Science</em>, 355(6327), 820-826.</p>
<p>[2] Yeo, In-Kwon and Johnson, Richard (2000). A new family of power transformations to improve normality or symmetry. <em>Biometrika</em>, 87(4), 954-959.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://poissonisfish.wordpress.com/2018/11/16/the-all-new-caret-interface-in-r/"> poissonisfish</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/uFwSNknP8co" height="1"></a></div>