<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/exploratory-data-analysis-data-preparation-with-funmodeling/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://blog.datascienceheroes.com/exploratory-data-analysis-data-preparation-with-funmodeling/"> R - Data Science Heroes Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h1>funModeling quick-start</h1>
<p><img alt="Exploratory Data Analysis &amp; Data Preparation with 'funModeling'" src="https://i1.wp.com/blog.datascienceheroes.com/content/images/2018/01/funModeling_cover.png?w=456" data-recalc-dims="1"></p>
<p>This package contains a set of functions related to exploratory data analysis, data preparation, and model performance. It is used by people coming from business, research, and teaching (professors and students).</p>
<p><img alt="Exploratory Data Analysis &amp; Data Preparation with 'funModeling'" src="https://i2.wp.com/datascienceheroes.com/img/blog/funModeling_cover_3.png?w=400&ssl=1" data-recalc-dims="1"></p>
<p><code>funModeling</code> is intimately related to the <em>Data Science Live Book</em> -Open Source- (2017) in the sense that most of its functionality is used to explain different topics addressed by the book.</p>
<p><img alt="Exploratory Data Analysis &amp; Data Preparation with 'funModeling'" src="https://i2.wp.com/datascienceheroes.com/img/blog/data-science-live-book-cover-2.png?w=200&ssl=1" data-recalc-dims="1"></p>
<p><img alt="📗" src="https://s.w.org/images/core/emoji/2.3/72x72/1f4d7.png" class="wp-smiley"> <em>The paperback version is being prepared, get notified by the <a rel="nofollow" href="http://datascienceheroes.us11.list-manage.com/subscribe?u=926c6b0c9f42f5cd0df67a9a0&id=5fa77fa6c2" target="_blank">newsletter</a> or <a rel="nofollow" href="https://twitter.com/pabloc_ds" target="_blank">twitter</a>.</em></p>
<h2>Opening the black-box </h2>
<p>Some functions have in-line comments so the user can open the black-box and learn how it was developed, or to tune or improve any of them.</p>
<p>All the functions are well documented, explaining all the parameters with the help of many short examples. R documentation can be accessed by: <code>help(&quot;name_of_the_function&quot;)</code>.</p>
<p><strong>Important changes from latest version 1.6.7</strong>, (relevant only if you were using previous versions):</p>
<p>From the latest version, 1.6.7 (Jan 21-2018), the parameters <code>str_input</code>, <code>str_target</code> and <code>str_score</code> will be renamed to <code>input</code>, <code>target</code> and <code>score</code> respectively. The functionality remains the same.</p>
<p>If you were using these parameters names on production, they will be still working until next release. this means that for now, you can use for example <code>str_input</code> or <code>input</code>.</p>
<p>The other important change was in <code>discretize_get_bins</code>, which is detailed later in this document.</p>
<p></p>
<h3>About this quick-start</h3>
<p>This quick-start is focused only on the functions. All explanations around them, and the how and when to use them, can be accessed by following the “<strong><em>Read more here.</em></strong>” links below each section, which redirect you to the book.</p>
<p>Below there are most of the <code>funModeling</code> functions divided by category.</p>
<h2>Exploratory data analysis </h2>
<h3><code>df_status</code>: Dataset health status</h3>
<p>Use case: analyze the zeros, missing values (<code>NA</code>), infinity, data type, and number of unique values for a given dataset.</p>
<pre><code>library(funModeling)

df_status(heart_disease)

##                  variable q_zeros p_zeros q_na p_na q_inf p_inf    type
## 1                     age       0    0.00    0 0.00     0     0 integer
## 2                  gender       0    0.00    0 0.00     0     0  factor
## 3              chest_pain       0    0.00    0 0.00     0     0  factor
## 4  resting_blood_pressure       0    0.00    0 0.00     0     0 integer
## 5       serum_cholestoral       0    0.00    0 0.00     0     0 integer
## 6     fasting_blood_sugar     258   85.15    0 0.00     0     0  factor
## 7         resting_electro     151   49.83    0 0.00     0     0  factor
## 8          max_heart_rate       0    0.00    0 0.00     0     0 integer
## 9             exer_angina     204   67.33    0 0.00     0     0 integer
## 10                oldpeak      99   32.67    0 0.00     0     0 numeric
## 11                  slope       0    0.00    0 0.00     0     0 integer
## 12      num_vessels_flour     176   58.09    4 1.32     0     0 integer
## 13                   thal       0    0.00    2 0.66     0     0  factor
## 14 heart_disease_severity     164   54.13    0 0.00     0     0 integer
## 15           exter_angina     204   67.33    0 0.00     0     0  factor
## 16      has_heart_disease       0    0.00    0 0.00     0     0  factor
##    unique
## 1      41
## 2       2
## 3       4
## 4      50
## 5     152
## 6       2
## 7       3
## 8      91
## 9       2
## 10     40
## 11      3
## 12      4
## 13      3
## 14      5
## 15      2
## 16      2
</code></pre>
<p>[<img alt="🔎" src="https://s.w.org/images/core/emoji/2.3/72x72/1f50e.png" class="wp-smiley"> <a rel="nofollow" href="https://livebook.datascienceheroes.com/exploratory-data-analysis.html#dataset-health-status" target="_blank"><strong>Read more<br>
here.</strong></a>]</p>
<p></p>
<h3><code>plot_num</code>: Plotting distributions for numerical variables</h3>
<p>Plots only numeric variables.</p>
<pre><code>plot_num(heart_disease)
</code></pre>
<p><img alt="Exploratory Data Analysis &amp; Data Preparation with 'funModeling'" src="https://i0.wp.com/blog.datascienceheroes.com/content/images/2018/01/unnamed-chunk-2-1.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>Notes:</p>
<ul>
<li><code>bins</code>: Sets the number of bins (10 by default).</li>
<li><code>path_out</code> indicates the path directory; if it has a value, then the<br>
plot is exported in jpeg. To save in current directory path must be<br>
dot: “.”</li>
</ul>
<p>[<img alt="🔎" src="https://s.w.org/images/core/emoji/2.3/72x72/1f50e.png" class="wp-smiley"> <a rel="nofollow" href="https://livebook.datascienceheroes.com/exploratory-data-analysis.html#plotting-numerical-variable" target="_blank"><strong>Read more<br>
here.</strong></a>]</p>
<p></p>
<h3><code>profiling_num</code>: Calculating several statistics for numerical variables</h3>
<p>Retrieves several statistics for numerical variables.</p>
<pre><code>profiling_num(heart_disease)

##                 variable   mean std_dev variation_coef p_01 p_05 p_25
## 1                    age  54.44    9.04           0.17   35   40   48
## 2 resting_blood_pressure 131.69   17.60           0.13  100  108  120
## 3      serum_cholestoral 246.69   51.78           0.21  149  175  211
## 4         max_heart_rate 149.61   22.88           0.15   95  108  134
## 5            exer_angina   0.33    0.47           1.44    0    0    0
## 6                oldpeak   1.04    1.16           1.12    0    0    0
## 7                  slope   1.60    0.62           0.38    1    1    1
## 8      num_vessels_flour   0.67    0.94           1.39    0    0    0
## 9 heart_disease_severity   0.94    1.23           1.31    0    0    0
##    p_50  p_75  p_95  p_99 skewness kurtosis  iqr        range_98
## 1  56.0  61.0  68.0  71.0    -0.21      2.5 13.0        [35, 71]
## 2 130.0 140.0 160.0 180.0     0.70      3.8 20.0      [100, 180]
## 3 241.0 275.0 326.9 406.7     1.13      7.4 64.0   [149, 406.74]
## 4 153.0 166.0 181.9 192.0    -0.53      2.9 32.5 [95.02, 191.96]
## 5   0.0   1.0   1.0   1.0     0.74      1.5  1.0          [0, 1]
## 6   0.8   1.6   3.4   4.2     1.26      4.5  1.6        [0, 4.2]
## 7   2.0   2.0   3.0   3.0     0.51      2.4  1.0          [1, 3]
## 8   0.0   1.0   3.0   3.0     1.18      3.2  1.0          [0, 3]
## 9   0.0   2.0   3.0   4.0     1.05      2.8  2.0          [0, 4]
##         range_80
## 1       [42, 66]
## 2     [110, 152]
## 3 [188.8, 308.8]
## 4   [116, 176.6]
## 5         [0, 1]
## 6       [0, 2.8]
## 7         [1, 2]
## 8         [0, 2]
## 9         [0, 3]
</code></pre>
<p>Note:</p>
<ul>
<li><code>plot_num</code> and <code>profiling_num</code> automatically exclude non-numeric<br>
variables</li>
</ul>
<p>[<img alt="🔎" src="https://s.w.org/images/core/emoji/2.3/72x72/1f50e.png" class="wp-smiley"> <a rel="nofollow" href="https://livebook.datascienceheroes.com/exploratory-data-analysis.html#numerical-profiling-in-r" target="_blank"><strong>Read more<br>
here.</strong></a>]</p>
<p></p>
<h3><code>freq</code>: Getting frequency distributions for categoric variables</h3>
<pre><code>library(dplyr)

# Select only two variables for this example
heart_disease_2=heart_disease %>% select(chest_pain, thal)

# Frequency distribution
freq(heart_disease_2)
</code></pre>
<p><img alt="Exploratory Data Analysis &amp; Data Preparation with 'funModeling'" src="https://i2.wp.com/blog.datascienceheroes.com/content/images/2018/01/distribution_categorical_variable-1.png?w=456&ssl=1" data-recalc-dims="1"></p>
<pre><code>##   chest_pain frequency percentage cumulative_perc
## 1          4       144       47.5              48
## 2          3        86       28.4              76
## 3          2        50       16.5              92
## 4          1        23        7.6             100
</code></pre>
<p><img alt="Exploratory Data Analysis &amp; Data Preparation with 'funModeling'" src="https://i0.wp.com/blog.datascienceheroes.com/content/images/2018/01/distribution_categorical_variable-2.png?w=456&ssl=1" data-recalc-dims="1"></p>
<pre><code>##   thal frequency percentage cumulative_perc
## 1    3       166      54.79              55
## 2    7       117      38.61              93
## 3    6        18       5.94              99
## 4 </code></pre>