<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Modelplot[R/py] introduction</title><link href="https://modelplot.github.io/" rel="alternate"></link><link href="https://modelplot.github.io/feeds/modelplotr.tag.atom.xml" rel="self"></link><id>https://modelplot.github.io/</id><updated>2019-04-25T23:55:00+02:00</updated><entry><title>modelplotr v1.0 now on CRAN: Visualize the Business Value of your Predictive Models</title><link href="https://modelplot.github.io/intro_modelplotr.html" rel="alternate"></link><published>2019-04-25T23:55:00+02:00</published><updated>2019-04-25T23:55:00+02:00</updated><author><name>Jurriaan Nagelkerke</name></author><id>tag:modelplot.github.io,2019-04-25:intro_modelplotr.html</id><summary type="html">&lt;p&gt;&lt;img alt="plot of chunk topviz" src="https://modelplot.github.io/img/modelplotr_CRAN-topviz-1.gif" /&gt;&lt;/p&gt;
&lt;h3&gt;Summary&lt;/h3&gt;
&lt;p&gt;In this blog we explain most valuable evaluation plots to assess the business value of a predictive model. Since these visualisations are not included in most popular model building packages or modules in R and Python, we show how you can easily create these plots for your own predictive models with our modelplotr r package and our modelplotpy python module &lt;a href="https://modelplot.github.io/intro_modelplotpy.html"&gt;(Prefer python? Read all about modelplotpy here!)&lt;/a&gt;. This will help you to explain your model's business value in laymans terms to non-techies. &lt;/p&gt;
&lt;h3&gt;Intro&lt;/h3&gt;
&lt;p&gt;&lt;img alt=" " src="img/cartoonrocplot.jpg" /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;‘...And as we can see clearly on this ROC plot, the sensitivity of the model at the value of 0.2 on one minus the specificity is quite high! Right?…’. &lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;If your fellow business colleagues didn’t already wander away during your presentation about your fantastic predictive model, it will definitely push them over the edge when you start talking like this. Why? Because the ROC curve is not easy to quickly explain and also difficult to translate into answers on the business questions your spectators have. And these business questions were the reason you’ve built a model in the first place!   &lt;/p&gt;
&lt;p&gt;What business questions? We build models for all kinds of supervised classification problems. Such as predictive models to select the best records in a dataset, which can be customers, leads, items, events... For instance: You want to know which of your active customers have the highest probability to churn; you need to select those prospects that are most likely to respond to an offer; you have to identify transactions that have a high risk to be fraudulent. During your presentation, your audience is therefore mainly focused on answering questions like &lt;em&gt;Does your model enable us to our target audience? How much better are we, using your model? What will the expected response on our campaign be? What is the financial impact of using your model?&lt;/em&gt;    &lt;/p&gt;
&lt;p&gt;During our model building efforts, we should already be focused on verifying how well the model performs. Often, we do so by training the model parameters on a selection or subset of records and test the performance on a holdout set or external validation set. We look at a set of performance measures like the ROC curve and the AUC value. These plots and statistics are very helpful to check during model building and optimization whether your model is under- or overfitting and what set of parameters performs best on test data. However, these statistics are not that valuable in assessing the business value the model you developed. &lt;/p&gt;
&lt;p&gt;One reason that the ROC curve is not that useful in explaining the business value of your model, is because  it’s quite hard to explain the interpretation of ‘area under the curve’, ‘specificity’ or ‘sensitivity’ to business people. Another important reason that these statistics and plots are useless in your business meetings is that they don’t help in determining &lt;em&gt;how&lt;/em&gt; to apply your predictive model: What percentage of records should we select based on the model? Should we select only the best 10% of cases? Or should we stop at 30%? Or go on until we have selected 70%?...  This is something you want to decide &lt;em&gt;together&lt;/em&gt; with your business colleague to best match the business plans and campaign targets they have to meet. The four plots - the cumulative gains, cumulative lift, response and cumulative response - and three financial plots - costs &amp;amp; revenues, profit and return on investment - we are about to introduce are in our view the best ones for that cause.&lt;/p&gt;
&lt;h3&gt;Installing modelplotr&lt;/h3&gt;
&lt;p&gt;Before we start exploring the plots, let's install our &lt;strong&gt;modelplotr&lt;/strong&gt; package. Since it is available on &lt;strong&gt;CRAN&lt;/strong&gt; it can easily be installed. All source code and latest developments are also available on &lt;a href="https://github.com/modelplot/modelplotr"&gt;github&lt;/a&gt;. &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nf"&gt;install.packages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;modelplotr&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now we're ready to use modelplotr. In the &lt;strong&gt;package vignette&lt;/strong&gt; (also available &lt;a href="https://modelplot.github.io/intro_modelplotpy.html"&gt;here&lt;/a&gt;) we go into much more detail on our modelplot package in r and all its functionalities. Here, we'll focus on using modelplotr with a business example. &lt;/p&gt;
&lt;h3&gt;Example: Predictive models from &lt;em&gt;caret&lt;/em&gt;, &lt;em&gt;mlr&lt;/em&gt;, &lt;em&gt;h2o&lt;/em&gt; and &lt;em&gt;keras&lt;/em&gt; on the &lt;em&gt;Bank Marketing Data Set&lt;/em&gt;&lt;/h3&gt;
&lt;p&gt;Let's get down to business! Our example is based on a publicly available dataset, called the Bank Marketing Data Set. It is one of the most popular datasets which is made available on the &lt;a href="https://archive.ics.uci.edu/ml/index.php"&gt;UCI Machine Learning Repository&lt;/a&gt;. The data set comes from a Portugese bank and deals with a frequently-posed marketing question: whether a customer did or did not acquire a term deposit, a financial product. There are 4 datasets available and the &lt;strong&gt;bank-additional-full.csv&lt;/strong&gt; is the one we use. It contains the information of 41.188 customers and 21 columns of information. &lt;/p&gt;
&lt;p&gt;To illustrate how to use modelplotr, let's say that we work as a data scientist for this bank and our marketing colleagues have asked us to help to select the customers that are most likely to respond to a term deposit offer. For that purpose, we will develop a predictive model and create the plots to discuss the results with our marketing colleagues. Since we want to show you how to build the plots, not how to build a perfect model, we'll only use six of the available columns as features in our example. Here’s a short description on the data we use:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;y&lt;/strong&gt;: has the client subscribed a term deposit?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;duration&lt;/strong&gt;: last contact duration, in seconds (numeric)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;campaign&lt;/strong&gt;: number of contacts performed during this campaign and for this client&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;pdays&lt;/strong&gt;: number of days that passed by after the client was last contacted from a previous campaign&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;previous&lt;/strong&gt;: number of contacts performed before this campaign and for this client (numeric)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;euribor3m&lt;/strong&gt;: euribor 3 month rate&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Let's load the data and have a quick look at it:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# download bank data and prepare &lt;/span&gt;

&lt;span class="c1"&gt;#zipname = &amp;#39;https://archive.ics.uci.edu/ml/machine-learning-databases/00222/bank-additional.zip&amp;#39;&lt;/span&gt;
&lt;span class="c1"&gt;# we encountered that the source at uci.edu is not always available, therefore we made a copy to our repos.&lt;/span&gt;
&lt;span class="n"&gt;zipname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;https://modelplot.github.io/img/bank-additional.zip&amp;#39;&lt;/span&gt;
&lt;span class="n"&gt;csvname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;bank-additional/bank-additional-full.csv&amp;#39;&lt;/span&gt;
&lt;span class="n"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="nf"&gt;tempfile&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;download.file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;zipname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;wb&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;bank&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="nf"&gt;read.table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;unzip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;csvname&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;sep&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stringsAsFactors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;FALSE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;header&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;unlink&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;bank&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;bank[&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nf"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;y&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;duration&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;campaign&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;pdays&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;previous&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;euribor3m&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# rename target class value &amp;#39;yes&amp;#39; for better interpretation and convert to factor&lt;/span&gt;
&lt;span class="n"&gt;bank&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="n"&gt;y[bank&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;yes&amp;#39;&lt;/span&gt;&lt;span class="n"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;term.deposit&amp;#39;&lt;/span&gt;
&lt;span class="n"&gt;bank&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="nf"&gt;as.factor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bank&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#explore data&lt;/span&gt;
&lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bank&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;## &amp;#39;data.frame&amp;#39;:    41188 obs. of  6 variables:&lt;/span&gt;
&lt;span class="c1"&gt;##  $ y        : Factor w/ 2 levels &amp;quot;no&amp;quot;,&amp;quot;term.deposit&amp;quot;: 1 1 1 1 1 1 1 1 1 1 ...&lt;/span&gt;
&lt;span class="c1"&gt;##  $ duration : int  261 149 226 151 307 198 139 217 380 50 ...&lt;/span&gt;
&lt;span class="c1"&gt;##  $ campaign : int  1 1 1 1 1 1 1 1 1 1 ...&lt;/span&gt;
&lt;span class="c1"&gt;##  $ pdays    : int  999 999 999 999 999 999 999 999 999 999 ...&lt;/span&gt;
&lt;span class="c1"&gt;##  $ previous : int  0 0 0 0 0 0 0 0 0 0 ...&lt;/span&gt;
&lt;span class="c1"&gt;##  $ euribor3m: num  4.86 4.86 4.86 4.86 4.86 ...&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;On this data, we've applied some predictive modeling techniques. To show modelplotr can be used for any kind of model, built with numerous packages, we've created some models with the &lt;a href="https://topepo.github.io/caret/index.html"&gt;&lt;strong&gt;caret package&lt;/strong&gt;&lt;/a&gt;, the &lt;a href="https://mlr-org.github.io/mlr/"&gt;&lt;strong&gt;mlr package&lt;/strong&gt;&lt;/a&gt;, the &lt;a href="http://docs.h2o.ai/"&gt;&lt;strong&gt;h2o package&lt;/strong&gt;&lt;/a&gt; and  the &lt;a href="https://keras.rstudio.com/"&gt;&lt;strong&gt;keras package&lt;/strong&gt;&lt;/a&gt;. These four are very popular R packages to build models with many predictive modeling techniques, such as logistic regression, random forest, XG boost, svm, neural nets and many, many others. When you've built your model with one of these packages, using modelplotr is super simple. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;mlr&lt;/strong&gt;, &lt;strong&gt;caret&lt;/strong&gt;, &lt;strong&gt;h2o&lt;/strong&gt; and &lt;strong&gt;keras&lt;/strong&gt; provide numerous different algorithms for binary classification. It should be noted, that to use our &lt;strong&gt;modelplotr&lt;/strong&gt; package, you don't have to use  one of these packages to build your models. It's just a tiny bit more work to use modelplotr for models created differently, using R or even outside or R! More on this in the vignette (see: &lt;strong&gt;vignette(modelplotr)&lt;/strong&gt; or go &lt;a href="https://modelplot.github.io/intro_modelplotpy.html"&gt;here&lt;/a&gt;. For now, to have a few models to evaluate with our plots, we do take advantage of mlr's/caret's/h2o's/keras' greatness.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# prepare data for training and train models &lt;/span&gt;
&lt;span class="n"&gt;test_size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0.3&lt;/span&gt;
&lt;span class="n"&gt;train_index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="nf"&gt;sample&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;seq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;nrow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bank&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;test_size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nf"&gt;nrow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bank&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;replace&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;F&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;train&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bank[train_index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bank[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;train_index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;#train models using mlr...&lt;/span&gt;
&lt;span class="n"&gt;trainTask&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;mlr&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;makeClassifTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;y&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;testTask&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;mlr&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;makeClassifTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;y&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;mlr&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;configureMlr&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;# this line is needed when using mlr without loading it (mlr::)&lt;/span&gt;
&lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mlr&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;makeClassifTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;y&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;lrn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mlr&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;makeLearner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;classif.randomForest&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;predict.type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;prob&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;rf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mlr&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;train&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lrn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#... or train models using caret...&lt;/span&gt;
&lt;span class="c1"&gt;# setting caret cross validation, here tuned for speed (not accuracy!)&lt;/span&gt;
&lt;span class="n"&gt;fitControl&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;caret&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;trainControl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;cv&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;classProbs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;TRUE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# mnl model using glmnet package&lt;/span&gt;
&lt;span class="n"&gt;mnl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;caret&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;train&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="n"&gt;.,data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;glmnet&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;trControl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fitControl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;## Warning in load(system.file(&amp;quot;models&amp;quot;, &amp;quot;models.RData&amp;quot;, package = &amp;quot;caret&amp;quot;)):&lt;/span&gt;
&lt;span class="c1"&gt;## strings not representable in native encoding will be translated to UTF-8&lt;/span&gt;

&lt;span class="c1"&gt;#... or train models using h2o...&lt;/span&gt;
&lt;span class="n"&gt;h2o&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;h2o.init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;## Warning in h2o.clusterInfo(): &lt;/span&gt;
&lt;span class="c1"&gt;## Your H2O cluster version is too old (3 months and 27 days)!&lt;/span&gt;
&lt;span class="c1"&gt;## Please download and install the latest version from http://h2o.ai/download/&lt;/span&gt;
&lt;span class="n"&gt;h2o&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;h2o.no_progress&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;h2o_train&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;h2o&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;as.h2o&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;h2o_test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;h2o&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;as.h2o&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;gbm&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;h2o&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;h2o.gbm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;y&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setdiff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;colnames&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;y&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                    &lt;span class="n"&gt;training_frame&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;h2o_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;nfolds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#... or train models using keras.&lt;/span&gt;
&lt;span class="n"&gt;x_train&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="nf"&gt;as.matrix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;train[&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;-1&lt;/span&gt;&lt;span class="n"&gt;]&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;train[&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;to_categorical&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;as.numeric&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="m"&gt;-1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;`%&amp;gt;%`&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;magrittr&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;`%&amp;gt;%`&lt;/span&gt;
&lt;span class="n"&gt;nn&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;keras_model_sequential&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;%&lt;/span&gt;
&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;layer_dense&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;units&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;kernel_initializer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;uniform&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;activation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;relu&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                   &lt;span class="n"&gt;input_shape&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;NCOL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x_train&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="o"&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;layer_dense&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;units&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;kernel_initializer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;uniform&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;activation&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;relu&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;layer_dense&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;units&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;levels&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;train[&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;&lt;span class="n"&gt;activation&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;softmax&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;nn&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;%&lt;/span&gt; &lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;optimizer&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;rmsprop&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;loss&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;categorical_crossentropy&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;accuracy&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;nn&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;%&lt;/span&gt; &lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;epochs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;batch_size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1028&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Ok, we’ve generated some predictive models. Now, let’s prepare the data for plotting! We will focus on explaining to our marketing colleagues how good our predictive model works and how it can help them select customers for their term deposit campaign.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nf"&gt;library&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;modelplotr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# transform datasets and model objects into scored data and calculate ntiles &lt;/span&gt;
&lt;span class="c1"&gt;# preparation steps&lt;/span&gt;
&lt;span class="n"&gt;scores_and_ntiles&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="nf"&gt;prepare_scores_and_ntiles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;datasets&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;train&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;test&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                      &lt;span class="n"&gt;dataset_labels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;train data&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;test data&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                      &lt;span class="n"&gt;models&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;rf&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;mnl&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;gbm&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;nn&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                      &lt;span class="n"&gt;model_labels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;random forest&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;multinomial logit&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                          &lt;span class="s"&gt;&amp;quot;gradient boosted trees&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;artificial neural network&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                      &lt;span class="n"&gt;target_column&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;y&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                      &lt;span class="n"&gt;ntiles&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;## ... scoring mlr model &amp;quot;rf&amp;quot; on dataset &amp;quot;train&amp;quot;.&lt;/span&gt;
&lt;span class="c1"&gt;## ... scoring caret model &amp;quot;mnl&amp;quot; on dataset &amp;quot;train&amp;quot;.&lt;/span&gt;
&lt;span class="c1"&gt;## ... scoring h2o model &amp;quot;gbm&amp;quot; on dataset &amp;quot;train&amp;quot;.&lt;/span&gt;
&lt;span class="c1"&gt;## ... scoring keras model &amp;quot;nn&amp;quot; on dataset &amp;quot;train&amp;quot;.&lt;/span&gt;
&lt;span class="c1"&gt;## ... scoring mlr model &amp;quot;rf&amp;quot; on dataset &amp;quot;test&amp;quot;.&lt;/span&gt;
&lt;span class="c1"&gt;## ... scoring caret model &amp;quot;mnl&amp;quot; on dataset &amp;quot;test&amp;quot;.&lt;/span&gt;
&lt;span class="c1"&gt;## ... scoring h2o model &amp;quot;gbm&amp;quot; on dataset &amp;quot;test&amp;quot;.&lt;/span&gt;
&lt;span class="c1"&gt;## ... scoring keras model &amp;quot;nn&amp;quot; on dataset &amp;quot;test&amp;quot;.&lt;/span&gt;
&lt;span class="c1"&gt;## Data preparation step 1 succeeded! Dataframe created.&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;What just happened? In the &lt;strong&gt;prepare_scores_and_ntiles&lt;/strong&gt; function, we've scored the customers in the train dataset and test dataset with their probability to acquire a term deposit, according to the predictive models we've just built with &lt;strong&gt;caret&lt;/strong&gt;, &lt;strong&gt;mlr&lt;/strong&gt;, &lt;strong&gt;h2o&lt;/strong&gt; and &lt;strong&gt;keras&lt;/strong&gt;. Aside from the datasets and model objects, we had to specify the name of the target variable and for our convenience, we gave our datasets and models some useful labels. These labels are used in the plots. And we could specify how many ntiles we want - bear with us for a few seconds, we'll get into the details of ntiles in a while. Let's have a look at some lines from the dataframe &lt;strong&gt;scores_and_ntiles&lt;/strong&gt; we just created:&lt;/p&gt;
&lt;table class="table table-striped table-hover table-condensed" style="font-size: 10px; margin-left: auto; margin-right: auto;"&gt;
 &lt;thead&gt;
  &lt;tr&gt;
   &lt;th style="text-align:left;"&gt; model_label &lt;/th&gt;
   &lt;th style="text-align:left;"&gt; dataset_label &lt;/th&gt;
   &lt;th style="text-align:left;"&gt; y_true &lt;/th&gt;
   &lt;th style="text-align:right;"&gt; prob_no &lt;/th&gt;
   &lt;th style="text-align:right;"&gt; prob_term.deposit &lt;/th&gt;
   &lt;th style="text-align:right;"&gt; ntl_no &lt;/th&gt;
   &lt;th style="text-align:right;"&gt; ntl_term.deposit &lt;/th&gt;
  &lt;/tr&gt;
 &lt;/thead&gt;
&lt;tbody&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; random forest &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; train data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; no &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1.0000000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0000000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 44 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 63 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; multinomial logit &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; test data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; no &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.9818192 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0181808 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 33 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 68 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; random forest &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; test data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; no &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1.0000000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0000000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 6 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 85 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; gradient boosted trees &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; test data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; no &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.9874957 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0125043 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 52 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 49 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; artificial neural network &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; train data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; no &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.9848772 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0151228 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 52 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 49 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; artificial neural network &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; train data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; no &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.8355713 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.1644287 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 85 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 16 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; random forest &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; train data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; term.deposit &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.2040000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.7960000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 97 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 4 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; gradient boosted trees &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; test data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; no &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.9891243 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0108757 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 49 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 52 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; multinomial logit &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; train data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; no &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.9089722 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0910278 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 68 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 33 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; gradient boosted trees &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; train data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; no &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.9943736 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0056264 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 36 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 65 &lt;/td&gt;
  &lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The function created a dataframe, with per record in each dataset, per model the actual target value (y), the predicted probability per target class ('no' and 'term.deposit') and the bucketing in ntiles (1 to 100, we'll explain what they mean shortly).  &lt;/p&gt;
&lt;p&gt;Now that we have scored all models we want on all datasets we want for the target we want, we can take the last step before plotting. In this second step, we specify the scope of the analysis. For this, we use the &lt;strong&gt;plotting_scope&lt;/strong&gt; function and use the dataframe as our &lt;em&gt;prepared_input&lt;/em&gt;. There are some other parameters you might want to tweak. An important parameter is &lt;strong&gt;scope&lt;/strong&gt;, enabling you to set the analysis perspective you want to see in the plots. You can use modelplotr to evaluate your model(s) from several perspectives: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Interpret just one model (the default)&lt;/li&gt;
&lt;li&gt;Compare the model performance across different datasets&lt;/li&gt;
&lt;li&gt;Compare the performance across different models&lt;/li&gt;
&lt;li&gt;Compare the performance across different target classes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We don't set the "scope" parameter now, therefore the default - &lt;em&gt;no comparison&lt;/em&gt; - is chosen. 
We will keep it simple and evaluate - from a business perspective - how well a selected model will perform in a selected dataset for one target class. We can use other parameters to focus on a specific model (let's say the &lt;strong&gt;gradient boosted trees&lt;/strong&gt; model) and on a specific dataset (let's pick the &lt;strong&gt;test data&lt;/strong&gt;). When not specified, modelplotr will set a value for you. The default value for the target class is the smallest target category, in our case &lt;strong&gt;term.deposit&lt;/strong&gt; ; since we want to focus on customers that do take term deposits, this default is perfect so we don't specify it explicitly here: &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# transform data generated with prepare_scores_and_ntiles into aggregated data for chosen plotting scope &lt;/span&gt;
&lt;span class="n"&gt;plot_input&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="nf"&gt;plotting_scope&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prepared_input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scores_and_ntiles&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                             &lt;span class="n"&gt;select_model_label&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;gradient boosted trees&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                             &lt;span class="n"&gt;select_dataset_label&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;test data&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;## Data preparation step 2 succeeded! Dataframe created.&lt;/span&gt;
&lt;span class="c1"&gt;## &amp;quot;prepared_input&amp;quot; aggregated...&lt;/span&gt;
&lt;span class="c1"&gt;## Data preparation step 3 succeeded! Dataframe created.&lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;span class="c1"&gt;## No comparison specified, default values are used. &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;span class="c1"&gt;## Single evaluation line will be plotted: Target value &amp;quot;term.deposit&amp;quot; plotted for dataset &amp;quot;test data&amp;quot; and model &amp;quot;gradient boosted trees.&lt;/span&gt;
&lt;span class="c1"&gt;## &amp;quot;&lt;/span&gt;
&lt;span class="c1"&gt;## -&amp;gt; To compare models, specify: scope = &amp;quot;compare_models&amp;quot;&lt;/span&gt;
&lt;span class="c1"&gt;## -&amp;gt; To compare datasets, specify: scope = &amp;quot;compare_datasets&amp;quot;&lt;/span&gt;
&lt;span class="c1"&gt;## -&amp;gt; To compare target classes, specify: scope = &amp;quot;compare_targetclasses&amp;quot;&lt;/span&gt;
&lt;span class="c1"&gt;## -&amp;gt; To plot one line, do not specify scope or specify scope = &amp;quot;no_comparison&amp;quot;.&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;As you can see in the output above, modelplotr prints some guiding information about the options chosen and unused options to the console. We have generated an aggregated dataframe, with the scope and selections we want and many metrics used for our plots:&lt;/p&gt;
&lt;div style="border: 1px solid #ddd; padding: 0px; overflow-y: scroll; height:350px; overflow-x: scroll; width:100%; "&gt;&lt;table class="table table-striped table-hover table-condensed" style="font-size: 10px; width: auto !important; "&gt;
 &lt;thead&gt;
  &lt;tr&gt;
   &lt;th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"&gt; scope &lt;/th&gt;
   &lt;th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"&gt; model_label &lt;/th&gt;
   &lt;th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"&gt; dataset_label &lt;/th&gt;
   &lt;th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"&gt; target_class &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; ntile &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; neg &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; pos &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; tot &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; pct &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; negtot &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; postot &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; tottot &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; pcttot &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; cumneg &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; cumpos &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; cumtot &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; cumpct &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; gain &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; cumgain &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; gain_ref &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; gain_opt &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; lift &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; cumlift &lt;/th&gt;
   &lt;th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"&gt; cumlift_ref &lt;/th&gt;
   &lt;th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"&gt; legend &lt;/th&gt;
  &lt;/tr&gt;
 &lt;/thead&gt;
&lt;tbody&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; no_comparison &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; gradient boosted trees &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; test data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; term.deposit &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; NA &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; NA &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; NA &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; NA &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; NA &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; NA &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0000000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0000000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.00 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0000000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; NA &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; NA &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1 &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; term.deposit &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; no_comparison &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; gradient boosted trees &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; test data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; term.deposit &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 27 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 97 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 124 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.7822581 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 11014 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1343 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 12357 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.1086833 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 27 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 97 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 124 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.7822581 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0722264 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0722264 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.01 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0923306 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 7.197590 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 7.197590 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1 &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; term.deposit &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; no_comparison &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; gradient boosted trees &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; test data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; term.deposit &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 2 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 22 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 102 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 124 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.8225806 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 11014 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1343 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 12357 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.1086833 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 49 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 199 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 248 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.8024194 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0759494 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.1481757 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.02 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.1846612 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 7.568599 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 7.383095 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1 &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; term.deposit &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; no_comparison &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; gradient boosted trees &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; test data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; term.deposit &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 3 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 45 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 78 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 123 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.6341463 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 11014 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1343 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 12357 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.1086833 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 94 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 277 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 371 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.7466307 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0580789 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.2062547 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.03 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.2762472 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 5.834807 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 6.869781 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1 &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; term.deposit &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; no_comparison &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; gradient boosted trees &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; test data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; term.deposit &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 4 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 48 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 76 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 124 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.6129032 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 11014 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1343 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 12357 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.1086833 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 142 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 353 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 495 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.7131313 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0565897 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.2628444 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.04 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.3685778 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 5.639349 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 6.561552 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1 &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; term.deposit &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; no_comparison &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; gradient boosted trees &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; test data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; term.deposit &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 5 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 46 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 77 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 123 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.6260163 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 11014 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1343 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 12357 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.1086833 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 188 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 430 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 618 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.6957929 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.0573343 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.3201787 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.05 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.4601638 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 5.760002 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 6.402020 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1 &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; term.deposit &lt;/td&gt;
  &lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;(plot_input has 101 rows and 25 columns)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;We're ready to start plotting now!&lt;/p&gt;
&lt;h3&gt;Let’s introduce the Gains, Lift and (cumulative) Response plots.&lt;/h3&gt;
&lt;p&gt;Before we throw more code and output at you, let’s get you familiar with the plots we so strongly advocate to use to assess a predictive model’s business value. Although each plot sheds light on the business value of your model from a different angle, they all use the same data: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Predicted probability for the target class&lt;/li&gt;
&lt;li&gt;Equally sized groups based on this predicted probability, named ntiles&lt;/li&gt;
&lt;li&gt;Actual number of observed target class observations in these groups (ntiles)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Regarding the &lt;strong&gt;ntiles&lt;/strong&gt;: It’s common practice to split the data to score into 10 equally large groups and call these groups &lt;em&gt;deciles&lt;/em&gt;. Observations that belong to the top-10% with highest model probability in a set, are in decile 1 of that set; the next group of 10% with high model probability are decile 2 and finally the 10% observations with the lowest model probability on the target class belong to decile 10. &lt;/p&gt;
&lt;p&gt;*Notice that modelplotr does support that you specify the number of equally sized groups with the parameter &lt;strong&gt;ntiles&lt;/strong&gt;. Hence, &lt;strong&gt;ntiles=100&lt;/strong&gt; results in 100 equally sized groups with in the first group the 1% with the highest model probability and in group 100 the 1% with the lowest model probability. These groups are often referred to as percentiles; modelplotr will also label them as such. Any value between 4 and 100 can be specified for &lt;strong&gt;ntiles&lt;/strong&gt;. &lt;/p&gt;
&lt;p&gt;Each of the plots in modelplotr places the ntiles on the x axis and another measure on the y axis. The ntiles are plotted from left to right so the observations with the highest model probability are on the left side of the plot. This results in plots like this:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="img/decileplot.png" /&gt; &lt;/p&gt;
&lt;p&gt;Now that it’s clear what is on the horizontal axis of each of the plots, we can go into more detail on the metrics for each plot on the vertical axis. For each plot, we’ll start with a brief explanation what insight you gain with the plot from a business perspective. After that, we apply it to our banking data and show some neat features of modelplotr to help you explain the value of your wonderful predictive models to others.&lt;/p&gt;
&lt;h4&gt;1. Cumulative gains plot&lt;/h4&gt;
&lt;p&gt;The cumulative gains plot - often named ‘gains plot’ - helps you answer the question:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:orange"&gt;When we apply the model and select the best X ntiles, what % of the actual target class observations can we expect to target?&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;
&lt;p&gt;Hence, the cumulative gains plot visualises the percentage of the target class members you have selected if you would decide to select up until ntile X. This is a very important business question, because in most cases, you want to use a predictive model to target a &lt;strong&gt;subset&lt;/strong&gt; of observations - customers, prospects, cases,... - instead of targeting all cases. And since we won't build perfect models all the time, we will miss some potential. And that's perfectly all right, because if we are not willing to accept that, we should not use a model in the first place. Or build only perfect models, that scores all actual target class members with a 100% probability and all the cases that do not belong to the target class with a 0% probability. However, if you’re such a wizard, you don’t need these plots any way or you should have a careful look at your model - maybe you’re cheating?....  &lt;/p&gt;
&lt;p&gt;So, we'll have to accept we will lose some. &lt;em&gt;What percentage&lt;/em&gt; of the actual target class members you do select with your model at a given ntile, that’s what the cumulative gains plot tells you. The plot comes with two reference lines to tell you how good/bad your model is doing: The &lt;em&gt;random model line&lt;/em&gt; and the &lt;em&gt;wizard model line&lt;/em&gt;. The random model line tells you what proportion of the actual target class you would expect to select when no model is used at all. This vertical line runs from the origin (with 0% of cases, you can only have 0% of the actual target class members) to the upper right corner (with 100% of the cases, you have 100% of the target class members). It’s the rock bottom of how your model can perform; are you close to this, then your model is not much better than a coin flip. The wizard model is the upper bound of what your model can do. It starts in the origin and rises as steep as possible towards 100%. Say, exactly 10% of all cases belong to the target category. This means that this line goes steep up from the origin to the value of decile 1 (or percentile 10 in case ntiles=100) and cumulative gains of 100% and remains there for all other ntiles as it is a cumulative measure. Your model will always move between these two reference lines - closer to a wizard is always better -  and looks like this: &lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="img/cumgainsplot.png" /&gt;&lt;/p&gt;
&lt;p&gt;Back to our business example. How many of the term deposit buyers can we select with the top-20% of our predictive models? Let's find out! To generate the cumulate gains plot, we can simply call the function &lt;strong&gt;plot_cumgains()&lt;/strong&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# plot the cumulative gains plot&lt;/span&gt;
&lt;span class="nf"&gt;plot_cumgains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk gainsplot" src="https://modelplot.github.io/img/modelplotr_CRAN-gainsplot-1.png" /&gt;&lt;/p&gt;
&lt;p&gt;We don't need to specify any other parameters than the data to use, &lt;strong&gt;plot_input&lt;/strong&gt;, which is generated with the &lt;strong&gt;plotting_scope()&lt;/strong&gt; function we ran previously. There are several other parameters available to customize the plot, though. If we want to emphasize the model performance at a specific ntile, we can add both highlighting to the plot and add some explanatory text below the plot. Both are optional, though:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# plot the cumulative gains plot and annotate the plot at percentile = 20&lt;/span&gt;
&lt;span class="nf"&gt;plot_cumgains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;highlight_ntile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk gainsplotannotated" src="https://modelplot.github.io/img/modelplotr_CRAN-gainsplotannotated-1.png" /&gt;&lt;/p&gt;
&lt;p&gt;Our &lt;strong&gt;highlight_ntile&lt;/strong&gt; parameter adds some guiding elements to the plot at ntile 20 as well as a text box below the graph with the interpretation of the plot at ntile 20 in words. This interpretation is also printed to the console. Our simple model - only 6 pedictors were used - seems to do a nice job selecting the customers interested in buying term deposites. &lt;em&gt;When we select 20% with the highest probability according to gradient boosted trees, this selection holds 87% of all term deposit cases in test data.&lt;/em&gt; With a perfect model, we would have selected 100%, since less than 20% of all customers in the test set buy term deposits. A random pick would only hold 20% of the customers with term deposits. How much better than random do we do? This brings us to plot number two! &lt;/p&gt;
&lt;h4&gt;2. Cumulative lift plot&lt;/h4&gt;
&lt;p&gt;The cumulative lift plot, often referred to as lift plot or index plot, helps you answer the question:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:orange"&gt;When we apply the model and select the best X ntiles, how many times better is that than using no model at all?&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The lift plot helps you in explaining how much better selecting based on your model is compared to taking random selections instead. Especially when models are not yet used that often within your organisation or domain, this really helps business understand what selecting based on models can do for them. &lt;/p&gt;
&lt;p&gt;The lift plot only has one reference line: the ‘random model’.  With a random model we mean that each observation gets a random number and all cases are devided into ntiles based on these random numbers. When we would do that, the % of actual target category observations in each ntile would be equal to the overall % of actual target category observations in the total set. Since the lift is calculated as the ratio of these two numbers, we get a horizontal line at the value of 1. Your model should however be able to do better, resulting in a high ratio for ntile 1. How high the lift can get, depends on the quality of your model, but also on the % of target class observations in the data: If 50% of your data belongs to the target class of interest, a perfect model would 'only' do twice as good (lift: 2) as a random selection. With a smaller target class value, say 10%, the model can potentially be 10 times better (lift: 10) than a random selection. Therefore, no general guideline of a 'good' lift can be specified. Towards the last ntile, since the plot is cumulative, with 100% of cases, we have the whole set again and therefore the cumulative lift will always end up at a value of 1. It looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="img/cumliftplot.png" /&gt;&lt;/p&gt;
&lt;p&gt;To generate the cumulative lift plot for our gradient boosted trees model predicting term deposit buying, we call the function &lt;strong&gt;plot_cumlift()&lt;/strong&gt;. Let's add some highlighting to see how much better a selection based on our model containing the best 20 (perce)ntiles would be, compared to a random selection of 20% of all customers:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# plot the cumulative lift plot and annotate the plot at percentile = 20&lt;/span&gt;
&lt;span class="nf"&gt;plot_cumlift&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;highlight_ntile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## Plot annotation for plot: Cumulative lift&lt;/span&gt;
&lt;span class="c1"&gt;## - When we select 20% with the highest probability according to model gradient boosted trees in test data, this selection for term.deposit cases is 4.3 times better than selecting without a model. &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk liftplot" src="https://modelplot.github.io/img/modelplotr_CRAN-liftplot-1.png" /&gt;&lt;/p&gt;
&lt;p&gt;A term deposit campaign targeted at a selection of 20% of all customers based on our gradient boosted trees model can be expected to have a 4 times higher response (434%) compared to a random sample of customers. Not bad, right? The cumulative lift really helps in getting a positive return on marketing investments. It should be noted, though, that since the cumulative lift plot is relative, it doesn't tell us how high the actual reponse will be on our campaign...   &lt;/p&gt;
&lt;h4&gt;3. Response plot&lt;/h4&gt;
&lt;p&gt;One of the easiest to explain evaluation plots is the response plot. It simply plots the percentage of target class observations per ntile. It can be used to answer the following business question:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:orange"&gt;When we apply the model and select ntile X, what is the expected % of target class observations in that ntile?&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;
&lt;p&gt;The plot has one reference line: The % of target class cases in the total set. It looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="img/responseplot.png" /&gt;&lt;/p&gt;
&lt;p&gt;A good model starts with a high response value in the first ntile(s) and suddenly drops quickly towards 0 for later ntiles. This indicates good differentiation between target class members - getting high model scores - and all other cases. An interesting point in the plot is the location where your model’s line intersects the random model line. From that ntile onwards, the % of target class cases is lower than a random selection of cases would hold.  &lt;/p&gt;
&lt;p&gt;To generate the response plot for our term deposit model, we can simply call the function &lt;strong&gt;plot_response()&lt;/strong&gt;. Let's immediately highlight the plot to have the interpretation of the response plot at (perce)ntile 10 added to the plot:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# plot the response plot and annotate the plot at ntile = 10&lt;/span&gt;
&lt;span class="nf"&gt;plot_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;highlight_ntile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## Plot annotation for plot: Response&lt;/span&gt;
&lt;span class="c1"&gt;## - When we select ntile 10 according to model gradient boosted trees in dataset test data the % of term.deposit cases in the selection is 50.4%. &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk responseplot" src="https://modelplot.github.io/img/modelplotr_CRAN-responseplot-1.png" /&gt;&lt;/p&gt;
&lt;p&gt;As the plot shows and the text below the plot states: &lt;em&gt;When we select decile 1 according to model gradient boosted trees in dataset test data the % of term deposit cases in the selection is 51%.&lt;/em&gt;. This is quite good, especially when compared to the overall likelihood of 12%. The response in the 20th ntile is much lower, about 10%. From ntile 22 onwards, the expected response is lower than the overall likelihood of 12%. However, most of the time, our model will be used to select the highest decile &lt;em&gt;up until&lt;/em&gt; some decile. That makes it even more relevant to have a look at the cumulative version of the response plot. And guess what, that's our final plot!   &lt;/p&gt;
&lt;h4&gt;4. Cumulative response plot&lt;/h4&gt;
&lt;p&gt;Finally, one of the most used plots: The cumulative response plot. It answers the question burning on each business reps lips:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:orange"&gt;When we apply the model and select up until ntile X, what is the expected % of target class observations in the selection?&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The reference line in this plot is the same as in the response plot: the % of target class cases in the total set. &lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="img/cumresponseplot.png" /&gt;&lt;/p&gt;
&lt;p&gt;Whereas the response plot crosses the reference line, in the cumulative response plot it never crosses it but ends up at the same point for the last ntile: Selecting all cases up until ntile 100 is the same as selecting all cases, hence the % of target class cases will be exactly the same. This plot is most often used to decide - together with business colleagues - up until what decile to select for a campaign. &lt;/p&gt;
&lt;p&gt;Back to our banking business case. To generate the cumulative response plot, we call the function &lt;strong&gt;plot_cumresponse()&lt;/strong&gt;. Let's highlight it at percentile 30 to see what the overall expected response will be if we select prospects for a term deposit offer based on our gradient boosted trees model:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# plot the cumulative response plot and annotate the plot at decile = 3&lt;/span&gt;
&lt;span class="nf"&gt;plot_cumresponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;highlight_ntile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## Plot annotation for plot: Cumulative response&lt;/span&gt;
&lt;span class="c1"&gt;## - When we select ntiles 1 until 30 according to model gradient boosted trees in dataset test data the % of term.deposit cases in the selection is 34.9%. &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk cumresponseplot" src="https://modelplot.github.io/img/modelplotr_CRAN-cumresponseplot-1.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;When we select ntiles 1 until 30 according to model gradient boosted trees in dataset test data the % of term deposit cases in the selection is 36%.&lt;/em&gt; Since the test data is an independent set, not used to train the model, we can expect the response on the term deposit campaign to be 36%. &lt;/p&gt;
&lt;p&gt;The cumulative response percentage at a given decile is a number your business colleagues can really work with: Is that response big enough to have a successfull campaign, given costs and other expectations? Will the absolute number of sold term deposits meet the targets? Or do we lose too much of all potential term deposit buyers by only selecting the top 30%? To answer that question, we can go back to the cumulative gains plot. And that's why there's no absolute winner among these plots and we advice to use them all. To make that happen, there's also a function to easily combine all four plots. &lt;/p&gt;
&lt;h4&gt;All four plots together&lt;/h4&gt;
&lt;p&gt;With the function call &lt;strong&gt;plot_multiplot&lt;/strong&gt; we get the previous four plots on one grid. We can easily save it to a file to include it in a presentation or share it with colleagues.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# plot all four evaluation plots and save to file, highlight decile 2&lt;/span&gt;
&lt;span class="nf"&gt;plot_multiplot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;highlight_ntile&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
               &lt;span class="n"&gt;save_fig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;TRUE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;save_fig_filename&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;Selection model Term Deposits&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## Plot annotation for plot: Cumulative gains&lt;/span&gt;
&lt;span class="c1"&gt;## - When we select 20% with the highest probability according to model gradient boosted trees, this selection holds 87% of all term.deposit cases in test data. &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## Plot annotation for plot: Cumulative lift&lt;/span&gt;
&lt;span class="c1"&gt;## - When we select 20% with the highest probability according to model gradient boosted trees in test data, this selection for term.deposit cases is 4.3 times better than selecting without a model. &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## Plot annotation for plot: Response&lt;/span&gt;
&lt;span class="c1"&gt;## - When we select ntile 2 according to model gradient boosted trees in dataset test data the % of term.deposit cases in the selection is 32.2%. &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## Plot annotation for plot: Cumulative response&lt;/span&gt;
&lt;span class="c1"&gt;## - When we select ntiles 1 until 2 according to model gradient boosted trees in dataset test data the % of term.deposit cases in the selection is 47.2%. &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;span class="c1"&gt;## Warning: No location for saved plot specified! Plot is saved to tempdir(). Specify &amp;#39;save_fig_filename&amp;#39; to customize location and name.&lt;/span&gt;
&lt;span class="c1"&gt;## Plot is saved as: C:\Users\J9AF3~1.NAG\AppData\Local\Temp\Rtmpc5waFv/Selection model Term Deposits.png&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk allplots" src="https://modelplot.github.io/img/modelplotr_CRAN-allplots-1.png" /&gt;&lt;/p&gt;
&lt;h4&gt;Even more business-savvy: Financial plots&lt;/h4&gt;
&lt;p&gt;And there's more! To plot the financial implications of implementing a predictive model, modelplotr provides three additional plots: the Costs &amp;amp; revenues plot, the Profit plot and the ROI plot. So, when you know what the fixed costs, variable costs and revenues per sale associated with a campaign based on your model are, you can use these to visualize financial consequences of using your model. Here, we'll just show the &lt;strong&gt;Profit plot&lt;/strong&gt;. See the package vignette for more details on the &lt;strong&gt;Costs &amp;amp; Revenues plot&lt;/strong&gt; and the &lt;strong&gt;Return on Investment plot&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The profit plot visualized the cumulative profit up until that decile when the model is used for campaign selection. It can be used to answer the following business question:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When we apply the model and select up until ntile X, what is the expected profit of the campaign?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img alt=" " src="img/profitplot.png" /&gt;&lt;/p&gt;
&lt;p&gt;From this plot, it can be quickly spotted with what selection size the campaign profit is maximized. However, this does not mean that this is the best option from an investment point of view. &lt;/p&gt;
&lt;p&gt;Business colleagues should be able to tell you the expected costs and revenues regarding the campaign. Let's assume they told us fixed costs for the campaign (a tv commercial and some glossy print material) are in total € 75,000 and each targeted customer costs another € 50 (prospects are called and receive an incentive) and the expected revenue per new term deposit customer is € 250 according to the business case. &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;#Profit plot - automatically highlighting the ntile where profit is maximized!&lt;/span&gt;
&lt;span class="nf"&gt;plot_profit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;fixed_costs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;75000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;variable_costs_per_unit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;profit_per_unit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;250&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## Plot annotation for plot: Profit&lt;/span&gt;
&lt;span class="c1"&gt;## - When we select ntiles 1 until 19 in dataset test data using model gradient boosted trees to target term.deposit cases the expected profit is &amp;lt;U+20AC&amp;gt;93,850 &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk plot_profit" src="https://modelplot.github.io/img/modelplotr_CRAN-plot_profit-1.png" /&gt;&lt;/p&gt;
&lt;p&gt;Using this plot, we can decide to select the top 19 ntiles according to our model to maximize profit and earn about € 94,000 with this campaign. Both decreasing and increasing the selection based on the model would harm profits, as the plot clearly shows.&lt;/p&gt;
&lt;p&gt;Neat! With these plots, we are able to talk with business colleagues about the actual value of our predictive model, without having to bore them with technicalities any nitty gritty details. We've translated our model in business terms and visualised it to simplify interpretation and communication. Hopefully, this helps many of you in discussing how to optimally take advantage of your predictive model building efforts.   &lt;/p&gt;
&lt;h3&gt;Get more out of modelplotr: using different scopes, highlight ntiles, customize text &amp;amp; colors.&lt;/h3&gt;
&lt;p&gt;As we mentioned earlier, the modelplotr package also enables to make interesting comparisons, using the &lt;strong&gt;scope&lt;/strong&gt; parameter. Comparisons between different models, between different datasets and (in case of a multiclass target) between different target classes. Also, modelplotr provides a lot of customization options: You can hightlight plots and add annotation texts to explain the plots, change all textual elements in the plots and customize line colors. Curious? Please have a look at the package documentation or read our other posts on modelplotr. &lt;/p&gt;
&lt;p&gt;However, to give one example, we could compare whether gradient boosted trees was indeed the best choice to select the top-30% customers for a term deposit offer:  &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# set plotting scope to model comparison&lt;/span&gt;
&lt;span class="n"&gt;plot_input&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="nf"&gt;plotting_scope&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prepared_input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scores_and_ntiles&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;scope&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;compare_models&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;## Data preparation step 2 succeeded! Dataframe created.&lt;/span&gt;
&lt;span class="c1"&gt;## &amp;quot;prepared_input&amp;quot; aggregated...&lt;/span&gt;
&lt;span class="c1"&gt;## Data preparation step 3 succeeded! Dataframe created.&lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;span class="c1"&gt;## Models &amp;quot;random forest&amp;quot;, &amp;quot;multinomial logit&amp;quot;, &amp;quot;gradient boosted trees&amp;quot;, &amp;quot;artificial neural network&amp;quot; compared for dataset &amp;quot;test data&amp;quot; and target value &amp;quot;term.deposit&amp;quot;.&lt;/span&gt;

&lt;span class="c1"&gt;# plot the cumulative response plot and annotate the plot at ntile 20&lt;/span&gt;
&lt;span class="nf"&gt;plot_cumresponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;highlight_ntile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## Plot annotation for plot: Cumulative response&lt;/span&gt;
&lt;span class="c1"&gt;## - When we select ntiles 1 until 20 according to model random forest in dataset test data the % of term.deposit cases in the selection is 46.5%. &lt;/span&gt;
&lt;span class="c1"&gt;## - When we select ntiles 1 until 20 according to model multinomial logit in dataset test data the % of term.deposit cases in the selection is 42.1%. &lt;/span&gt;
&lt;span class="c1"&gt;## - When we select ntiles 1 until 20 according to model gradient boosted trees in dataset test data the % of term.deposit cases in the selection is 47.2%. &lt;/span&gt;
&lt;span class="c1"&gt;## - When we select ntiles 1 until 20 according to model artificial neural network in dataset test data the % of term.deposit cases in the selection is 40.7%. &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk comparemodels" src="https://modelplot.github.io/img/modelplotr_CRAN-comparemodels-1.png" /&gt;&lt;/p&gt;
&lt;p&gt;Seems like the algorithm used will not make a big difference in this case. Hopefully you agree by now that using these plots really can make a difference in explaining the business value of your predictive models! &lt;/p&gt;
&lt;p&gt;You can read more on how to use modelplotr &lt;a href="https://github.com/jurrr/modelplotr/issues" target="_blank"&gt;here&lt;/a&gt;. In case you experience issues when using modelplotr, please let us know via the &lt;a href="https://github.com/jurrr/modelplotr/issues" target="_blank"&gt;issues section on Github&lt;/a&gt;. Any other feedback or suggestions, please let us know via &lt;a href="mailto:jurriaan.nagelkerke@gmail.com"&gt;jurriaan.nagelkerke@gmail.com&lt;/a&gt; or &lt;a href="mailto:pb.marcus@hotmail.com"&gt;pb.marcus@hotmail.com&lt;/a&gt;. Happy modelplotting!&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="img/cartoon2d.jpg" /&gt;&lt;/p&gt;</summary><category term="modelplot"></category><category term="R"></category><category term="modelplotr"></category><category term="CRAN"></category><category term="blog"></category></entry><entry><title>modelplotr vignette</title><link href="https://modelplot.github.io/vignette_modelplotr.html" rel="alternate"></link><published>2019-04-20T14:00:00+02:00</published><updated>2019-04-20T14:00:00+02:00</updated><author><name>Jurriaan Nagelkerke</name></author><id>tag:modelplot.github.io,2019-04-20:vignette_modelplotr.html</id><summary type="html">&lt;blockquote&gt;
&lt;p&gt;Why ROC curves are a bad idea to explain your model to business people&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The modelplotr package makes it easy to create a number of valuable evaluation plots to assess the business value of a predictive model. Using these plots, it can be shown how implementation of the model will impact business targets like response or return on investment of a campaign. &lt;/p&gt;
&lt;h2&gt;Why use modelplotr&lt;/h2&gt;
&lt;p&gt;&lt;img src="https://modelplot.github.io/img/cartoonrocplot.jpg" title="Cartoon ROC plot" alt="Cartoon ROC plot" width="100%" /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;‘...And as we can see clearly on this ROC plot, the sensitivity of the model at the value of 0.2 on one minus the specificity is quite high! Right?…’.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;If your fellow business colleagues didn’t already wander away during your presentation about your fantastic predictive model, it will definitely push them over the edge when you start talking like this. Why? Because the ROC curve is not easy to quickly explain and also difficult to translate into answers on the business questions your spectators have. And these business questions were the reason you’ve built a model in the first place!&lt;/p&gt;
&lt;p&gt;What business questions? We build models for all kinds of supervised classification problems. Such as predictive models to select the best records in a dataset, which can be customers, leads, items, events... For instance: You want to know which of your active customers have the highest probability to churn; you need to select those prospects that are most likely to respond to an offer; you have to identify transactions that have a high risk to be fraudulent. During your presentation, your audience is therefore mainly focused on answering questions like: Does your model enable us to select our target audience? How much better will we be doing, using your model? What will the expected response on our campaign be? What is the optimal selection size? Modelplotr helps you answer these busines questions.&lt;/p&gt;
&lt;p&gt;During our model building efforts, we should already be focused on verifying how well the model performs. Often, we do so by training the model parameters on a selection or subset of records and test the performance on a holdout set or external validation set. We look at a set of performance measures like the ROC curve and the AUC value. These plots and statistics are very helpful to check during model building and model optimization whether your model is under- or overfitting and what set of parameters performs best on test data. However, these statistics are not that valuable in assessing the &lt;em&gt;business value&lt;/em&gt; the model you developed.&lt;/p&gt;
&lt;p&gt;One reason that the ROC curve is not that useful in explaining the business value of your model, is because it’s quite hard to explain the interpretation of ‘area under the curve’, ‘specificity’ or ‘sensitivity’ to business people. Another important reason that these statistics and plots are useless in your business meetings is that they don’t help in determining how to apply your predictive model: What percentage of records should we select based on the model? Should we select only the best 10% of cases? Or should we stop at 30%? Or go on until we have selected 70%?... This is something you want to decide together with your business colleague to best match the business plans and campaign targets they have to meet. The four plots - the cumulative gains, cumulative lift, response and cumulative response - we are about to introduce are in our view the best ones for that cause. On top of that, we also introduce three plots that enable plotting the financial impact of using your model in a campaign: The costs &amp;amp; revenues plot, the profit plot and the return on investment plot. In the end, talking about financial consequences of implementing a is often the most effective when discussing the value of your model with business colleagues.   &lt;/p&gt;
&lt;h2&gt;The plots in modelplotr&lt;/h2&gt;
&lt;p&gt;Before getting into the details how to use modelplotr, let's first introduce the plots you can create with it in more detail. We begin by explaining what in is on the x axis all these plots. Next, we introduce the different measures that are plotted on the y axis of these plots. &lt;/p&gt;
&lt;h3&gt;All plots: explaining what's on the canvas&lt;/h3&gt;
&lt;p&gt;Although each plot sheds light on the business value of your model from a different angle, they all use the same data:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Predicted probability for the target class&lt;/li&gt;
&lt;li&gt;Equally sized groups based on this predicted probability, named ntiles&lt;/li&gt;
&lt;li&gt;Actual number of observed target class observations in these groups (ntiles)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Regarding the ntiles: It’s common practice to split the data to score into 10 equally large groups and call these groups deciles. Observations that belong to the top-10% with highest model probability in a set, are in decile 1 of that set; the next group of 10% with high model probability are decile 2 and finally the 10% observations with the lowest model probability on the target class belong to decile 10. &lt;/p&gt;
&lt;p&gt;*Notice that modelplotr does support that you specify the number of equally sized groups with the parameter &lt;strong&gt;ntiles&lt;/strong&gt;. Hence, &lt;strong&gt;ntiles=100&lt;/strong&gt; results in 100 equally sized groups with in the first group the 1% with the highest model probability and in group 100 the 1% with the lowest model probability. These groups are often referred to as percentiles; modelplotr will also label them as such. Any value between 4 and 100 can be specified for &lt;strong&gt;ntiles&lt;/strong&gt;. For illustration purposes, we will use deciles, hence the default of &lt;strong&gt;ntiles=10&lt;/strong&gt; *&lt;/p&gt;
&lt;p&gt;Each of the plots in modelplotr places the deciles on the x axis and another measure on the y axis. The deciles are plotted from left to right so the observations with the highest model probability are on the left side of the plot. This results in plots like this:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://modelplot.github.io/img/decileplot.png" title="plot of chunk decileplot" alt="plot of chunk decileplot" width="100%" /&gt;&lt;/p&gt;
&lt;p&gt;Now that it’s clear what is on the horizontal axis of each of the plots, we can go into more detail on the metrics for each plot on the vertical axis. For each plot, there's a brief explanation what insight you gain with the plot from a business perspective. &lt;/p&gt;
&lt;h3&gt;Cumulative gains plot&lt;/h3&gt;
&lt;p&gt;The cumulative gains plot - often named ‘gains plot’ - helps you answer the question:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When we apply the model and select the best X deciles, what % of the actual target class observations can we expect to target?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Hence, the cumulative gains plot visualises the percentage of the target class members you have selected if you would decide to select up until decile X. This is a very important business question, because in most cases, you want to use a predictive model to target a subset of observations - customers, prospects, cases,... - instead of targeting all cases. And since we won't build perfect models all the time, we will miss some potential. &lt;/p&gt;
&lt;p&gt;So, we'll have to accept we will lose some. What percentage of the actual target class members you do select with your model at a given decile, that’s what the cumulative gains plot tells you. The plot comes with two reference lines to tell you how good/bad your model is doing: The random model line and the wizard model line. The random model line tells you what proportion of the actual target class you would expect to select when no model is used at all. This vertical line runs from the origin (with 0% of cases, you can only have 0% of the actual target class members) to the upper right corner (with 100% of the cases, you have 100% of the target class members). It’s the rock bottom of how your model can perform; are you close to this, then your model is not much better than a coin flip. The wizard model is the upper bound of what your model can do. It starts in the origin and rises as steep as possible towards 100%. If less than 10% of all cases belong to the target category, this means that it goes steep up from the origin to the value of decile 1 and cumulative gains of 100% and remains there for all other deciles as it is a cumulative measure. Your model will always move between these two reference lines - closer to a wizard is always better - and looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://modelplot.github.io/img/cumgainsplot.png" title="plot of chunk cumgainsplot" alt="plot of chunk cumgainsplot" width="100%" /&gt;&lt;/p&gt;
&lt;h3&gt;Cumulative lift plot&lt;/h3&gt;
&lt;p&gt;The cumulative lift plot, often referred to as lift plot or index plot, helps you answer the question:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When we apply the model and select the best X deciles, how many times better is that than using no model at all?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The lift plot helps you in explaining how much better selecting based on your model is compared to taking random selections instead. Especially when models are not yet used within a certain organisation or domain, this really helps business understand what selecting based on models can do for them.&lt;/p&gt;
&lt;p&gt;The lift plot only has one reference line: the ‘random model’. With a random model we mean that each observation gets a random number and all cases are devided into deciles based on these random numbers. The % of actual target category observations in each decile would be equal to the overall % of actual target category observations in the total set. Since the lift is calculated as the ratio of these two numbers, we get a horizontal line at the value of 1. Your model should however be able to do better, resulting in a high ratio for decile 1. How high the lift can get, depends on the quality of your model, but also on the % of target class observations in the data: If 50% of your data belongs to the target class of interest, a perfect model would 'only' do twice as good (lift: 2) as a random selection. With a smaller target class value, say 10%, the model can potentially be 10 times better (lift: 10) than a random selection. Therefore, no general guideline of a 'good' lift can be specified. Towards decile 10, since the plot is cumulative, with 100% of cases, we have the whole set again and therefore the cumulative lift will always end up at a value of 1. It looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://modelplot.github.io/img/cumliftplot.png" title="plot of chunk cumliftplot" alt="plot of chunk cumliftplot" width="100%" /&gt;&lt;/p&gt;
&lt;h3&gt;Response plot&lt;/h3&gt;
&lt;p&gt;One of the easiest to explain evaluation plots is the response plot. It simply plots the percentage of target class observations per decile. It can be used to answer the following business question:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When we apply the model and select decile X, what is the expected % of target class observations in that decile?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The plot has one reference line: The % of target class cases in the total set. It looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://modelplot.github.io/img/responseplot.png" title="plot of chunk responseplot" alt="plot of chunk responseplot" width="100%" /&gt;&lt;/p&gt;
&lt;p&gt;A good model starts with a high response value in the first decile(s) and suddenly drops quickly towards 0 for later deciles. This indicates good differentiation between target class members - getting high model scores - and all other cases. An interesting point in the plot is the location where your model’s line intersects the random model line. From that decile onwards, the % of target class cases is lower than a random selection of cases would hold.&lt;/p&gt;
&lt;h3&gt;Cumulative response plot&lt;/h3&gt;
&lt;p&gt;Finally, one of the most used plots: The cumulative response plot. It answers the question burning on each business rep's lips:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When we apply the model and select up until decile X, what is the expected % of target class observations in the selection?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The reference line in this plot is the same as in the response plot: the % of target class cases in the total set.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://modelplot.github.io/img/cumresponseplot.png" title="plot of chunk cumresponseplot" alt="plot of chunk cumresponseplot" width="100%" /&gt;&lt;/p&gt;
&lt;p&gt;Whereas the response plot crosses the reference line, in the cumulative response plot it never crosses it but ends up at the same point for decile 10: Selecting all cases up until decile 10 is the same as selecting all cases, hence the % of target class cases will be exactly the same. This plot is most often used to decide - together with business colleagues - up until what decile to select for a campaign.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To plot the financial implications of implementing a predictive model, modelplotr provides three additional plots: the Costs &amp;amp; revenues plot, the Profit plot and the ROI plot. &lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;Costs &amp;amp; Revenues plot&lt;/h3&gt;
&lt;p&gt;The costs &amp;amp; revenues plot plots both the cumulative revenues and and the cumulative costs (investments) up until that decile when the model is used for campaign selection. It can be used to answer the following business question:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When we apply the model and select up until decile X, what are the expected revenues and investments of the campaign?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The plot includes both costs and revenues lines. The costs are the cumulative costs of selecting up until a given decile and consist of both fixed costs and variable costs. The fixed costs for campaigns often include costs to create the campaign and other costs that do not vary with the size of the campaign selection. The variable costs do depend on the selection size, resulting in a linear increasing line. The revenues take into account the expected response % - as plotted in the cumulative response plot - as well as the expected revenue per response.   &lt;/p&gt;
&lt;p&gt;&lt;img src="https://modelplot.github.io/img/costsrevsplot.png" title="plot of chunk costsrevsplot" alt="plot of chunk costsrevsplot" width="100%" /&gt;&lt;/p&gt;
&lt;p&gt;The campaign is profitable in the plot area where revenues exceed costs. The optimal profit might be difficult to see quickly, since the reference line is a diagonal. Therefore, to evaluate profitability, the next plot - the profit plot - is more suitable.  &lt;/p&gt;
&lt;h3&gt;Profit plot&lt;/h3&gt;
&lt;p&gt;The profit plot visualized the cumulative profit up until that decile when the model is used for campaign selection. It can be used to answer the following business question:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When we apply the model and select up until decile X, what is the expected profit of the campaign?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src="https://modelplot.github.io/img/profitplot.png" title="plot of chunk profitplot" alt="plot of chunk profitplot" width="100%" /&gt;&lt;/p&gt;
&lt;p&gt;From this plot, it can be quickly spotted with what selection size the campaign profit is maximized. However, this does not mean that this is the best option from an investment point of view. It might be that, taking into consideration the investments that is needed for the profit, another decile is preferred. Therefore, the roi plot is needed as well.&lt;/p&gt;
&lt;h3&gt;Return on investment plot&lt;/h3&gt;
&lt;p&gt;The Return on Investment plot plots the cumulative revenues as a percentage of investments up until that decile when the model is used for campaign selection. It can be used to answer the following business question:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When we apply the model and select up until decile X, what is the expected % return on investment of the campaign?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src="https://modelplot.github.io/img/roiplot.png" title="plot of chunk roiplot" alt="plot of chunk roiplot" width="100%" /&gt;&lt;/p&gt;
&lt;p&gt;From this plot, the selection size with the optimal return on investment for the campaign is easily identified. Do note that the decile at which the campaign profit is maximized, is not necessarily the same as the decile where the campaign ROI is maximized. It can be the case that a bigger selection (higher decile) results in a higher profit, however this selection needs a larger investment, impacting the ROI negatively.   &lt;/p&gt;
&lt;h2&gt;Data preparation steps&lt;/h2&gt;
&lt;p&gt;To be able to use the plots presented above, you need to create a dataframe that serves as an input for all these plots. We've included three functions in modelplotr to create this input dataframe really easy and fast. Especially when you've trained your models using &lt;strong&gt;caret&lt;/strong&gt;, &lt;strong&gt;mlr&lt;/strong&gt;, &lt;strong&gt;h2o&lt;/strong&gt; or &lt;strong&gt;keras&lt;/strong&gt; the process is super simple. In this case, you ony need two function calls to prepare your data for plotting. In case you use another package to train your models or when you've trained your models outside of R, you can still use modelplotr, you just need one extra step. Further on we'll guide you how to prepare the input in that case.&lt;/p&gt;
&lt;h3&gt;Some example data&lt;/h3&gt;
&lt;p&gt;To show how modelplotr works, we've included some test data in the package. This dataset is a subset of the dataset made available by the University of California, Irvine. The complete dataset is available here: https://archive.ics.uci.edu/ml/machine-learning-databases/00222/bank-additional.zip. Let's load the data:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# load example data (Bank clients that have/have not subscribed a term deposit - see ?bank_td for details)&lt;/span&gt;
&lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;bank_td&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bank_td&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;## &amp;#39;data.frame&amp;#39;:    2000 obs. of  7 variables:&lt;/span&gt;
&lt;span class="c1"&gt;##  $ has_td   : Factor w/ 2 levels &amp;quot;term.deposit&amp;quot;,..: 2 2 2 2 2 2 2 2 2 2 ...&lt;/span&gt;
&lt;span class="c1"&gt;##  $ td_type  : Factor w/ 4 levels &amp;quot;no.td&amp;quot;,&amp;quot;td.type.A&amp;quot;,..: 1 1 1 1 1 1 1 1 1 1 ...&lt;/span&gt;
&lt;span class="c1"&gt;##  $ duration : int  312 82 133 150 393 174 197 104 420 364 ...&lt;/span&gt;
&lt;span class="c1"&gt;##  $ campaign : int  1 4 1 4 2 1 1 1 1 2 ...&lt;/span&gt;
&lt;span class="c1"&gt;##  $ pdays    : int  999 999 999 999 999 999 999 6 1 999 ...&lt;/span&gt;
&lt;span class="c1"&gt;##  $ previous : int  0 0 0 0 0 1 0 1 1 0 ...&lt;/span&gt;
&lt;span class="c1"&gt;##  $ euribor3m: num  4.86 4.96 4.96 4.96 4.96 ...&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;A brief introduction to the data: This dataset contains 7 variables, including 2 potential target variables and 5 features to predict these targets.  The binary target is &lt;strong&gt;has_td&lt;/strong&gt;; it indicates whether the client has subscribed for a term deposit ('term.deposit') or not ('no.term.deposit'). The multinomial target is &lt;strong&gt;td_type&lt;/strong&gt; which has four possible values: 'no.td', 'td.type.A', 'td.type.B' and 'td.type.C'. This target is included to show that modelplotr also works to plot predictive models with multiclass targets. The five features are a subset of all features available in the actual source, just to have some predictors available to build some example models evaluate with modelplotr. For details on the data, see ?bank_td.&lt;/p&gt;
&lt;p&gt;Now, let's train some models. To illustrate that you can use models trained using caret, mlr, h2o and keras, we'll train some models first, one for each package, and include these models in our input for the plots. This way, we can easily compare the models in the plots. Also, we use a train set and a test set for each model, enabling us to also compare between datasets. More on modelplotr's options to compare stuff (models, datasets, target classes) in the next section on &lt;strong&gt;Plotting scopes&lt;/strong&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# prepare data for training model for binomial target has_td and train models&lt;/span&gt;
&lt;span class="n"&gt;train_index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;sample&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;seq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;nrow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bank_td&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0.5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nf"&gt;nrow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bank_td&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;replace&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;FALSE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;train&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bank_td[train_index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nf"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;has_td&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;duration&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;campaign&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;pdays&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;previous&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;euribor3m&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bank_td[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;train_index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nf"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;has_td&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;duration&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;campaign&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;pdays&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;previous&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;euribor3m&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;#train models using mlr...&lt;/span&gt;
&lt;span class="n"&gt;trainTask&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;mlr&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;makeClassifTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;has_td&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;testTask&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;mlr&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;makeClassifTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;has_td&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;mlr&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;configureMlr&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;# this line is needed when using mlr without loading it (mlr::)&lt;/span&gt;
&lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mlr&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;makeClassifTask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;has_td&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;lrn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mlr&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;makeLearner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;classif.randomForest&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;predict.type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;prob&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;rf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mlr&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;train&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lrn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#... or train models using caret...&lt;/span&gt;
&lt;span class="c1"&gt;# setting caret cross validation, here tuned for speed (not accuracy!)&lt;/span&gt;
&lt;span class="n"&gt;fitControl&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;caret&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;trainControl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;cv&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;classProbs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;TRUE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# mnl model using glmnet package&lt;/span&gt;
&lt;span class="n"&gt;mnl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;caret&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;train&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;has_td&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="n"&gt;.,data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;glmnet&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;trControl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fitControl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;## Warning in load(system.file(&amp;quot;models&amp;quot;, &amp;quot;models.RData&amp;quot;, package = &amp;quot;caret&amp;quot;)):&lt;/span&gt;
&lt;span class="c1"&gt;## strings not representable in native encoding will be translated to UTF-8&lt;/span&gt;
&lt;span class="c1"&gt;## Loading required package: lattice&lt;/span&gt;
&lt;span class="c1"&gt;## Loading required package: ggplot2&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Modelplotr can be used with models built with h2o and keras just as easily. Want to see this in action? Run the code below and add these models to the function &lt;strong&gt;prepare_scores_and_ntiles()&lt;/strong&gt; in the next step.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;#.. or train models using h2o... [NOT RUN]&lt;/span&gt;
&lt;span class="n"&gt;h2o&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;h2o.init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;h2o&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;h2o.no_progress&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;h2o_train&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;h2o&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;as.h2o&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;h2o_test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;h2o&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;as.h2o&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;gbm&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;h2o&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;h2o.gbm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;has_td&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                          &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setdiff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;colnames&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;has_td&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                          &lt;span class="n"&gt;training_frame&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;h2o_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                          &lt;span class="n"&gt;nfolds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#.. or train models using keras...  [NOT RUN]&lt;/span&gt;
&lt;span class="n"&gt;x_train&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="nf"&gt;as.matrix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;train[&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;-1&lt;/span&gt;&lt;span class="n"&gt;]&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;train[&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;to_categorical&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;as.numeric&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="m"&gt;-1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;`%&amp;gt;%`&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;magrittr&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;`%&amp;gt;%`&lt;/span&gt;
&lt;span class="n"&gt;nn&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;keras_model_sequential&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;%&lt;/span&gt;
&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;layer_dense&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;units&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;kernel_initializer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;uniform&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;activation&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;relu&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;input_shape&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;NCOL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x_train&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;layer_dense&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;units&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;kernel_initializer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;uniform&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;activation&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;relu&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;layer_dense&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;units&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;levels&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;train[&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;&lt;span class="n"&gt;activation&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;softmax&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;nn&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;%&lt;/span&gt; &lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;optimizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;rmsprop&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;loss&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;categorical_crossentropy&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;metrics&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;accuracy&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;nn&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;%&lt;/span&gt; &lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;epochs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;batch_size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1028&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;verbose&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now that we have some datasets and some trained models, we can start using modelplotr to prepare the data for plotting:&lt;/p&gt;
&lt;h3&gt;prepare_scores_and_ntiles()&lt;/h3&gt;
&lt;p&gt;This function builds a dataframe object that contains actuals and predictions on the target variable for each dataset in datasets and each model in models. It contains the dataset name, actuals on the target, the predicted probabilities for each class of the target and attribution to ntiles in the dataset for each class of the target.&lt;/p&gt;
&lt;p&gt;The function prepare_scores_and_ntiles() has 6 parameters, of which 3 are required:&lt;/p&gt;
&lt;table class="table" style="font-size: 10px; margin-left: auto; margin-right: auto;"&gt;
 &lt;thead&gt;
  &lt;tr&gt;
   &lt;th style="text-align:left;"&gt; Parameter &lt;/th&gt;
   &lt;th style="text-align:left;"&gt; Type.and.Description &lt;/th&gt;
  &lt;/tr&gt;
 &lt;/thead&gt;
&lt;tbody&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; datasets * &lt;/td&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; List of Strings. A list of the names of the dataframe objects to include in model evaluation. All dataframes need to contain target variable and feature variables. &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; dataset_labels &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; List of Strings. A list of labels for the datasets, user. When dataset_labels is not specified, the names from datasets are used. &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; models * &lt;/td&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; List of Strings. Names of the model objects containing parameters to apply models to data. To use this function, model objects need to be generated by the mlr package or by the caret package or by the h20 package. Modelplotr automatically detects whether the model is built using mlr or caret or h2o. &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; model_labels &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; List of Strings. Labels for the models to use in plots. When model_labels is not specified, the names from moddels are used. &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; target_column * &lt;/td&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; String. Name of the target variable in datasets. Target can be either binary or multinomial. Continuous targets are not supported. &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; ntiles &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Integer. Number of ntiles. The ntile parameter represents the specified number of equally sized buckets the observations in each dataset are grouped into. By default, observations are grouped in 10 equally sized buckets, often referred to as deciles. &lt;/td&gt;
  &lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Now, let's use the &lt;em&gt;scores_and_ntiles()&lt;/em&gt; function on our models to evaluate the business performance on both the train and the test data:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# prepare data (for h2o/keras: add &amp;quot;gbm&amp;quot; and &amp;quot;nn&amp;quot; to models and nice labels to model_labels params)&lt;/span&gt;

&lt;span class="n"&gt;scores_and_ntiles&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="nf"&gt;prepare_scores_and_ntiles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;datasets&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;train&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;test&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                      &lt;span class="n"&gt;dataset_labels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;train data&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;test data&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                      &lt;span class="n"&gt;models&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;rf&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;mnl&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;  
                      &lt;span class="n"&gt;model_labels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;random forest&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;multinomial logit&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; 
                      &lt;span class="n"&gt;target_column&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;has_td&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                      &lt;span class="n"&gt;ntiles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;## ... scoring mlr model &amp;quot;rf&amp;quot; on dataset &amp;quot;train&amp;quot;.&lt;/span&gt;
&lt;span class="c1"&gt;## ... scoring caret model &amp;quot;mnl&amp;quot; on dataset &amp;quot;train&amp;quot;.&lt;/span&gt;
&lt;span class="c1"&gt;## ... scoring mlr model &amp;quot;rf&amp;quot; on dataset &amp;quot;test&amp;quot;.&lt;/span&gt;
&lt;span class="c1"&gt;## ... scoring caret model &amp;quot;mnl&amp;quot; on dataset &amp;quot;test&amp;quot;.&lt;/span&gt;
&lt;span class="c1"&gt;## Data preparation step 1 succeeded! Dataframe created.&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This is what the resulting dataframe looks like (first 5 rows):&lt;/p&gt;
&lt;table class="table" style="font-size: 10px; width: auto !important; "&gt;
 &lt;thead&gt;
  &lt;tr&gt;
   &lt;th style="text-align:left;"&gt; model_label &lt;/th&gt;
   &lt;th style="text-align:left;"&gt; dataset_label &lt;/th&gt;
   &lt;th style="text-align:left;"&gt; y_true &lt;/th&gt;
   &lt;th style="text-align:right;"&gt; prob_term.deposit &lt;/th&gt;
   &lt;th style="text-align:right;"&gt; prob_no.term.deposit &lt;/th&gt;
   &lt;th style="text-align:right;"&gt; ntl_term.deposit &lt;/th&gt;
   &lt;th style="text-align:right;"&gt; ntl_no.term.deposit &lt;/th&gt;
  &lt;/tr&gt;
 &lt;/thead&gt;
&lt;tbody&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; random forest &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; train data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; no.term.deposit &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1.000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 59 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 7 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; random forest &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; train data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; no.term.deposit &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1.000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 79 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 6 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; random forest &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; train data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; no.term.deposit &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.062 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.938 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 23 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 78 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; random forest &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; train data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; no.term.deposit &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1.000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 97 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 25 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; random forest &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; train data &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; no.term.deposit &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 0.000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 1.000 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 84 &lt;/td&gt;
   &lt;td style="text-align:right;"&gt; 38 &lt;/td&gt;
  &lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;h3&gt;plotting_scope()&lt;/h3&gt;
&lt;p&gt;This function builds a dataframe in the required format for all modelplotr plots, relevant to the selected scope of evaluation. Each record in this dataframe represents a unique combination of datasets, models, target classes and ntiles. &lt;/p&gt;
&lt;p&gt;As an input, plotting_scope can handle a dataframe created with prepare_scores_and_ntiles (see above) or created otherwise with similar layout. Also, you can provide a dataframe created with aggregate_over_ntiles(). See the section below for more info on the function aggregate_over_ntiles.  &lt;/p&gt;
&lt;p&gt;Aside from the input, the most important parameter is &lt;strong&gt;scope=&lt;/strong&gt;. There are four perspectives you can take to plot with modelplotr:&lt;/p&gt;
&lt;table class="table" style="font-size: 10px; margin-left: auto; margin-right: auto;"&gt;
 &lt;thead&gt;
  &lt;tr&gt;
   &lt;th style="text-align:left;"&gt; Scope &lt;/th&gt;
   &lt;th style="text-align:left;"&gt; Description &lt;/th&gt;
  &lt;/tr&gt;
 &lt;/thead&gt;
&lt;tbody&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; "no_comparison" (default) &lt;/td&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; In this perspective, you're interested in the performance of one model on one dataset for one target class. Therefore, only one line is plotted in the plots. The parameters select_model_label, select_dataset_label and select_targetclass determine which group is plotted. When not specified, the first alphabetic model, the first alphabetic dataset and the smallest (when select_smallest_targetclass=TRUE) or first alphabetic target value are selected &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; "compare_models" &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; In this perspective, you're interested in how well different models perform in comparison to each other on the same dataset and for the same target value. This results in a comparison between models available in ntiles_aggregate\$model_label for a selected dataset (default: first alphabetic dataset) and for a selected target value (default: smallest (when select_smallest_targetclass=TRUE) or first alphabetic target value). &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; "compare_datasets" &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; In this perspective, you're interested in how well a model performs in different datasets for a specific model on the same target value. This results in a comparison between datasets available in ntiles_aggregate\$dataset_label for a selected model (default: first alphabetic model) and for a selected target value (default: smallest (when select_smallest_targetclass=TRUE) or first alphabetic target value). &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; "compare_targetclasses" &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; In this perspective, you're interested in how well a model performs for different target values on a specific dataset.This resuls in a comparison between target classes available in ntiles_aggregate\$target_class for a selected model (default: first alphabetic model) and for a selected dataset (default: first alphabetic dataset). &lt;/td&gt;
  &lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Other parameters let you select a subset of models/datasets/target classes you want to include in your plot, see ?plotting_scope for details.&lt;/p&gt;
&lt;table class="table" style="font-size: 10px; margin-left: auto; margin-right: auto;"&gt;
 &lt;thead&gt;
  &lt;tr&gt;
   &lt;th style="text-align:left;"&gt; Parameter &lt;/th&gt;
   &lt;th style="text-align:left;"&gt; Type.and.Description &lt;/th&gt;
  &lt;/tr&gt;
 &lt;/thead&gt;
&lt;tbody&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; prepared_input * &lt;/td&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; Dataframe. Dataframe created with prepare_scores_and_ntiles or dataframe created with aggregate_over_ntiles or a dataframe that is created otherwise with similar layout as the output of these functions (see ?prepare_scores_and_ntiles and ?aggregate_over_ntiles for layout details) &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; scope &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; String. Evaluation type of interest. Possible values: "compare_models","compare_datasets", "compare_targetclasses","no_comparison". Default is NA, equivalent to "no_comparison". &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; select_model_label &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; String. Selected model when scope is "compare_datasets" or "compare_targetclasses" or "no_comparison". Needs to be identical to model descriptions as specified in model_labels (or models when model_labels is not specified). When scope is "compare_models", select_model_label can be used to take a subset of available models. &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; select_dataset_label &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; String. Selected dataset when scope is compare_models or compare_targetclasses or no_comparison. Needs to be identical to dataset descriptions as specified in dataset_labels (or datasets when dataset_labels is not specified). When scope is "compare_datasets", select_dataset_label can be used to take a subset of available datasets. &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; select_targetclass &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; String. Selected target value when scope is compare_models or compare_datasets or no_comparison. Default is smallest value when select_smallest_targetclass=TRUE, otherwise first alphabetical value. When scope is "compare_targetclasses", select_targetclass can be used to take a subset of available target classes. &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; select_smallest_targetclass &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Boolean. Select the target value with the smallest number of cases in dataset as group of interest. Default is True, hence the target value with the least observations is selected &lt;/td&gt;
  &lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Now, let's use plotting_scope to generate the input for all plots:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;#generate input data frame for all plots in modelplotr&lt;/span&gt;
&lt;span class="n"&gt;plot_input&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="nf"&gt;plotting_scope&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prepared_input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scores_and_ntiles&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;## Data preparation step 2 succeeded! Dataframe created.&lt;/span&gt;
&lt;span class="c1"&gt;## &amp;quot;prepared_input&amp;quot; aggregated...&lt;/span&gt;
&lt;span class="c1"&gt;## Data preparation step 3 succeeded! Dataframe created.&lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;span class="c1"&gt;## No comparison specified, default values are used. &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;span class="c1"&gt;## Single evaluation line will be plotted: Target value &amp;quot;term.deposit&amp;quot; plotted for dataset &amp;quot;test data&amp;quot; and model &amp;quot;multinomial logit.&lt;/span&gt;
&lt;span class="c1"&gt;## &amp;quot;&lt;/span&gt;
&lt;span class="c1"&gt;## -&amp;gt; To compare models, specify: scope = &amp;quot;compare_models&amp;quot;&lt;/span&gt;
&lt;span class="c1"&gt;## -&amp;gt; To compare datasets, specify: scope = &amp;quot;compare_datasets&amp;quot;&lt;/span&gt;
&lt;span class="c1"&gt;## -&amp;gt; To compare target classes, specify: scope = &amp;quot;compare_targetclasses&amp;quot;&lt;/span&gt;
&lt;span class="c1"&gt;## -&amp;gt; To plot one line, do not specify scope or specify scope = &amp;quot;no_comparison&amp;quot;.&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Since we only provided the input data and not the scope, the default scope (no comparison) is used. To adjust, specify &lt;strong&gt;scope=&lt;/strong&gt; and/or set the other parameters to customize the models/datasets/target classes you want to include in your plots. &lt;/p&gt;
&lt;h3&gt;Custom prepration of modelplotr input&lt;/h3&gt;
&lt;p&gt;Maybe you prefer to prepare the input for modelplotr differently. For instance when your models are not created with mlr, catet, h2o or keras. Or when your models are created outside of R or your already have the scored data available. In these cases, you have two extra options to prepare the input for &lt;strong&gt;plotting_scope&lt;/strong&gt;, as visualised below:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://modelplot.github.io/img/modelplotr_process.png" title="plot of chunk modelplotr_process" alt="plot of chunk modelplotr_process" width="100%" /&gt;&lt;/p&gt;
&lt;h4&gt;Option 2: Prepare input for aggregate_over_ntiles()&lt;/h4&gt;
&lt;p&gt;With option 2, you prepare  your own dataframe containing actuals and probabilities and ntiles (1st ntile = (1/#ntiles) percent with highest model probability, last ntile = (1/#ntiles) percent with lowest probability according to model) , In that case, make sure the input dataframe contains the folowing columns &amp;amp; formats:&lt;/p&gt;
&lt;table class="table" style="font-size: 10px; margin-left: auto; margin-right: auto;"&gt;
 &lt;thead&gt;
  &lt;tr&gt;
   &lt;th style="text-align:left;"&gt; column &lt;/th&gt;
   &lt;th style="text-align:left;"&gt; type &lt;/th&gt;
   &lt;th style="text-align:left;"&gt; definition &lt;/th&gt;
  &lt;/tr&gt;
 &lt;/thead&gt;
&lt;tbody&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; model_label &lt;/td&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; Factor &lt;/td&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; Name of the model object &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; dataset_label &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Factor &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Datasets to include in the plot as factor levels &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; y_true &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Factor &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Target with actual values &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; prob_[tv1] &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Decimal &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Probability according to model for target value 1 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; prob_[tv2] &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Decimal &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Probability according to model for target value 2 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; ... &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; ... &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; ... &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; prob_[tvn] &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Decimal &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Probability according to model for target value n &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; ntl_[tv1] &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Integer &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Ntile based on probability according to model for target value 1 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; ntl_[tv2] &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Integerl &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Ntile based on probability according to model for target value 2 &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; ... &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; ... &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; ... &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; ntl_[tvn] &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Integer &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Ntile based on probability according to model for target value n &lt;/td&gt;
  &lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Once you have this data frame prepared, you can use it as an input for &lt;strong&gt;plotting_scope()&lt;/strong&gt;, as it aggregates the input automatically.  If you prefer, you can aggregate it first yourself using &lt;strong&gt;aggregate_over_ntiles()&lt;/strong&gt;.  &lt;/p&gt;
&lt;h4&gt;Option 3: Prepare input for plotting_scope()&lt;/h4&gt;
&lt;p&gt;A third option is to build an aggregated data frame yourself as an input for &lt;strong&gt;plotting_scope()&lt;/strong&gt;. This does require some extra preparation that is not needed when using option 2, but this can be the better option when you don't want to move around actual and predicted scores on individual cases, due to size or maybe privacy/confidentiality. In this case, make sure the data frame you create, exactly matches the definitions below:&lt;/p&gt;
&lt;table class="table" style="font-size: 10px; width: auto !important; "&gt;
 &lt;thead&gt;
  &lt;tr&gt;
   &lt;th style="text-align:left;"&gt; column &lt;/th&gt;
   &lt;th style="text-align:left;"&gt; type &lt;/th&gt;
   &lt;th style="text-align:left;"&gt; definition &lt;/th&gt;
  &lt;/tr&gt;
 &lt;/thead&gt;
&lt;tbody&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; model_label &lt;/td&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; String &lt;/td&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; Name of the model object &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; dataset_label &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Factor &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Datasets to include in the plot as factor levels &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; target_class &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; String or Integer &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Target classes to include in the plot &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; ntile &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Integer &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Ntile groups based on model probability for target class &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; neg &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Integer &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Number of cases not belonging to target class in dataset in ntile &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; pos &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Integer &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Number of cases belonging to target class in dataset in ntile &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; tot &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Integer &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Total number of cases in dataset in ntile &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; pct &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Decimal &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Percentage of cases in dataset in ntile that belongs to target class (pos/tot) &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; negtot &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Integer &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Total number of cases not belonging to target class in dataset &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; postot &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Integer &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Total number of cases belonging to target class in dataset &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; tottot &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Integer &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Total number of cases in dataset &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; pcttot &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Decimal &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Percentage of cases in dataset that belongs to target class (postot / tottot) &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; cumneg &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Integer &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Cumulative number of cases not belonging to target class in dataset from ntile 1 up until ntile &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; cumpos &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Integer &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Cumulative number of cases belonging to target class in dataset from ntile 1 up until ntile &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; cumtot &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Integer &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Cumulative number of cases in dataset from ntile 1 up until ntile &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; cumpct &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Integer &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Cumulative percentage of cases belonging to target class in dataset from ntile 1 up until ntile (cumpos/cumtot) &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; gain &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Decimal &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Gains value for dataset for ntile (pos/postot) &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; cumgain &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Decimal &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Cumulative gains value for dataset for ntile (cumpos/postot) &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; gain_ref &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Decimal &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Lower reference for gains value for dataset for ntile (ntile/#ntiles) &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; gain_opt &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Decimal &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Upper reference for gains value for dataset for ntile &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; lift &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Decimal &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Lift value for dataset for ntile (pct/pcttot) &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; cumlift &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Decimal &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Cumulative lift value for dataset for ntile ((cumpos/cumtot)/pcttot) &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; cumlift_ref &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Decimal &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Reference value for Cumulative lift value (constant: 1) &lt;/td&gt;
  &lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Once you have this data frame prepared, you can use it as an input for &lt;strong&gt;plotting_scope()&lt;/strong&gt;.  &lt;/p&gt;
&lt;h2&gt;Plotting&lt;/h2&gt;
&lt;p&gt;Now that we have data that are well prepared for all plots, plotting is quite easy. For instance, the cumulative gains plot:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nf"&gt;plot_cumgains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk plot_cg" src="https://modelplot.github.io/img/modelplotr-plot_cg-1.png" /&gt;&lt;/p&gt;
&lt;p&gt;Creating the other non-financial plots is just as easy:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;#Cumulative lift&lt;/span&gt;
&lt;span class="nf"&gt;plot_cumlift&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#Response plot&lt;/span&gt;
&lt;span class="nf"&gt;plot_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#Cumulative response plot&lt;/span&gt;
&lt;span class="nf"&gt;plot_cumresponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The cumulative lift plot, cumulative gains plot, response plot and cumulative response plot can be combined on one canvas:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;## ... scoring mlr model &amp;quot;rf&amp;quot; on dataset &amp;quot;train&amp;quot;.
## ... scoring caret model &amp;quot;mnl&amp;quot; on dataset &amp;quot;train&amp;quot;.
## ... scoring mlr model &amp;quot;rf&amp;quot; on dataset &amp;quot;test&amp;quot;.
## ... scoring caret model &amp;quot;mnl&amp;quot; on dataset &amp;quot;test&amp;quot;.
## Data preparation step 1 succeeded! Dataframe created.
## Data preparation step 2 succeeded! Dataframe created.
## &amp;quot;prepared_input&amp;quot; aggregated...
## Data preparation step 3 succeeded! Dataframe created.
## 
## No comparison specified, default values are used. 
## 
## Single evaluation line will be plotted: Target value &amp;quot;term.deposit&amp;quot; plotted for dataset &amp;quot;test data&amp;quot; and model &amp;quot;multinomial logit.
## &amp;quot;
## -&amp;gt; To compare models, specify: scope = &amp;quot;compare_models&amp;quot;
## -&amp;gt; To compare datasets, specify: scope = &amp;quot;compare_datasets&amp;quot;
## -&amp;gt; To compare target classes, specify: scope = &amp;quot;compare_targetclasses&amp;quot;
## -&amp;gt; To plot one line, do not specify scope or specify scope = &amp;quot;no_comparison&amp;quot;.
&lt;/pre&gt;&lt;/div&gt;


&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nf"&gt;plot_multiplot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk plot_multi" src="https://modelplot.github.io/img/modelplotr-plot_multi-1.png" /&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;## Data preparation step 2 succeeded! Dataframe created.
## &amp;quot;prepared_input&amp;quot; aggregated...
## Data preparation step 3 succeeded! Dataframe created.
## 
## No comparison specified, default values are used. 
## 
## Single evaluation line will be plotted: Target value &amp;quot;term.deposit&amp;quot; plotted for dataset &amp;quot;test data&amp;quot; and model &amp;quot;multinomial logit.
## &amp;quot;
## -&amp;gt; To compare models, specify: scope = &amp;quot;compare_models&amp;quot;
## -&amp;gt; To compare datasets, specify: scope = &amp;quot;compare_datasets&amp;quot;
## -&amp;gt; To compare target classes, specify: scope = &amp;quot;compare_targetclasses&amp;quot;
## -&amp;gt; To plot one line, do not specify scope or specify scope = &amp;quot;no_comparison&amp;quot;.
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;There is a lot you can customize for the plots in modelplotr: all textual elements, line colors, highlighting and annotating the plots at a specific ntile. All these options are discussed further on. &lt;/p&gt;
&lt;h2&gt;For financial plots, three extra parameters need to be provided:&lt;/h2&gt;
&lt;p&gt;&lt;table class="table" style="font-size: 10px; margin-left: auto; margin-right: auto;"&gt;
 &lt;thead&gt;
  &lt;tr&gt;
   &lt;th style="text-align:left;"&gt; Parameter &lt;/th&gt;
   &lt;th style="text-align:left;"&gt; Type.and.Description &lt;/th&gt;
  &lt;/tr&gt;
 &lt;/thead&gt;
&lt;tbody&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; fixed_costs &lt;/td&gt;
   &lt;td style="text-align:left;font-style: italic;"&gt; Numeric. Specifying the fixed costs related to a selection based on the model. These costs are constant and do not vary with selection size (ntiles). &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; variable_costs_per_unit &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Numeric. Specifying the variable costs per selected unit for a selection based on the model. These costs vary with selection size (ntiles). &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td style="text-align:left;"&gt; profit_per_unit &lt;/td&gt;
   &lt;td style="text-align:left;"&gt; Numeric. Specifying the profit per unit in case the selected unit converts / responds positively. &lt;/td&gt;
  &lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/p&gt;
&lt;p&gt;With these extra parameters, all three financial plots can be plotted, for instance the ROI plot:  &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nf"&gt;plot_roi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;fixed_costs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;variable_costs_per_unit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;profit_per_unit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## Plot annotation for plot: Return on Investment (ROI)&lt;/span&gt;
&lt;span class="c1"&gt;## - When we select ntiles 1 until 14 in dataset test data using model multinomial logit to target term.deposit cases the expected return on investment is 60%. &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk plot_roi" src="https://modelplot.github.io/img/modelplotr-plot_roi-1.png" /&gt;&lt;/p&gt;
&lt;p&gt;By default, in the ROI plot the ntile is highlighted where return on investment is highest. In the profit plot and costs &amp;amp; revenues plot, the ntile where the profit is highest is highlighted by default. This can be changed, see the section on highlighting or ?plot_roi / ?plot_profit / ?plot_costsrevs for details. As an example:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;#Costs &amp;amp; Revenues plot, highlighted at max roi instead of max profit&lt;/span&gt;
&lt;span class="nf"&gt;plot_costsrevs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;fixed_costs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;variable_costs_per_unit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;profit_per_unit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;highlight_ntile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;max_roi&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## Plot annotation for plot: Costs and Revenues&lt;/span&gt;
&lt;span class="c1"&gt;## - When we select ntiles 1 until 14 in dataset test data using model  to target term.deposit cases the revenues are &amp;lt;U+20AC&amp;gt;3,850 &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk plot_costrev_profit" src="https://modelplot.github.io/img/modelplotr-plot_costrev_profit-1.png" /&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;#Profit plot , highlighted at custom ntile instead of at max profit&lt;/span&gt;
&lt;span class="nf"&gt;plot_profit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;fixed_costs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;variable_costs_per_unit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;profit_per_unit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;highlight_ntile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## Plot annotation for plot: Profit&lt;/span&gt;
&lt;span class="c1"&gt;## - When we select ntiles 1 until 5 in dataset test data using model multinomial logit to target term.deposit cases the expected profit is &amp;lt;U+20AC&amp;gt;350 &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk plot_costrev_profit" src="https://modelplot.github.io/img/modelplotr-plot_costrev_profit-2.png" /&gt;&lt;/p&gt;
&lt;h2&gt;Highlighting and customizing plots&lt;/h2&gt;
&lt;p&gt;The look and feel of plots can be customized in a number of ways. In the next sections all customizations are presented. &lt;/p&gt;
&lt;h3&gt;highlighting&lt;/h3&gt;
&lt;p&gt;To highlight a specific decile (or ntile), this can be done with the parameter &lt;strong&gt;highlight_ntile=&lt;/strong&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nf"&gt;plot_cumgains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;highlight_ntile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## Plot annotation for plot: Cumulative gains&lt;/span&gt;
&lt;span class="c1"&gt;## - When we select 20% with the highest probability according to model multinomial logit, this selection holds 74% of all term.deposit cases in test data. &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk plot_cgh" src="https://modelplot.github.io/img/modelplotr-plot_cgh-1.png" /&gt;&lt;/p&gt;
&lt;p&gt;For financial plots (plot_costsrevs, plot_profit and plot_roi), the highlighing is added automatically, highlighting the optimum. If you want to highlight at another decile value, this can easily be done by setting the parameter (eg. highlight_ntile = 20).&lt;/p&gt;
&lt;p&gt;With parameter &lt;strong&gt;highlight_how&lt;/strong&gt; you can specify How to annotate the plot. Possible values: "plot_text","plot", "text". Default is "plot_text", both highlighting the ntile and value on the plot as well as in text below the plot. "plot" only highligths the plot, but does not add text below the plot explaining the plot at chosen ntile. "text" adds text below the plot explaining the plot at chosen ntile but does not highlight the plot.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nf"&gt;plot_cumresponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;highlight_ntile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;highlight_how&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;plot&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## Plot annotation for plot: Cumulative response&lt;/span&gt;
&lt;span class="c1"&gt;## - When we select ntiles 1 until 20 according to model multinomial logit in dataset test data the % of term.deposit cases in the selection is 45.0%. &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk plot_crhh" src="https://modelplot.github.io/img/modelplotr-plot_crhh-1.png" /&gt;&lt;/p&gt;
&lt;h3&gt;Customizing textual elements&lt;/h3&gt;
&lt;p&gt;All textual elements in the plots can be customized. To achieve this, first you have to create a list object with all default values for all textual elements. Modelplotr has a special function to build this list. Once the list is created, you can easily explore the defaults for all plots and change them to your will. &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;my_text&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="nf"&gt;customize_plot_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;## List with default values for all textual plot elements is created.&lt;/span&gt;
&lt;span class="c1"&gt;##       To customize titles, axis labels and annotation text, modify specific list elements.&lt;/span&gt;
&lt;span class="c1"&gt;##       E.g, when List is named &amp;#39;mylist&amp;#39;, to change the lift plot title to &amp;#39;Cumulatieve Lift grafiek&amp;#39;, use:&lt;/span&gt;
&lt;span class="c1"&gt;##       mylist$cumlift$title &amp;lt;- &amp;#39;Cumulatieve Lift grafiek&amp;#39;&lt;/span&gt;
&lt;span class="c1"&gt;##       plot_cumlift(custom_plot_text = mylist)&lt;/span&gt;

&lt;span class="c1"&gt;#explore default values for the cumulative response plot:&lt;/span&gt;
&lt;span class="n"&gt;my_text&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="n"&gt;cumresponse&lt;/span&gt;
&lt;span class="c1"&gt;## $plottitle&lt;/span&gt;
&lt;span class="c1"&gt;## [1] &amp;quot;Cumulative response&amp;quot;&lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;span class="c1"&gt;## $plotsubtitle&lt;/span&gt;
&lt;span class="c1"&gt;## [1] &amp;quot;model: multinomial logit  &amp;amp;  dataset: test data  &amp;amp;  target class: term.deposit&amp;quot;&lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;span class="c1"&gt;## $x_axis_label&lt;/span&gt;
&lt;span class="c1"&gt;## [1] &amp;quot;percentile&amp;quot;&lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;span class="c1"&gt;## $y_axis_label&lt;/span&gt;
&lt;span class="c1"&gt;## [1] &amp;quot;cumulative response&amp;quot;&lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;span class="c1"&gt;## $response_refline_label&lt;/span&gt;
&lt;span class="c1"&gt;## [1] &amp;quot;overall response&amp;quot;&lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;span class="c1"&gt;## $annotationtext&lt;/span&gt;
&lt;span class="c1"&gt;## [1] &amp;quot;When we select ntiles 1 until &amp;amp;NTL according to model &amp;amp;MDL in dataset &amp;amp;DS the %% of &amp;amp;YVAL cases in the selection is &amp;amp;VALUE.&amp;quot;&lt;/span&gt;

&lt;span class="c1"&gt;#translate to Dutch&lt;/span&gt;
&lt;span class="n"&gt;my_text&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="n"&gt;cumresponse&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="n"&gt;plottitle&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;Cumulatieve Respons grafiek&amp;#39;&lt;/span&gt;
&lt;span class="n"&gt;my_text&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="n"&gt;cumresponse&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="n"&gt;x_axis_label&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;percentiel&amp;#39;&lt;/span&gt;
&lt;span class="n"&gt;my_text&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="n"&gt;cumresponse&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="n"&gt;y_axis_label&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;% respons (cumulatief)&amp;#39;&lt;/span&gt;
&lt;span class="n"&gt;my_text&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="n"&gt;cumresponse&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="n"&gt;response_refline_label&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;respons in totale dataset&amp;#39;&lt;/span&gt;
&lt;span class="n"&gt;my_text&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="n"&gt;cumresponse&lt;/span&gt;&lt;span class="o"&gt;$&lt;/span&gt;&lt;span class="n"&gt;annotationtext&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;Selecteren we percentiel 1 t/m &amp;amp;NTL volgens model &amp;amp;MDL in dataset &amp;amp;DS dan is het %% &amp;amp;YVAL gevallen in de selectie &amp;amp;VALUE.&amp;quot;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;As you can see, in the annotationtext you can take advantage of some placeholders starting with &lt;strong&gt;&amp;amp;&lt;/strong&gt;. For details on available placeholders, see &lt;strong&gt;?customize_plot_text&lt;/strong&gt;. &lt;/p&gt;
&lt;p&gt;Now, you can include the altered list in your plot function to use the custom plot element texts:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nf"&gt;plot_cumresponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;highlight_ntile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;custom_plot_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;my_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## Plot annotation for plot: Cumulatieve Respons grafiek&lt;/span&gt;
&lt;span class="c1"&gt;## - Selecteren we percentiel 1 t/m 20 volgens model multinomial logit in dataset test data dan is het % term.deposit gevallen in de selectie 45.0%. &lt;/span&gt;
&lt;span class="c1"&gt;##  &lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk plotcustomtext" src="https://modelplot.github.io/img/modelplotr-plotcustomtext-1.png" /&gt;&lt;/p&gt;
&lt;h3&gt;Customizing colors&lt;/h3&gt;
&lt;p&gt;The colors of the value lines in all plots can be changed setting the parameter &lt;strong&gt;custom_line_colors=&lt;/strong&gt; to a vector of strings, specifying colors for the lines in the plot. Both color names and color codes and RColorbrewer palet can be used. The vector is automatically cropped / expanded to match the required length. When not specified, colors from the RColorBrewer palet "Set1" are used.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# set scope to compare models, to have several lines in the plots&lt;/span&gt;
&lt;span class="n"&gt;plot_input&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="nf"&gt;plotting_scope&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prepared_input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scores_and_ntiles&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;scope&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;compare_models&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;## Data preparation step 2 succeeded! Dataframe created.&lt;/span&gt;
&lt;span class="c1"&gt;## &amp;quot;prepared_input&amp;quot; aggregated...&lt;/span&gt;
&lt;span class="c1"&gt;## Data preparation step 3 succeeded! Dataframe created.&lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;span class="c1"&gt;## Models &amp;quot;random forest&amp;quot;, &amp;quot;multinomial logit&amp;quot; compared for dataset &amp;quot;test data&amp;quot; and target value &amp;quot;term.deposit&amp;quot;.&lt;/span&gt;

&lt;span class="c1"&gt;#customize plot line colors with RColorbrewer &lt;/span&gt;
&lt;span class="nf"&gt;plot_cumgains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;custom_line_colors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;RColorBrewer&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;brewer.pal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;Accent&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="c1"&gt;## Warning in RColorBrewer::brewer.pal(2, &amp;quot;Accent&amp;quot;): minimal value for n is 3, returning requested palette with 3 different levels&lt;/span&gt;
&lt;span class="c1"&gt;## specified custom_line_colors vector greater than required length!&lt;/span&gt;
&lt;span class="c1"&gt;##         It is cropped to match required length&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk plotcustomcolor" src="https://modelplot.github.io/img/modelplotr-plotcustomcolor-1.png" /&gt;&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;#customize plot line colors with color names / hexadecimal codes &lt;/span&gt;
&lt;span class="nf"&gt;plot_cumlift&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;custom_line_colors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;deepskyblue2&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;#FF0000&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk plotcustomcolor" src="https://modelplot.github.io/img/modelplotr-plotcustomcolor-2.png" /&gt;&lt;/p&gt;
&lt;h3&gt;Saving plots&lt;/h3&gt;
&lt;p&gt;Saving plots can be done by setting the parameter &lt;strong&gt;save_fig = TRUE&lt;/strong&gt; and/or by providing a filename for the plot (&lt;strong&gt;save_fig_filename = &lt;/strong&gt;). The plot name can include the path to the location where to save the plot (eg. 'C://TEMP//myplotname.png'). When no (location and) file name is specified, the plot is saved to a temporary directory (&lt;strong&gt;tempdir()&lt;/strong&gt;) with the plot type as its name.  &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# save plot with defaults&lt;/span&gt;
&lt;span class="nf"&gt;plot_cumgains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;save_fig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;TRUE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# save plot with custom filename&lt;/span&gt;
&lt;span class="nf"&gt;plot_cumlift&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;save_fig_filename&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;plot123.png&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# save plot with custom location &lt;/span&gt;
&lt;span class="nf"&gt;plot_cumresponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;save_fig_filename&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;D:\\&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# save plot with custom location and filename&lt;/span&gt;
&lt;span class="nf"&gt;plot_cumresponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;save_fig_filename&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;D:\\plot123.png&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;h3&gt;modelplotr &amp;amp; Multinomial targets&lt;/h3&gt;
&lt;p&gt;Modelplotr can also be used for a multinomial target. To illustrate this, let's build a model on the multinomial target in the data and plot the cumulative response chart. All functionality is the same, see above for details how to customize the plots.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# prepare data for training model for multinomial target td_type and train models&lt;/span&gt;
&lt;span class="n"&gt;train_index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;sample&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;seq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;nrow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bank_td&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0.5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nf"&gt;nrow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bank_td&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;replace&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;FALSE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;train&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bank_td[train_index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nf"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;td_type&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;duration&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;campaign&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;pdays&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;previous&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;euribor3m&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bank_td[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;train_index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nf"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;td_type&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;duration&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;campaign&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;pdays&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;previous&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;euribor3m&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# train a model&lt;/span&gt;
&lt;span class="c1"&gt;# setting caret cross validation, here tuned for speed (not accuracy!)&lt;/span&gt;
&lt;span class="n"&gt;fitControl&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="n"&gt;caret&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;trainControl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;cv&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;classProbs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;TRUE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# mnl model using glmnet package&lt;/span&gt;
&lt;span class="n"&gt;mnl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;caret&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;train&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;td_type&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="n"&gt;.,data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;glmnet&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;trControl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fitControl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;## Warning in load(system.file(&amp;quot;models&amp;quot;, &amp;quot;models.RData&amp;quot;, package = &amp;quot;caret&amp;quot;)):&lt;/span&gt;
&lt;span class="c1"&gt;## strings not representable in native encoding will be translated to UTF-8&lt;/span&gt;

&lt;span class="c1"&gt;# prepare data&lt;/span&gt;
&lt;span class="n"&gt;scores_and_ntiles&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="nf"&gt;prepare_scores_and_ntiles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;datasets&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;train&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;test&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                      &lt;span class="n"&gt;dataset_labels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;train data&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;test data&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                      &lt;span class="n"&gt;models&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;mnl&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                      &lt;span class="n"&gt;model_labels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;multinomial logit&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                      &lt;span class="n"&gt;target_column&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;td_type&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                      &lt;span class="n"&gt;ntiles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;## ... scoring caret model &amp;quot;mnl&amp;quot; on dataset &amp;quot;train&amp;quot;.&lt;/span&gt;
&lt;span class="c1"&gt;## ... scoring caret model &amp;quot;mnl&amp;quot; on dataset &amp;quot;test&amp;quot;.&lt;/span&gt;
&lt;span class="c1"&gt;## Data preparation step 1 succeeded! Dataframe created.&lt;/span&gt;

&lt;span class="c1"&gt;#generate input data frame for all plots, set scope at comparing target classes, leave out the &amp;#39;no.td&amp;#39; class&lt;/span&gt;
&lt;span class="n"&gt;plot_input&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;-&lt;/span&gt; &lt;span class="nf"&gt;plotting_scope&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prepared_input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scores_and_ntiles&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;scope&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;#39;compare_targetclasses&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                             &lt;span class="n"&gt;select_targetclass&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;c&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;td.type.A&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;td.type.B&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;&amp;#39;td.type.C&amp;#39;&lt;/span&gt; &lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="c1"&gt;## Data preparation step 2 succeeded! Dataframe created.&lt;/span&gt;
&lt;span class="c1"&gt;## &amp;quot;prepared_input&amp;quot; aggregated...&lt;/span&gt;
&lt;span class="c1"&gt;## Data preparation step 3 succeeded! Dataframe created.&lt;/span&gt;
&lt;span class="c1"&gt;## &lt;/span&gt;
&lt;span class="c1"&gt;## Target classes &amp;quot;td.type.A&amp;quot;, &amp;quot;td.type.B&amp;quot;, &amp;quot;td.type.C&amp;quot; compared for dataset &amp;quot;test data&amp;quot; and model &amp;quot;multinomial logit&amp;quot;.&lt;/span&gt;

&lt;span class="c1"&gt;#plot &lt;/span&gt;
&lt;span class="nf"&gt;plot_cumresponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot_input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;img alt="plot of chunk multinom" src="https://modelplot.github.io/img/modelplotr-multinom-1.png" /&gt;&lt;/p&gt;</summary><category term="modelplot"></category><category term="R"></category><category term="modelplotr"></category><category term="CRAN"></category><category term="blog"></category></entry></feed>