<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/the-seaclass-r-package/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://rviews.rstudio.com/2017/10/23/the-seaclass-r-package/"> R Views</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<h1>The SeaClass R Package</h1>
<p>The Operations Technology and Advanced Analytics Group (OTAAG) at Seagate Technology has decided to share an internal project that helps accelerate development of classification models. The interactive SeaClass tool is contained in an R-based package built using <code>shiny</code> and other CRAN packages commonly used for binary classification. The package is free to use and develop further, but any analysis mistakes are the sole responsibility of the user. Check out the demo video below:</p>
<p align="center">
<iframe width="95%" allowfullscreen src="https://www.youtube.com/embed/ZTz9ZcATQ_M" height="480px"></iframe>
</p>
<div>
<h3>Origin Story</h3>
<p>Manufacturer data sets used for pass/fail analysis are typically highly imbalanced with many more passing cases than failing cases. In some situations, the failure examples may be scarce or nonexistent. In these extreme cases complex modeling techniques are likely inadvisable. Data scientists commonly consider data scarcity, class imbalance, and data dimensionality when discriminating between competing candidate approaches, such as anomaly detection, simple models, and complex models. Standard approaches are easily identified within each of these analysis categories, and can be exploited as reasonable initial classification analysis baselines.</p>
<p>The SeaClass application was created to generate template R code for the commonly encountered classification problems described above. The application allows data analysts to explore multiple models quickly with essentially no programming required. SeaClass provides an option to download the corresponding R code for further model training/testing. This workflow enables our data analysts to jump-start their modeling, saving time and initial hassles.</p>
<p>The Advanced Analytics group decided to open-source the package for several reasons. Firstly, we encourage other contributors to suggest improvements to the SeaClass application. Additionally, we are hopeful our application will inspire other code-generating projects within the R community. Lastly, our group benefits greatly from open-source tools, and it’s nice to give back every once in a while.</p>
</div>
<div>
<h3>Package Overview</h3>
<p>The SeaClass R package provides tools for analyzing classification problems. In particular, specialized tools are available for addressing the problem of imbalanced data sets. The SeaClass application provides an easy-to-use interface that requires only minimal R programming knowledge to get started, and can be launched using the RStudio Addins menu. The application allows the user to explore numerous methods by simply clicking on the available options and interacting with the generated results. The user can choose to download the codes for any procedures they wish to explore further. SeaClass was designed to jump-start the analysis process for both novice and advanced R users. See screenshots below for one demonstration.</p>
<div>
<img src="https://i2.wp.com/rviews.rstudio.com/post/2017-10-16-Dienes-SeaClass_files/screen_shots.png?w=456&ssl=1" data-recalc-dims="1">
</div>
</div>
<div>
<h3>Installation Instructions</h3>
<p>The SeaClass application depends on multiple R packages. To install SeaClass and its dependencies, run:</p>
<pre><code>install.packages('devtools')
devtools::install_github('ChrisDienes/SeaClass')</code></pre>
</div>
<div>
<h3>Usage Instructions</h3>
<p><strong>Step 1.</strong> Begin by loading and preparing your data in R. Some general advice:</p>
<ul>
<li>Your data set must be saved as an R data frame object.</li>
<li>The data set must contain a binary response variable (0/1, PASS/FAIL, A/B, etc.)</li>
<li>All other variables must be predictor variables.</li>
<li>Predictor variables can be numeric, categorical, or factors.</li>
<li>Including too many predictors may slow down the application and weaken performance.</li>
<li>Categorical predictors are often ignored when the number of levels exceeds 10, since they tend to have improper influences.</li>
<li>Missing values are not allowed and will throw a flag. Please remove or impute NAs prior to starting the app.</li>
<li>Keep the number of observations (rows) to a medium or small size.</li>
<li>Data sets with many rows (>10,000) or many columns (>30) may slow down the app’s interactive responses.</li>
</ul>
<p><strong>Step 2.</strong> After data preparation, start the application by either loading SeaClass from the RStudio Addins drop-down menu, or by loading the SeaClass function from the command line. For example:</p>
<pre><code>library(SeaClass)

### Make some fake data:
X &lt;- matrix(rnorm(10000,0,1),ncol=10,nrow=1000)
X[1:100,1:2] &lt;- X[1:100,1:2] + 3
Y &lt;- c(rep(1,100), rep(0,900))
Fake_Data &lt;- data.frame(Y = Y , X)

### Load the SeaClass rare failure data:
data(&quot;rareFailData&quot;)

### Start the interactive GUI:
SeaClass()</code></pre>
<p>If the application fails to load, you may need to specify your favorite browser path first. For example:</p>
<pre><code>options(browser = &quot;C:/Program Files (x86)/Google/Chrome/Application/chrome.exe&quot;)</code></pre>
<p><strong>Step 3.</strong> The user has various options for configuring their analysis within the GUI. Once the analysis runs, the user can view the results, interact with the results (module-dependent), save the underlying R script, or start over. Additional help is provided within the application. See above screenshots for one depiction of these steps.</p>
<p><strong>Step 4.</strong> Besides the SeaClass function, several other functions are contained within the library. For example:</p>
<pre><code>### List available functions:
ls(&quot;package:SeaClass&quot;)
### Note this is a sample data set:
# data(rareFailData)
### Note code_output is a support function for SeaClass, not for general use.

### View help:
?accuracy_threshold

### Run example from help file:
### General Use: ###
set.seed(123)
x &lt;- c(rnorm(100,0,1),rnorm(100,2,1))
group &lt;- c(rep(0,100),rep(2,100))
accuracy_threshold(x=x, group=group, pos_class=2)
accuracy_threshold(x=x, group=group, pos_class=0)
### Bagged Example ###
set.seed(123)
replicate_function = function(index){accuracy_threshold(x=x[index], group=group[index], pos_class=2)[[2]]}
sample_cuts &lt;- replicate(100, {
  sample_index = sample.int(n=length(x),replace=TRUE)
  replicate_function(index=sample_index)
})
bagged_scores &lt;- sapply(x, function(x) mean(x > sample_cuts))
unbagged_cut    &lt;- accuracy_threshold(x=x, group=group, pos_class=2)[[2]]
unbagged_scores &lt;- ifelse(x > unbagged_cut, 1, 0)
# Compare AUC:
PRROC::roc.curve(scores.class0 = bagged_scores,weights.class0 = ifelse(group==2,1,0))[[2]]
PRROC::roc.curve(scores.class0 = unbagged_scores,weights.class0 = ifelse(group==2,1,0))[[2]]
bagged_prediction &lt;- ifelse(bagged_scores > 0.50, 2, 0)
unbagged_prediction &lt;- ifelse(x > unbagged_cut, 2, 0)
# Compare Confusion Matrix:
table(bagged_prediction, group)
table(unbagged_prediction, group)</code></pre>
</div>
</div>
<p> </p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://rviews.rstudio.com/2017/10/23/the-seaclass-r-package/"> R Views</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/xd7WYwXQTe8" height="1"></a></div>