<span><span lang="en"><span>We will develop a classification example using 1R and RIPPER rule learners algorithms. The exercise was originally published in <i>&quot;Machine Learning in R&quot; </i>by Brett Lantz, PACKT publishing 2015 (open source community experience destilled).</span></span></span><br><br><span><span lang="en"><span><span lang="en"><span>The example we will develop is about classifying edible and poisonous mushrooms.</span></span></span></span></span><br><div><span><a href="https://2.bp.blogspot.com/-FdB-HV4sl6g/WQoH_-Bp7tI/AAAAAAAAC2A/s0J1f3XUdjYULtVo2FLQkxvqDLzCtbD6QCLcB/s1600/mush1.jpeg"></a></span></div><span><span lang="en"><span></span></span></span><br><span><br><span lang="en"><span><span lang="en"><span><span lang="en"><span>We will carry out the exercise verbatim as published in the aforementioned reference and </span></span></span></span></span></span><span lang="en"><span>including some simple transformations to the dataset.</span></span></span><br><span><span lang="en"><span><span lang="en"><span>For more details on the algorithms it is recommended to check the aforementioned reference.</span></span> </span></span></span><br><br><span><span lang="en"><span><br>### install and load required packages<br>#install.packages(&quot;RWeka&quot;)<br><br>library(RWeka)<br><br>### read and explore the data<br>mushrooms &lt;- read.csv(&quot;mushrooms.csv&quot;, stringsAsFactors = TRUE)<br>str(mushrooms)<br><br>### drop $veil_type column (does not provide)<br>### useful information<br>mushrooms$veil_type &lt;- NULL<br><br>### look at the distribution of the muschroom type<br>### class variable<br>table(mushrooms$type)<br><br>### data transformation<br><br>#Below function transforms the $type column<br>transformType &lt;- function(key){<br>  switch (as.character(key),<br>          'p' = 'poisonous',<br>          'e' = 'edible'<br>  )<br>}<br><br>#Below function transforms the $odor column<br>transformOdor &lt;- function(key){<br>  switch (as.character(key),<br>          'a' = 'almond',<br>          'l' = 'anise',<br>          'c' = 'creosote',<br>          'y' = 'fishy',<br>          'f' = 'foul',<br>          'm' = 'musty',<br>          'n' = 'none',<br>          'p' = 'pungent',<br>          's' = 'spicy'<br>  )<br>}<br><br>### apply transformations<br>mushrooms$type &lt;- sapply(mushrooms$type, transformType)<br>mushrooms$odor &lt;- sapply(mushrooms$odor, transformOdor)<br><br>mushrooms$type &lt;- as.factor(mushrooms$type)<br>mushrooms$odor &lt;- as.factor(mushrooms$odor)<br> </span></span></span><br><span><span lang="en"><span>### training a model on the data<br><br>### use the 1R implementation in the RWeka package<br>### called OneR()<br><br>### consider all possible features to predict $type<br>mushroom_1R &lt;- OneR(type ~ ., data = mushrooms)<br>mushroom_1R</span></span></span><br><br><span><span lang="en"><span>### 1R one rule selected:</span></span></span><br><span><span lang="en"><span> </span></span></span><br><span><span lang="en"><span></span></span></span><br><span><span lang="en"><span></span></span></span><br><div><span><a href="https://2.bp.blogspot.com/-Qo8Zn0r47hA/WQoJ-Ma7UUI/AAAAAAAAC2M/5ZdG0p1D-5MZPLnOmysA7ZxYzTwTu_8WgCLcB/s1600/mush2.png"></a></span></div><span><span lang="en"><span></span></span></span><br><span><span lang="en"><span><br>### evaluating model performance<br>summary(mushroom_1R)</span></span></span><br><span><span lang="en"><span><br></span></span></span><div><span><a href="https://1.bp.blogspot.com/-Wfaj5SI4F-Q/WQoKaZjWGqI/AAAAAAAAC2Q/KrB3vcZSTmQwATsSDft4ZjRgwtI3E1-XACLcB/s1600/mush3.png"></a></span></div><span><span lang="en"><span><br></span></span></span><span><span lang="en"><span>### improving model performance<br>### JRip() Java-based implementation of the Ripper<br>### rule learning algorithm<br>mushroom_JRip &lt;- JRip(type ~ ., data = mushrooms)<br></span></span></span><br><span><span lang="en"><span>### RIPPER selected rules (9): <br>mushroom_JRip</span></span></span><br><span><span lang="en"><span><br></span></span></span><div><span><a href="https://3.bp.blogspot.com/-ag4mNlvn7vA/WQoK1SQnt0I/AAAAAAAAC2U/sDOPymcxkH4HUaE-Ze6Upy1z1ibzX670gCLcB/s1600/mush4.png"></a></span></div><span><span lang="en"><span></span></span></span><br><span><br></span><span><span lang="en"><span>You can get the example and the dataset in:</span></span></span><br><span><span><span lang="en"><span><a target="_blank" href="https://github.com/pakinja/Data-R-Value/tree/master/MachineLearning_Identifying_Mushrooms_1R_RIPPER">https://github.com/pakinja/Data-R-Value</a></span></span></span></span><br><span><span lang="en"><span><br></span></span></span>