<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/vtreat-version-0-5-26-released-on-cran/"></div></div><div><a data-url="http://www.r-bloggers.com/vtreat-version-0-5-26-released-on-cran/" data-counturl="http://www.r-bloggers.com/vtreat-version-0-5-26-released-on-cran/" data-count="horizontal" data-text="vtreat version 0.5.26 released on CRAN" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.win-vector.com/blog/2016/07/vtreat-version-0-5-26-released-on-cran/"> R – Win-Vector Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a target="_blank" href="http://www.win-vector.com/">Win-Vector LLC</a>, <a target="_blank" href="https://ninazumel.com/">Nina Zumel</a> and <a target="_blank" href="http://johnmount.com/">I</a> are pleased to announce that <a target="_blank" href="https://cran.r-project.org/package=vtreat">‘vtreat’ version 0.5.26 has been released on CRAN</a>.</p>
<blockquote><p>‘vtreat’ is a data.frame processor/conditioner that prepares real-world data for predictive modeling in a statistically sound manner.</p>
<p><a target="_blank" href="http://winvector.github.io/vtreat/vtreat.html">(from the package documentation)</a>

</blockquote>
<p>‘vtreat’ is an <a target="_blank" href="https://cran.r-project.org/">R</a> package that incorporates a number of transforms and simulated out of sample (cross-frame simulation) procedures that can:</p>
<ul>
<li>Decrease the amount of hand-work needed to prepare data for predictive modeling.</li>
<li>Improve actual model performance on new out of sample or application data.</li>
<li>Lower your procedure documentation burden (through ready <a target="_blank" href="http://winvector.github.io/vtreat/">vtreat documentation and tutorials</a>).</li>
<li>Increase model reliability (by re-coding unexpected situations).</li>
<li>Increase model expressiveness (by allowing use of more variable types, especially large cardinality categorical variables).</li>
</ul>
<p>‘vtreat’ can be used to prepare data for either regression or classification.</p>
<p>Please read on for what ‘vtreat’ does and what is new.<span></span></p>
<p>
<h2>About vtreat</h2>
<p>The primary function of ‘vtreat’ is re-coding of high-cardinality categorical variables, re-coding of missing data, and out-of sample estimation of variable effects and significances. You can use ‘vtreat’ as a pre-processor and use ‘vtreat::prepare’ as a powerful replacement for ‘stats::model.matrix’. Using ‘vtreat’ should get you quickly into the competitive ballpark of best performance on a real-world data problem (such as <a target="_blank" href="http://winvector.github.io/VariableSignal/KDD2009example.html">KDD2009</a>) leaving you time to apply deeper domain knowledge and model tuning for even better results.</p>
<p>‘vtreat’ achieves this by using the assumption that you have a modeling “y” (or outcome to predict) throughout, and that all preparation and transformation should be designed to use knowledge of this “y” during training (and anticipate not having the “y” during test or application).</p>
<p>More simply: the purpose of ‘vtreat’ is to quickly take a messy real-world data frame similar to:</p>
<p><code>
<pre>
library('htmlTable')
library('vtreat')
dTrainC &lt;- data.frame(x=c('a','a','a','b','b',NA,NA),
                      z=c(1,2,3,4,NA,6,NA),
                      y=c(FALSE,FALSE,TRUE,FALSE,TRUE,TRUE,TRUE))
htmlTable(dTrainC)
</pre>
<p></p>
<p><center>
<table>
<thead>
<tr>
<th> </th>
<th>x</th>
<th>z</th>
<th>y</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>a</td>
<td>1</td>
<td>FALSE</td>
</tr>
<tr>
<td>2</td>
<td>a</td>
<td>2</td>
<td>FALSE</td>
</tr>
<tr>
<td>3</td>
<td>a</td>
<td>3</td>
<td>TRUE</td>
</tr>
<tr>
<td>4</td>
<td>b</td>
<td>4</td>
<td>FALSE</td>
</tr>
<tr>
<td>5</td>
<td>b</td>
<td></td>
<td>TRUE</td>
</tr>
<tr>
<td>6</td>
<td></td>
<td>6</td>
<td>TRUE</td>
</tr>
<tr>
<td>7</td>
<td></td>
<td></td>
<td>TRUE</td>
</tr>
</tbody>
</table>
<p></p>
<p>And build a treatment plan:</p>
<p><code>
<pre>
treatmentsC &lt;- designTreatmentsC(dTrainC,colnames(dTrainC),'y',TRUE)
</pre>
<p></p>
<p>The treatment plan can then be used to clean up the original data and also be applied to any future application or test data:</p>
<p><code>
<pre>
dTrainCTreated &lt;- prepare(treatmentsC,dTrainC,pruneSig=0.5)
nround &lt;- function(x) { if(is.numeric(x)) { round(x,2) } else { x } }
htmlTable(data.frame(lapply(dTrainCTreated,nround)))
</pre>
<p></p>
<p><center>
<table>
<thead>
<tr>
<th> </th>
<th>x_lev_NA</th>
<th>x_lev_x.a</th>
<th>x_catP</th>
<th>x_catB</th>
<th>z_clean</th>
<th>z_isBAD</th>
<th>y</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>0</td>
<td>1</td>
<td>0.43</td>
<td>-0.54</td>
<td>1</td>
<td>0</td>
<td>FALSE</td>
</tr>
<tr>
<td>2</td>
<td>0</td>
<td>1</td>
<td>0.43</td>
<td>-0.54</td>
<td>2</td>
<td>0</td>
<td>FALSE</td>
</tr>
<tr>
<td>3</td>
<td>0</td>
<td>1</td>
<td>0.43</td>
<td>-0.54</td>
<td>3</td>
<td>0</td>
<td>TRUE</td>
</tr>
<tr>
<td>4</td>
<td>0</td>
<td>0</td>
<td>0.29</td>
<td>-0.13</td>
<td>4</td>
<td>0</td>
<td>FALSE</td>
</tr>
<tr>
<td>5</td>
<td>0</td>
<td>0</td>
<td>0.29</td>
<td>-0.13</td>
<td>3.2</td>
<td>1</td>
<td>TRUE</td>
</tr>
<tr>
<td>6</td>
<td>1</td>
<td>0</td>
<td>0.29</td>
<td>0.56</td>
<td>6</td>
<td>0</td>
<td>TRUE</td>
</tr>
<tr>
<td>7</td>
<td>1</td>
<td>0</td>
<td>0.29</td>
<td>0.56</td>
<td>3.2</td>
<td>1</td>
<td>TRUE</td>
</tr>
</tbody>
</table>
<p></p>
<p>‘vtreat’ is designed to be concise, yet implement substantial data preparation and cleaning.</p>
<h2>What is new</h2>
<p>This release concentrates on code-cleanup and convenience functions inspired by Nina Zumel’s recent article on y-aware PCA/PCR (my note why you should read this series is <a target="_blank" href="http://www.win-vector.com/blog/2016/06/why-you-should-read-nina-zumels-3-part-series-on-principal-components-analysis-and-regression/">here</a>). In particular we now have user facing functions and documentation on:</p>
<ul>
<li>‘vtreat’ <a target="_blank" href="http://winvector.github.io/vtreat/vtreatScaleMode.html">y-aware scaling</a>. This implements the y-aware methods <a target="_blank" href="http://www.win-vector.com/blog/2016/05/pcr_part2_yaware/">described here</a>. This includes the important variation that all calculations are “simulated out of sample” or “cross validated” when you replace the ‘vtreat::designTreatments[N/C/Z]’/’vtreat::prepare’ pattern with the ‘vtreat::mkCrossFrame[N/C]Experiment’ pattern. We suggest the ‘designTreatments[N/C/Z]/prepare’ pattern for speed and ease of description and the ‘mkCrossFrame[N/C]Experiment’ if you are suspect over-fitting in the preparation step.</li>
<li><a target="_blank" href="http://winvector.github.io/vtreat/vtreatSplitting.html">y-stratified splitting.</a> Procedures in ‘vtreat’ tend to be “y-aware” so we upgraded the cross-validation (simulated out of sample) methods to also be “y-aware” and stratify on the outcome. This can greatly decrease model fitting variance especially when modeling rare outcomes.</li>
<li><a target="_blank" href="http://winvector.github.io/vtreat/vtreatGrouping.html">User controlled data grouping.</a> ‘vtreat’ uses cross-validations methods throughout to attempt to simulate model performance on new application data. In many situations much cross-validation or data splitting must preserve record or row grouping to be at all meaningful. For example it may not make sense to split multiple records taken from a single patient into the training and test group, we may instead prefer that each patient have all their records either in training or test. ‘vtreat’ now allows specification of record groups or even user supplied splitting functions as documented <a target="_blank" href="http://winvector.github.io/vtreat/vtreatGrouping.html">here</a>.</li>
</ul>
<p>‘vtreat’ now has essentially two workflows:</p>
<ul>
<li>‘vtreat::designTreatments[N/C/Z]’/’vtreat::prepare’ a faster, more intuitive, more deterministic, and easier to explain/describe workflow.</li>
<li>‘vtreat::mkCrossFrame[N/C]Experiment’ a bit more expensive in time and space, and more resistant to over-fitting workflow.</li>
</ul>
<p>We think analysts/data-scientists will be well served by learning both workflows and picking the work workflow most appropriate to the data set at hand.</p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/vtreat-version-0-5-26-released-on-cran/"></div></div><div><a data-url="http://www.r-bloggers.com/vtreat-version-0-5-26-released-on-cran/" data-counturl="http://www.r-bloggers.com/vtreat-version-0-5-26-released-on-cran/" data-count="vertical" data-text="vtreat version 0.5.26 released on CRAN" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.win-vector.com/blog/2016/07/vtreat-version-0-5-26-released-on-cran/"> R – Win-Vector Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/kPwEivbdaRg"></a></div></center></code></code></center></code>