R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(C50)
library(rpart)
library(rpart.plot)
library(gmodels)

NewResin_Train <- read.csv("C:/Users/gujjes/Downloads/MLTraining(1).csv", header=TRUE)
set.seed(12345)
resin2_rand <- NewResin_Train[order(runif(340)),]
resin2_train <-resin2_rand[1:270,]
resin2_test<-resin2_rand[271:340,]
table(resin2_train$Final.Resin.Product)
## 
## 34.9928 44.6572 44.8958 45.2194 48.1125 48.2656 48.5985 48.9419 49.6108 49.8733 
##       1       1       1       1       1       1       1       1       1       1 
## 50.0562  50.539 50.7018 50.8264 51.0388 51.0645 51.4173 51.6389 51.7499 51.7542 
##       1       1       3       1       1       1       1       1       1       1 
## 51.9275 52.0255 52.2982    52.4 52.6632 52.6775 52.8568  53.603 53.6901 53.7431 
##       1       1       1       1       1       1       1       1       1       1 
## 53.7647  53.818 54.2838 54.7161 54.7379 54.7551 54.9143 54.9633 55.1662 55.3368 
##       1       1       1       1       1       1       1       1       1       1 
##  55.384 55.6709 55.7156 55.9854 55.9974 56.1077 56.1411 56.2317 56.2341 56.2578 
##       1       1       1       1       1       1       1       1       1       1 
## 56.2895 56.3344 56.4587 56.4832 56.8166 56.8912 56.9286  57.002 57.0878 57.2828 
##       1       1       1       1       1       1       1       1       5       1 
## 57.3665 57.3837 57.4046 57.4496 57.4905 57.5374 57.5674 57.5757 57.8292 57.8816 
##       1       1       1       1       1       1       1       1       1       1 
## 57.9132 57.9862 58.0684 58.2107 58.4465 58.5547 58.5715 58.6142 58.6497 58.7121 
##       1       1       1       2       1       1       1       1       1       1 
## 58.7922 58.8721 58.9861 59.0097 59.0224 59.0736 59.0983 59.1129 59.1402 59.1799 
##       1       1       1       1       1       1       1       1       2       1 
## 59.2057 59.2104  59.228 59.2459 59.2728 59.2894 59.4259  59.447 59.4888   59.57 
##       1       1       1       1       1       1       1       1       1       1 
## 59.5771 59.6041 59.6207 59.6351 59.7572 59.8172 60.0028 60.0155 60.0915 60.1198 
##       1       1       1       1       1       2       1       1       2       1 
## 60.3389  60.348 60.3841 60.4143 60.5704 60.5905 60.5985 60.6612 60.7256 60.8884 
##       2       1       1       1       2       1       1       1       1       1 
## 60.8994  60.934  61.034  61.046 61.1001 61.2245 61.2518 61.2966 61.3639 61.5648 
##       2       2       1       1       1       1       1       1       1       2 
## 61.5701 61.6041 61.6135 61.6949 61.7537 61.8115 61.8191 61.9076 61.9088 61.9613 
##       1       1       1       1       1       2       1       1       1       1 
## 61.9674 62.0589 62.1702 62.2274 62.3344 62.4202 62.4287 62.5098   62.52 62.6006 
##       1       1       1       1       1       1       1       1       1       1 
## 62.6577 62.6643 62.6892 62.7188 62.7826 62.8249 62.8315 62.8651 62.8687 62.8756 
##       1       1       1       1       1       1       1       1       1       2 
##   62.99 63.1088 63.1921 63.2418 63.3183 63.4132 63.5061 63.5566 63.5663 63.5726 
##       1       1       1       1       1       1       1       1       1       1 
## 63.5974 63.7812 63.8119  63.828 63.9541 64.0708 64.0758 64.1042 64.1197 64.2108 
##       1       1       1       1       1       1       2       1       1       1 
## 64.2601 64.2815   64.36 64.3693 64.5671 64.6052  64.814 64.8494 64.8729 64.9631 
##       1       1       1       1       1       1       1       1       1       1 
## 65.0551 65.0753 65.0813  65.095 65.2009 65.3427 65.3517 65.3891 65.4238 65.4736 
##       1       1       1       1       1       1       1       1       2       1 
## 65.5486  65.668 65.7484  65.756 65.8051 65.8464 66.2678 66.2943 66.6801 66.7297 
##       1       1       1       1       1       1       1       1       1       1 
## 66.8832 66.9857 67.0707 67.3765 67.4257 67.4869 67.7875 67.9357 67.9925 68.0716 
##       1       1       1       1       1       1       1       1       1       1 
## 68.0742 68.2574 68.2739 68.4055 68.5176 68.7697 68.8784 68.9225 68.9638 68.9814 
##       1       1       1       1       1       1       1       1       1       1 
##  69.279 69.2873 69.7735 69.8379 70.1889 70.9129 70.9775 70.9784 71.2017 71.3125 
##       1       1       1       1       1       1       1       1       1       1 
## 71.3756 71.7253 72.3614 72.4389 73.0963  73.326 74.1765 74.3419 75.1404 75.5366 
##       1       1       1       1       1       1       1       1       1       1 
## 76.5254 
##       1
table(resin2_test$Final.Resin.Product)
## 
## 47.5572 48.3608 48.6229 49.5325 52.1271 53.8438 54.0355 54.5898 54.9711 55.0156 
##       1       1       1       1       1       1       1       1       1       1 
## 55.0341 55.6709 55.7981 55.8494 56.3987 56.8221  57.008 57.0878 57.1346 57.3655 
##       1       1       1       1       1       1       1       1       1       1 
## 57.3984 57.5674 58.0194 58.1832   58.19 58.3068 58.5035 58.5396 58.6643 58.8232 
##       1       1       1       1       1       1       1       1       1       1 
## 58.9058 58.9658  60.466 60.8805 60.8994 60.9887 61.0097 61.0295 61.0485 61.3695 
##       1       1       1       1       1       1       1       1       1       1 
## 61.4811 61.5819 61.6108 61.6857 61.7275 61.8042 61.9567 62.6759 62.7188 62.8934 
##       1       1       1       2       1       1       1       1       1       1 
##  63.006 63.3174 63.3907 63.5974 63.6159 63.8075 64.0664 64.2346  64.769 65.3747 
##       1       1       1       1       1       1       1       1       1       1 
## 66.4547 67.2839 67.3574 67.8877 68.2994 68.6541 69.0085 72.9945 78.5917 
##       1       1       1       1       1       1       1       1       1
str(resin2_test)
## 'data.frame':    70 obs. of  35 variables:
##  $ TreeSite                : chr  "Mix Harvest" "City Harvest" "City Harvest" "Village Harvest" ...
##  $ Pressure                : num  3 0 0 2 3 2 0 1 2 4 ...
##  $ Step1.Temp              : int  18 18 18 18 18 18 18 18 18 18 ...
##  $ Step1.conductivity      : num  13.5 13.2 13.5 13.2 13.5 13.5 13.5 11.4 13.5 12.8 ...
##  $ Step1.Resin             : num  14049 14064 13496 13272 14266 ...
##  $ Step2.pH                : num  5.6 5.66 5.6 5.64 5.67 5.64 5.64 5.67 5.62 5.6 ...
##  $ Step2.Conductivity      : int  49 50 46 49 50 50 50 48 48 49 ...
##  $ Step2.Yield             : int  8 9 10 8 8 9 8 8 9 7 ...
##  $ Step3.Temp              : num  19.7 19.7 19 19.7 19.7 ...
##  $ Step3.pH                : num  5.64 5.68 5.66 5.65 5.68 5.68 5.67 5.68 5.68 5.63 ...
##  $ Step3.Conductivity      : int  40 40 41 40 40 40 40 40 40 41 ...
##  $ Step3.yield             : int  18 15 14 17 15 17 14 16 15 17 ...
##  $ Step3.compression       : num  1.18 1.18 1.18 1.16 1.18 ...
##  $ Step4.pH                : num  5.47 7.69 7.2 7.55 5.9 6.61 5.33 6.81 5.6 7.27 ...
##  $ Step5.yield             : num  77 81 83 82 78 80 79 79 81 78 ...
##  $ Step5.temp              : num  18 19 18 19 19 19 18 19 19 20 ...
##  $ Step6.pH.start          : num  4.61 4.69 4.62 4.69 4.61 4.63 4.67 4.62 4.64 4.63 ...
##  $ Step6.Conductivity.start: num  106 107 105 106 120 ...
##  $ Step6.temperature       : int  17 18 18 18 17 17 18 17 18 18 ...
##  $ Step7.symmetry          : num  1.8 1.75 1.69 9.67 1.12 1.52 1.61 1.12 1.8 1.46 ...
##  $ Step8.temperature       : num  18.5 18.5 19 18.5 18 ...
##  $ step.8.yield            : int  91 92 92 92 92 93 94 92 93 90 ...
##  $ Step7.UV                : num  3.01 2.97 2.98 3.02 3 ...
##  $ Step8.UV                : num  0.692 0.694 0.72 0.69 0.712 ...
##  $ Step.1.pH               : num  7.18 7.2 7.24 7.1 7.2 ...
##  $ step.1.particles        : num  2647813 2780000 3255000 33000000 3059091 ...
##  $ step.1.quality.         : num  93.6 91.8 86 95 90 ...
##  $ step0.total.particles   : num  998582 920513 1060000 850000 1100000 ...
##  $ step0.warmup.hrs        : num  16.9 16.9 16.9 16 16.9 ...
##  $ step0.input.pH          : num  7.2 7.1 7.2 7.1 7.2 ...
##  $ step0.output.pH         : num  7.32 7.27 7.25 7.3 7.27 ...
##  $ Step0.tmpressure        : num  15.3 19.1 16.2 14.7 14.3 ...
##  $ Step0.return.flow       : num  81.9 81.9 81.9 80.3 81.9 ...
##  $ Step0.temperature       : num  10 10.12 10.12 10 9.88 ...
##  $ Final.Resin.Product     : num  56.4 61.7 55 62.7 61 ...
str(resin2_train)
## 'data.frame':    270 obs. of  35 variables:
##  $ TreeSite                : chr  "Village Harvest" "Village Harvest" "Village Harvest" "City Harvest" ...
##  $ Pressure                : num  2 0 0 0 1 1 2 3 3 2 ...
##  $ Step1.Temp              : int  18 18 18 18 18 18 18 18 18 18 ...
##  $ Step1.conductivity      : num  13.2 13.5 13.3 13.5 13.4 13 13.7 13.4 13.4 13.2 ...
##  $ Step1.Resin             : num  13159 12483 12785 14100 12563 ...
##  $ Step2.pH                : num  5.64 5.64 5.65 5.66 5.61 5.64 5.63 5.61 5.67 5.64 ...
##  $ Step2.Conductivity      : int  49 49 49 49 50 49 49 50 46 49 ...
##  $ Step2.Yield             : int  8 7 9 9 8 7 7 8 9 8 ...
##  $ Step3.Temp              : num  19 19.7 19.7 19.7 19.7 ...
##  $ Step3.pH                : num  5.63 5.65 5.67 5.68 5.66 5.64 5.62 5.7 5.68 5.65 ...
##  $ Step3.Conductivity      : int  41 40 40 40 40 40 40 40 40 40 ...
##  $ Step3.yield             : int  17 21 16 14 20 18 17 15 17 17 ...
##  $ Step3.compression       : num  1.26 1.16 1.18 1.18 1.16 ...
##  $ Step4.pH                : num  6.43 6.91 7.3 6.7 7.02 6.99 7.49 7.21 7.33 7.55 ...
##  $ Step5.yield             : num  80 82 82 79 84 81 82 79 87 82 ...
##  $ Step5.temp              : num  18 19 18 18 20 20 19 19 20 19 ...
##  $ Step6.pH.start          : num  4.68 4.69 4.7 4.63 4.65 4.7 4.59 4.66 4.64 4.69 ...
##  $ Step6.Conductivity.start: num  102 103 105 104 104 ...
##  $ Step6.temperature       : int  17 18 18 18 18 18 18 17 18 18 ...
##  $ Step7.symmetry          : num  1.64 1.61 1.41 1.41 1.87 1.65 1.87 1.06 1.8 1.75 ...
##  $ Step8.temperature       : num  18.5 18.5 18.5 18.5 18.5 ...
##  $ step.8.yield            : int  90 93 93 93 90 92 91 91 92 92 ...
##  $ Step7.UV                : num  3.02 2.98 2.99 2.89 3.01 ...
##  $ Step8.UV                : num  0.701 0.703 0.688 0.713 0.727 ...
##  $ Step.1.pH               : num  7.2 7.2 7.2 7.1 7.2 ...
##  $ step.1.particles        : num  2427500 2640000 2770000 3670000 2780000 ...
##  $ step.1.quality.         : num  94.2 98.2 95.1 94.6 95.1 ...
##  $ step0.total.particles   : num  868889 840000 950000 1010256 960000 ...
##  $ step0.warmup.hrs        : num  19.7 16 16.9 16.9 17 ...
##  $ step0.input.pH          : num  7.2 7.2 7.1 7.1 7.2 ...
##  $ step0.output.pH         : num  7.34 7.31 7.3 7.3 7.32 ...
##  $ Step0.tmpressure        : num  13.8 15.6 14.4 17.4 14.8 ...
##  $ Step0.return.flow       : num  80.4 80.3 81.9 81.9 81.2 ...
##  $ Step0.temperature       : num  9.56 10.1 10.34 10.12 10.06 ...
##  $ Final.Resin.Product     : num  59.3 71 61 56.3 67.9 ...
resin2_train$TreeSite = as.factor(resin2_train$TreeSite)
resin2_test$TreeSite = as.factor(resin2_test$TreeSite)

##Re-running the decision tree and random forest models with modified data
#revised decision tree model with rpart
rpartmodel2 <- rpart(Final.Resin.Product~., data=resin2_train, method = 'anova')
summary(rpartmodel2)
## Call:
## rpart(formula = Final.Resin.Product ~ ., data = resin2_train, 
##     method = "anova")
##   n= 270 
## 
##            CP nsplit rel error    xerror       xstd
## 1  0.27791485      0 1.0000000 1.0055874 0.10489951
## 2  0.12178424      1 0.7220851 0.7358733 0.08309345
## 3  0.05422432      2 0.6003009 0.6458785 0.06759378
## 4  0.04176818      3 0.5460766 0.6351812 0.06604956
## 5  0.03741543      4 0.5043084 0.6213511 0.06285652
## 6  0.02942100      5 0.4668930 0.6096217 0.06118237
## 7  0.02619517      6 0.4374720 0.5943916 0.05938842
## 8  0.01947945      7 0.4112768 0.6027184 0.06229733
## 9  0.01704187      8 0.3917974 0.6047151 0.06499826
## 10 0.01527325     10 0.3577136 0.6097708 0.06550507
## 11 0.01509449     11 0.3424404 0.6141552 0.06497369
## 12 0.01316619     12 0.3273459 0.6106708 0.06610380
## 13 0.01155538     13 0.3141797 0.6164629 0.06093879
## 14 0.01000000     14 0.3026243 0.6159412 0.06163970
## 
## Variable importance
##                 TreeSite          step0.output.pH              Step1.Resin 
##                       17                       12                       11 
##        Step0.temperature          step.1.quality.                Step.1.pH 
##                       10                        9                        8 
##        Step0.return.flow         Step0.tmpressure              Step5.yield 
##                        6                        4                        3 
##           Step7.symmetry        Step3.compression Step6.Conductivity.start 
##                        3                        3                        2 
##       Step2.Conductivity                 Step4.pH       Step1.conductivity 
##                        1                        1                        1 
##              Step3.yield           step0.input.pH         step0.warmup.hrs 
##                        1                        1                        1 
##                 Step3.pH                 Step2.pH        Step8.temperature 
##                        1                        1                        1 
## 
## Node number 1: 270 observations,    complexity param=0.2779149
##   mean=60.86954, MSE=36.5422 
##   left son=2 (154 obs) right son=3 (116 obs)
##   Primary splits:
##       TreeSite          splits as  LLR,          improve=0.2779149, (0 missing)
##       Step0.temperature < 10.11453 to the right, improve=0.1623813, (0 missing)
##       Step1.Resin       < 12480.5  to the left,  improve=0.1602819, (0 missing)
##       step0.output.pH   < 7.289643 to the left,  improve=0.1521203, (0 missing)
##       Step5.yield       < 80.39818 to the left,  improve=0.1402625, (0 missing)
##   Surrogate splits:
##       step0.output.pH   < 7.298438 to the left,  agree=0.881, adj=0.724, (0 split)
##       Step0.temperature < 10.10913 to the right, agree=0.752, adj=0.422, (0 split)
##       Step.1.pH         < 7.197619 to the left,  agree=0.748, adj=0.414, (0 split)
##       Step0.return.flow < 81.90516 to the right, agree=0.719, adj=0.345, (0 split)
##       step.1.quality.   < 93.36066 to the left,  agree=0.711, adj=0.328, (0 split)
## 
## Node number 2: 154 observations,    complexity param=0.1217842
##   mean=58.10373, MSE=30.15883 
##   left son=4 (35 obs) right son=5 (119 obs)
##   Primary splits:
##       Step1.Resin       < 12808.5  to the left,  improve=0.2587107, (0 missing)
##       step.1.quality.   < 87.88226 to the left,  improve=0.1397313, (0 missing)
##       Step3.compression < 1.188815 to the right, improve=0.1126030, (0 missing)
##       Step0.temperature < 10.11453 to the right, improve=0.1038099, (0 missing)
##       Step0.tmpressure  < 11.30958 to the left,  improve=0.1000074, (0 missing)
##   Surrogate splits:
##       Step3.compression < 1.255    to the right, agree=0.812, adj=0.171, (0 split)
##       Step0.tmpressure  < 11.22096 to the left,  agree=0.812, adj=0.171, (0 split)
##       Step3.pH          < 5.575    to the left,  agree=0.792, adj=0.086, (0 split)
##       step.8.yield      < 88.5     to the left,  agree=0.786, adj=0.057, (0 split)
##       Step.1.pH         < 7.282807 to the right, agree=0.786, adj=0.057, (0 split)
## 
## Node number 3: 116 observations,    complexity param=0.05422432
##   mean=64.54139, MSE=21.3786 
##   left son=6 (108 obs) right son=7 (8 obs)
##   Primary splits:
##       Step7.symmetry     < 1.09     to the right, improve=0.2157324, (0 missing)
##       Step2.Conductivity < 46.5     to the right, improve=0.2137481, (0 missing)
##       Step1.Resin        < 12016.95 to the left,  improve=0.1925142, (0 missing)
##       step0.input.pH     < 7.109916 to the left,  improve=0.1856576, (0 missing)
##       Step0.tmpressure   < 15.28579 to the left,  improve=0.1340051, (0 missing)
##   Surrogate splits:
##       Step2.Conductivity < 45.5     to the right, agree=0.957, adj=0.375, (0 split)
## 
## Node number 4: 35 observations,    complexity param=0.02619517
##   mean=52.95318, MSE=28.8939 
##   left son=8 (13 obs) right son=9 (22 obs)
##   Primary splits:
##       step.1.quality.          < 90.06    to the left,  improve=0.2555674, (0 missing)
##       Step5.yield              < 80.5     to the left,  improve=0.2384527, (0 missing)
##       Step4.pH                 < 6.825    to the left,  improve=0.2024653, (0 missing)
##       Step6.Conductivity.start < 104.0245 to the left,  improve=0.1733643, (0 missing)
##       Step0.tmpressure         < 11.69608 to the left,  improve=0.1517861, (0 missing)
##   Surrogate splits:
##       Step4.pH                 < 6.825    to the left,  agree=0.857, adj=0.615, (0 split)
##       Step6.Conductivity.start < 104.0245 to the left,  agree=0.829, adj=0.538, (0 split)
##       Step3.compression        < 1.255    to the right, agree=0.771, adj=0.385, (0 split)
##       Step5.yield              < 78.5     to the left,  agree=0.743, adj=0.308, (0 split)
##       step.1.particles         < 2965385  to the left,  agree=0.743, adj=0.308, (0 split)
## 
## Node number 5: 119 observations,    complexity param=0.03741543
##   mean=59.6186, MSE=20.43363 
##   left son=10 (111 obs) right son=11 (8 obs)
##   Primary splits:
##       Step5.yield     < 82.5     to the left,  improve=0.15181570, (0 missing)
##       step.1.quality. < 88.11333 to the left,  improve=0.13551610, (0 missing)
##       Step3.yield     < 15.5     to the left,  improve=0.13437600, (0 missing)
##       Step8.UV        < 0.69485  to the left,  improve=0.11975150, (0 missing)
##       step0.input.pH  < 7.148436 to the left,  improve=0.09762502, (0 missing)
##   Surrogate splits:
##       Step3.yield < 19.5     to the left,  agree=0.958, adj=0.375, (0 split)
## 
## Node number 6: 108 observations,    complexity param=0.04176818
##   mean=63.95689, MSE=17.1909 
##   left son=12 (7 obs) right son=13 (101 obs)
##   Primary splits:
##       Step1.Resin      < 11697.75 to the left,  improve=0.22196350, (0 missing)
##       step0.input.pH   < 7.109916 to the left,  improve=0.19551480, (0 missing)
##       Step5.yield      < 83.5     to the left,  improve=0.09623668, (0 missing)
##       Step0.tmpressure < 15.28579 to the left,  improve=0.08981585, (0 missing)
##       step.1.quality.  < 87.775   to the left,  improve=0.07204267, (0 missing)
## 
## Node number 7: 8 observations
##   mean=72.43206, MSE=11.03769 
## 
## Node number 8: 13 observations
##   mean=49.41813, MSE=31.68906 
## 
## Node number 9: 22 observations,    complexity param=0.01509449
##   mean=55.04207, MSE=15.4944 
##   left son=18 (7 obs) right son=19 (15 obs)
##   Primary splits:
##       Step0.tmpressure < 12.13498 to the left,  improve=0.4368973, (0 missing)
##       Step1.Resin      < 12309.65 to the left,  improve=0.4230592, (0 missing)
##       Step8.UV         < 0.70935  to the left,  improve=0.3818082, (0 missing)
##       Step5.yield      < 80.5     to the left,  improve=0.3781286, (0 missing)
##       step.1.quality.  < 93.00179 to the left,  improve=0.3153516, (0 missing)
##   Surrogate splits:
##       Step2.pH           < 5.625    to the left,  agree=0.864, adj=0.571, (0 split)
##       Step3.compression  < 1.235    to the right, agree=0.864, adj=0.571, (0 split)
##       step0.input.pH     < 7.203334 to the right, agree=0.864, adj=0.571, (0 split)
##       Step1.conductivity < 12.4     to the left,  agree=0.818, adj=0.429, (0 split)
##       Step2.Yield        < 7.5      to the left,  agree=0.818, adj=0.429, (0 split)
## 
## Node number 10: 111 observations,    complexity param=0.029421
##   mean=59.14576, MSE=16.74951 
##   left son=20 (19 obs) right son=21 (92 obs)
##   Primary splits:
##       step.1.quality.   < 88.045   to the left,  improve=0.15613160, (0 missing)
##       Step0.temperature < 10.03571 to the right, improve=0.14071740, (0 missing)
##       Step3.yield       < 15.5     to the left,  improve=0.12832540, (0 missing)
##       Step8.UV          < 0.69485  to the left,  improve=0.12466030, (0 missing)
##       Step0.tmpressure  < 15.9099  to the right, improve=0.08834975, (0 missing)
##   Surrogate splits:
##       Step8.UV         < 0.6879   to the left,  agree=0.856, adj=0.158, (0 split)
##       step0.warmup.hrs < 18.3     to the right, agree=0.838, adj=0.053, (0 split)
## 
## Node number 11: 8 observations
##   mean=66.17926, MSE=25.40629 
## 
## Node number 12: 7 observations
##   mean=56.53693, MSE=12.97275 
## 
## Node number 13: 101 observations,    complexity param=0.01947945
##   mean=64.47115, MSE=13.40304 
##   left son=26 (90 obs) right son=27 (11 obs)
##   Primary splits:
##       Step0.tmpressure  < 15.28579 to the left,  improve=0.14197460, (0 missing)
##       step0.input.pH    < 7.108064 to the left,  improve=0.11890590, (0 missing)
##       Step5.yield       < 83.5     to the left,  improve=0.09538495, (0 missing)
##       Step8.UV          < 0.7202   to the left,  improve=0.07473181, (0 missing)
##       Step0.temperature < 9.9214   to the right, improve=0.07340118, (0 missing)
## 
## Node number 18: 7 observations
##   mean=51.2334, MSE=4.023933 
## 
## Node number 19: 15 observations
##   mean=56.81945, MSE=10.91874 
## 
## Node number 20: 19 observations
##   mean=55.58729, MSE=17.89809 
## 
## Node number 21: 92 observations,    complexity param=0.01527325
##   mean=59.88066, MSE=13.3571 
##   left son=42 (65 obs) right son=43 (27 obs)
##   Primary splits:
##       Step0.temperature < 10.03571 to the right, improve=0.12262810, (0 missing)
##       Step7.symmetry    < 1.565    to the left,  improve=0.11603610, (0 missing)
##       TreeSite          splits as  LR-,          improve=0.08158899, (0 missing)
##       step0.input.pH    < 7.117524 to the left,  improve=0.07876424, (0 missing)
##       Step3.compression < 1.188815 to the right, improve=0.07780008, (0 missing)
##   Surrogate splits:
##       TreeSite                 splits as  LR-,          agree=0.859, adj=0.519, (0 split)
##       Step0.return.flow        < 82.0625  to the left,  agree=0.815, adj=0.370, (0 split)
##       step0.warmup.hrs         < 16.87402 to the right, agree=0.772, adj=0.222, (0 split)
##       step0.output.pH          < 7.296482 to the left,  agree=0.772, adj=0.222, (0 split)
##       Step6.Conductivity.start < 103.487  to the right, agree=0.761, adj=0.185, (0 split)
## 
## Node number 26: 90 observations,    complexity param=0.01704187
##   mean=63.98889, MSE=11.98437 
##   left son=52 (57 obs) right son=53 (33 obs)
##   Primary splits:
##       Step0.temperature < 9.9214   to the right, improve=0.15553330, (0 missing)
##       step0.input.pH    < 7.108064 to the left,  improve=0.11215220, (0 missing)
##       Step8.UV          < 0.7225   to the left,  improve=0.10525300, (0 missing)
##       Step0.return.flow < 79.38854 to the right, improve=0.07686055, (0 missing)
##       step0.warmup.hrs  < 17.55584 to the right, improve=0.07659861, (0 missing)
##   Surrogate splits:
##       Step3.Conductivity < 40.5     to the left,  agree=0.756, adj=0.333, (0 split)
##       step0.warmup.hrs   < 16.55238 to the right, agree=0.722, adj=0.242, (0 split)
##       Step3.compression  < 1.188815 to the left,  agree=0.700, adj=0.182, (0 split)
##       Step8.UV           < 0.71375  to the left,  agree=0.700, adj=0.182, (0 split)
##       Step0.return.flow  < 82.49074 to the left,  agree=0.700, adj=0.182, (0 split)
## 
## Node number 27: 11 observations
##   mean=68.41692, MSE=7.538337 
## 
## Node number 42: 65 observations,    complexity param=0.01316619
##   mean=59.05581, MSE=10.25407 
##   left son=84 (30 obs) right son=85 (35 obs)
##   Primary splits:
##       Step6.Conductivity.start < 105.956  to the left,  improve=0.1948986, (0 missing)
##       Step8.UV                 < 0.699    to the left,  improve=0.1553981, (0 missing)
##       Step7.symmetry           < 1.565    to the left,  improve=0.1352056, (0 missing)
##       Step5.temp               < 18.5     to the left,  improve=0.1326888, (0 missing)
##       Step3.compression        < 1.165    to the right, improve=0.1251886, (0 missing)
##   Surrogate splits:
##       Step0.tmpressure < 16.17419 to the right, agree=0.754, adj=0.467, (0 split)
##       Step1.Resin      < 13856.55 to the right, agree=0.738, adj=0.433, (0 split)
##       step0.input.pH   < 7.157158 to the left,  agree=0.723, adj=0.400, (0 split)
##       Step3.Temp       < 19.85664 to the left,  agree=0.677, adj=0.300, (0 split)
##       Step.1.pH        < 7.146774 to the right, agree=0.662, adj=0.267, (0 split)
## 
## Node number 43: 27 observations,    complexity param=0.01155538
##   mean=61.86642, MSE=15.24616 
##   left son=86 (13 obs) right son=87 (14 obs)
##   Primary splits:
##       Step5.yield       < 80.5     to the left,  improve=0.2769610, (0 missing)
##       Step0.temperature < 9.8375   to the left,  improve=0.2264512, (0 missing)
##       step0.input.pH    < 7.190474 to the left,  improve=0.2167303, (0 missing)
##       Step0.tmpressure  < 13.105   to the left,  improve=0.1908182, (0 missing)
##       Pressure          < 0.5      to the left,  improve=0.1458057, (0 missing)
##   Surrogate splits:
##       Step0.tmpressure   < 14.23011 to the left,  agree=0.778, adj=0.538, (0 split)
##       Step1.conductivity < 13.15    to the left,  agree=0.741, adj=0.462, (0 split)
##       step.1.quality.    < 90.67079 to the left,  agree=0.741, adj=0.462, (0 split)
##       step0.warmup.hrs   < 16.87402 to the left,  agree=0.704, adj=0.385, (0 split)
##       Step4.pH           < 5.565    to the left,  agree=0.667, adj=0.308, (0 split)
## 
## Node number 52: 57 observations,    complexity param=0.01704187
##   mean=62.95007, MSE=9.521646 
##   left son=104 (47 obs) right son=105 (10 obs)
##   Primary splits:
##       Step0.temperature     < 10.58523 to the left,  improve=0.3105141, (0 missing)
##       Step1.Resin           < 14444.7  to the left,  improve=0.2048429, (0 missing)
##       step0.total.particles < 1003125  to the left,  improve=0.1635155, (0 missing)
##       step.1.particles      < 2953000  to the left,  improve=0.1304884, (0 missing)
##       step0.output.pH       < 7.312019 to the left,  improve=0.1152205, (0 missing)
##   Surrogate splits:
##       Step1.Resin           < 14516.1  to the left,  agree=0.930, adj=0.6, (0 split)
##       Step8.temperature     < 18.77311 to the left,  agree=0.912, adj=0.5, (0 split)
##       step0.total.particles < 1043963  to the left,  agree=0.877, adj=0.3, (0 split)
##       Step1.conductivity    < 12.35    to the right, agree=0.860, adj=0.2, (0 split)
##       step.1.quality.       < 95.3     to the left,  agree=0.842, adj=0.1, (0 split)
## 
## Node number 53: 33 observations
##   mean=65.78321, MSE=11.15461 
## 
## Node number 84: 30 observations
##   mean=57.52886, MSE=7.226515 
## 
## Node number 85: 35 observations
##   mean=60.36463, MSE=9.137614 
## 
## Node number 86: 13 observations
##   mean=59.73395, MSE=8.770849 
## 
## Node number 87: 14 observations
##   mean=63.84656, MSE=13.11537 
## 
## Node number 104: 47 observations
##   mean=62.15693, MSE=6.5464 
## 
## Node number 105: 10 observations
##   mean=66.67781, MSE=6.652656
rpart.plot(rpartmodel2,box.palette="RdBu", shadow.col="gray", nn=TRUE)

rpart_pred = predict(rpartmodel2,resin2_test)
mean((rpart_pred-resin2_test$Final.Resin.Product)^2) #MeanSquareError
## [1] 20.49385
print(rpart_pred-resin2_test$Final.Resin.Product)
##          164          297           87          262          151           52 
##   3.33525385  -1.32107143  11.16366250  -0.56186596  -1.29554615  -0.47107143 
##          180          292          169          256          159          332 
##  -1.54731053  -1.25474615  -4.08194333   3.54252857  -6.14246596  -2.10449394 
##          163          280          108           37          320           81 
##   2.88980606  -6.15963750  -1.13544333   5.14816250   1.23045385   3.68505667 
##          136            2          255          340          316          192 
##   7.99606250  -0.53477143   3.96693404  -3.23591053  -3.23277143  -7.07897143 
##            4          202          225          106           38          116 
##  -2.60813571   6.96438947   7.60685385 -15.46564333  -0.77794333   1.14723404 
##          227          243          264          238          149          178 
##  -1.32107143  -0.86147143   8.03008947  -0.59158182   1.67945667  -3.27204615 
##           43           91          247          188          241          215 
##  -6.49716596   4.94076429   0.35273404   1.05951818  -2.61206596   4.72111000 
##          127          135          242           70           67          261 
##  -1.01074333   3.27682857   7.28695333   3.19113404   2.78395333   4.80976250 
##           20          313          146          252          337           77 
##   1.78535333   3.50336250   4.35051818  10.39751818   0.40850606  -3.64654667 
##          326           51           23          171          185          103 
##   1.02135333  -3.58344615  -6.57124667   0.67583404   1.94466250   0.16335667 
##           65          117          195          237           63           10 
##  -0.08361053  -5.17166923   0.42943404   0.57503404   8.45865333  -1.65056596 
##          147          167          274          269 
##  -0.03854333  -3.35164333   2.79806429   1.84835333
#CrossTable(resin2_test$Final.Resin.Product,rpart_pred,prop.chisq = FALSE, prop.c = FALSE, prop.r = FALSE, dnn = #c('ActualResin','PredictedResin'))
#(pdtr2 <- table(rpart_pred,resin2_test$Final.Resin.Product))
#(accuracy <- sum(diag(pdtr2))/sum(pdtr2)*100)


##Re-running random forest model with modified data
library(randomForest)
## randomForest 4.7-1
## Type rfNews() to see new features/changes/bug fixes.
random_resin2 <- randomForest(Final.Resin.Product~.,data=resin2_train,mtry = 3,importance = TRUE, na.action = na.omit)
summary(random_resin2)
##                 Length Class  Mode     
## call              6    -none- call     
## type              1    -none- character
## predicted       270    -none- numeric  
## mse             500    -none- numeric  
## rsq             500    -none- numeric  
## oob.times       270    -none- numeric  
## importance       68    -none- numeric  
## importanceSD     34    -none- numeric  
## localImportance   0    -none- NULL     
## proximity         0    -none- NULL     
## ntree             1    -none- numeric  
## mtry              1    -none- numeric  
## forest           11    -none- list     
## coefs             0    -none- NULL     
## y               270    -none- numeric  
## test              0    -none- NULL     
## inbag             0    -none- NULL     
## terms             3    terms  call
print(random_resin2)
## 
## Call:
##  randomForest(formula = Final.Resin.Product ~ ., data = resin2_train,      mtry = 3, importance = TRUE, na.action = na.omit) 
##                Type of random forest: regression
##                      Number of trees: 500
## No. of variables tried at each split: 3
## 
##           Mean of squared residuals: 15.95867
##                     % Var explained: 56.33
random_pred2 <- predict(random_resin2,resin2_test)
#(prn2<-table(random_pred2,resin2_test$Final.Resin.Product))
#(randaccuracy2 <-sum(diag(prn2))/sum(prn2)*100)
random_resin2
## 
## Call:
##  randomForest(formula = Final.Resin.Product ~ ., data = resin2_train,      mtry = 3, importance = TRUE, na.action = na.omit) 
##                Type of random forest: regression
##                      Number of trees: 500
## No. of variables tried at each split: 3
## 
##           Mean of squared residuals: 15.95867
##                     % Var explained: 56.33
importance(random_resin2)
##                            %IncMSE IncNodePurity
## TreeSite                 15.839251     729.04997
## Pressure                  2.941823     132.71770
## Step1.Temp                0.000000       0.00000
## Step1.conductivity        8.802062     324.66025
## Step1.Resin              15.848069     659.11561
## Step2.pH                  1.805252     204.46077
## Step2.Conductivity        7.727103     327.48764
## Step2.Yield               5.821304     102.53391
## Step3.Temp                4.488733     114.45172
## Step3.pH                  3.291567     172.90717
## Step3.Conductivity        2.742881      35.85039
## Step3.yield               8.866270     310.53510
## Step3.compression         9.071007     239.35637
## Step4.pH                  6.525684     260.50672
## Step5.yield              12.218167     538.91068
## Step5.temp                2.827892      59.58037
## Step6.pH.start            1.732550     166.30152
## Step6.Conductivity.start  3.076291     237.67058
## Step6.temperature         2.950301      47.95199
## Step7.symmetry           11.855867     403.42573
## Step8.temperature         4.289990     101.74009
## step.8.yield              3.912101     163.60147
## Step7.UV                  1.111764     213.33184
## Step8.UV                  1.574684     241.29533
## Step.1.pH                 9.077051     324.22097
## step.1.particles          4.844773     235.04789
## step.1.quality.          10.197762     481.53981
## step0.total.particles     4.998940     228.43611
## step0.warmup.hrs          4.767805     125.40080
## step0.input.pH           14.116110     438.50199
## step0.output.pH           8.968009     469.60789
## Step0.tmpressure         10.850799     554.11512
## Step0.return.flow         5.527307     172.19363
## Step0.temperature         9.432181     420.23620
order(importance(random_resin2))
##  [1]  3 37 23 24 17  6 11 16  2 19 18 10 22 21  9 29 26 28 33  8 14  7  4 12 31
## [26] 13 25 34 27 32 20 15 30  1  5 45 53 50 55 42 43 63 36 56 51 67 44 40 57 62
## [51] 60 52 47 58 48 46 59 38 41 54 68 64 65 61 49 66 39 35
##Mean Square Error of RandomForesModel
mean((random_pred2-resin2_test$Final.Resin.Product)^2)  #MeanSquareError
## [1] 14.35697
#importance(random_resin2)[order(importance(random_resin2)),]

##Selected features from Random forest model results: Model3 step.1.particles step0.total.particles Step.1.pH Step8.UV

      Step7.symmetry,Step6.Conductivity.start,Step0.tmpressure,Step0.temperature,step0.input.pH,step.1.quality., Step5.yield,step0.output.pH,TreeSite,Final.Resin.Product 
        

Creating new dataset according to features identified from Random Forest

##     step0.input.pH Step0.tmpressure Step7.symmetry Step0.temperature
## 14             7.2         13.83333           1.64          9.555556
## 32             7.2         15.58065           1.61         10.096774
## 196            7.1         14.41379           1.41         10.344828
## 83             7.1         17.41250           1.41         10.117944
## 119            7.2         14.78788           1.87         10.060606
## 300            7.1         15.86667           1.65         10.117944
##     step0.output.pH step.1.quality. Step5.yield Step1.Resin        TreeSite
## 14         7.340000        94.24722          80     13158.6 Village Harvest
## 32         7.309677        98.20000          82     12482.8 Village Harvest
## 196        7.296154        95.10000          82     12785.4 Village Harvest
## 83         7.296875        94.60000          79     14099.5    City Harvest
## 119        7.318182        95.10000          84     12563.1 Village Harvest
## 300        7.248148        88.50000          81     13577.2    City Harvest
##     Final.Resin.Product
## 14              59.2894
## 32              70.9784
## 196             61.0340
## 83              56.3344
## 119             67.9357
## 300             59.6207
## 'data.frame':    270 obs. of  10 variables:
##  $ step0.input.pH     : num  7.2 7.2 7.1 7.1 7.2 ...
##  $ Step0.tmpressure   : num  13.8 15.6 14.4 17.4 14.8 ...
##  $ Step7.symmetry     : num  1.64 1.61 1.41 1.41 1.87 1.65 1.87 1.06 1.8 1.75 ...
##  $ Step0.temperature  : num  9.56 10.1 10.34 10.12 10.06 ...
##  $ step0.output.pH    : num  7.34 7.31 7.3 7.3 7.32 ...
##  $ step.1.quality.    : num  94.2 98.2 95.1 94.6 95.1 ...
##  $ Step5.yield        : num  80 82 82 79 84 81 82 79 87 82 ...
##  $ Step1.Resin        : num  13159 12483 12785 14100 12563 ...
##  $ TreeSite           : Factor w/ 3 levels "City Harvest",..: 3 3 3 1 3 1 1 1 3 3 ...
##  $ Final.Resin.Product: num  59.3 71 61 56.3 67.9 ...
##     step0.input.pH Step0.tmpressure Step7.symmetry Step0.temperature
## 14             7.2         13.83333           1.64          9.555556
## 32             7.2         15.58065           1.61         10.096774
## 196            7.1         14.41379           1.41         10.344828
## 83             7.1         17.41250           1.41         10.117944
## 119            7.2         14.78788           1.87         10.060606
## 300            7.1         15.86667           1.65         10.117944
##     step0.output.pH step.1.quality. Step5.yield Step1.Resin        TreeSite
## 14         7.340000        94.24722          80     13158.6 Village Harvest
## 32         7.309677        98.20000          82     12482.8 Village Harvest
## 196        7.296154        95.10000          82     12785.4 Village Harvest
## 83         7.296875        94.60000          79     14099.5    City Harvest
## 119        7.318182        95.10000          84     12563.1 Village Harvest
## 300        7.248148        88.50000          81     13577.2    City Harvest
##     Final.Resin.Product
## 14              59.2894
## 32              70.9784
## 196             61.0340
## 83              56.3344
## 119             67.9357
## 300             59.6207
## 'data.frame':    270 obs. of  10 variables:
##  $ step0.input.pH     : num  7.2 7.2 7.1 7.1 7.2 ...
##  $ Step0.tmpressure   : num  13.8 15.6 14.4 17.4 14.8 ...
##  $ Step7.symmetry     : num  1.64 1.61 1.41 1.41 1.87 1.65 1.87 1.06 1.8 1.75 ...
##  $ Step0.temperature  : num  9.56 10.1 10.34 10.12 10.06 ...
##  $ step0.output.pH    : num  7.34 7.31 7.3 7.3 7.32 ...
##  $ step.1.quality.    : num  94.2 98.2 95.1 94.6 95.1 ...
##  $ Step5.yield        : num  80 82 82 79 84 81 82 79 87 82 ...
##  $ Step1.Resin        : num  13159 12483 12785 14100 12563 ...
##  $ TreeSite           : Factor w/ 3 levels "City Harvest",..: 3 3 3 1 3 1 1 1 3 3 ...
##  $ Final.Resin.Product: num  59.3 71 61 56.3 67.9 ...

## n= 270 
## 
## node), split, n, deviance, yval
##       * denotes terminal node
## 
##   1) root 270 9866.39400 60.86954  
##     2) TreeSite=City Harvest,Mix Harvest 154 4644.45900 58.10373  
##       4) Step1.Resin< 12808.5 35 1011.28600 52.95318  
##         8) step.1.quality.< 90.06 13  411.95780 49.41813 *
##         9) step.1.quality.>=90.06 22  340.87670 55.04207  
##          18) Step0.tmpressure< 12.13498 7   28.16753 51.23340 *
##          19) Step0.tmpressure>=12.13498 15  163.78110 56.81945 *
##       5) Step1.Resin>=12808.5 119 2431.60100 59.61860  
##        10) Step5.yield< 82.5 111 1859.19600 59.14576  
##          20) step.1.quality.< 88.045 19  340.06380 55.58729 *
##          21) step.1.quality.>=88.045 92 1228.85300 59.88066  
##            42) Step0.temperature>=10.03571 65  666.51480 59.05581 *
##            43) Step0.temperature< 10.03571 27  411.64620 61.86642  
##              86) Step5.yield< 80.5 13  114.02100 59.73395 *
##              87) Step5.yield>=80.5 14  183.61520 63.84656 *
##        11) Step5.yield>=82.5 8  203.25030 66.17926 *
##     3) TreeSite=Village Harvest 116 2479.91700 64.54139  
##       6) Step7.symmetry>=1.09 108 1856.61700 63.95689  
##        12) Step1.Resin< 11697.75 7   90.80923 56.53693 *
##        13) Step1.Resin>=11697.75 101 1353.70700 64.47115  
##          26) Step0.tmpressure< 15.28579 90 1078.59300 63.98889  
##            52) Step0.temperature>=9.921399 57  542.73380 62.95007  
##             104) Step0.temperature< 10.58523 47  307.68080 62.15693 *
##             105) Step0.temperature>=10.58523 10   66.52656 66.67781 *
##            53) Step0.temperature< 9.921399 33  368.10200 65.78321 *
##          27) Step0.tmpressure>=15.28579 11   82.92171 68.41692 *
##       7) Step7.symmetry< 1.09 8   88.30152 72.43206 *
## Call:
## rpart(formula = Final.Resin.Product ~ ., data = feature_train)
##   n= 270 
## 
##            CP nsplit rel error    xerror       xstd
## 1  0.27791485      0 1.0000000 1.0058589 0.10462217
## 2  0.12178424      1 0.7220851 0.7385326 0.08304573
## 3  0.05422432      2 0.6003009 0.6487828 0.06727510
## 4  0.04176818      3 0.5460766 0.6395846 0.06685824
## 5  0.03741543      4 0.5043084 0.6107288 0.06292990
## 6  0.02942100      5 0.4668930 0.6200828 0.06255112
## 7  0.02619517      6 0.4374720 0.6069110 0.05978801
## 8  0.01947945      7 0.4112768 0.5936252 0.05863276
## 9  0.01704187      8 0.3917974 0.5948290 0.06215735
## 10 0.01527325     10 0.3577136 0.5824567 0.06135640
## 11 0.01509449     11 0.3424404 0.5719935 0.06101048
## 12 0.01155538     12 0.3273459 0.5627259 0.06389189
## 13 0.01000000     13 0.3157905 0.5690636 0.06361042
## 
## Variable importance
##          TreeSite   step0.output.pH       Step1.Resin Step0.temperature 
##                22                16                14                13 
##   step.1.quality.       Step5.yield  Step0.tmpressure    Step7.symmetry 
##                12                10                 5                 5 
##    step0.input.pH 
##                 4 
## 
## Node number 1: 270 observations,    complexity param=0.2779149
##   mean=60.86954, MSE=36.5422 
##   left son=2 (154 obs) right son=3 (116 obs)
##   Primary splits:
##       TreeSite          splits as  LLR,          improve=0.2779149, (0 missing)
##       Step0.temperature < 10.11453 to the right, improve=0.1623813, (0 missing)
##       Step1.Resin       < 12480.5  to the left,  improve=0.1602819, (0 missing)
##       step0.output.pH   < 7.289643 to the left,  improve=0.1521203, (0 missing)
##       Step5.yield       < 80.39818 to the left,  improve=0.1402625, (0 missing)
##   Surrogate splits:
##       step0.output.pH   < 7.298438 to the left,  agree=0.881, adj=0.724, (0 split)
##       Step0.temperature < 10.10913 to the right, agree=0.752, adj=0.422, (0 split)
##       step.1.quality.   < 93.36066 to the left,  agree=0.711, adj=0.328, (0 split)
##       Step5.yield       < 81.5     to the left,  agree=0.681, adj=0.259, (0 split)
##       step0.input.pH    < 7.19853  to the left,  agree=0.641, adj=0.164, (0 split)
## 
## Node number 2: 154 observations,    complexity param=0.1217842
##   mean=58.10373, MSE=30.15883 
##   left son=4 (35 obs) right son=5 (119 obs)
##   Primary splits:
##       Step1.Resin       < 12808.5  to the left,  improve=0.2587107, (0 missing)
##       step.1.quality.   < 87.88226 to the left,  improve=0.1397313, (0 missing)
##       Step0.temperature < 10.11453 to the right, improve=0.1038099, (0 missing)
##       Step0.tmpressure  < 11.30958 to the left,  improve=0.1000074, (0 missing)
##       TreeSite          splits as  LR-,          improve=0.0963883, (0 missing)
##   Surrogate splits:
##       Step0.tmpressure < 11.22096 to the left,  agree=0.812, adj=0.171, (0 split)
##       Step5.yield      < 77.5     to the left,  agree=0.779, adj=0.029, (0 split)
## 
## Node number 3: 116 observations,    complexity param=0.05422432
##   mean=64.54139, MSE=21.3786 
##   left son=6 (108 obs) right son=7 (8 obs)
##   Primary splits:
##       Step7.symmetry    < 1.09     to the right, improve=0.21573240, (0 missing)
##       Step1.Resin       < 12016.95 to the left,  improve=0.19251420, (0 missing)
##       step0.input.pH    < 7.109916 to the left,  improve=0.18565760, (0 missing)
##       Step0.tmpressure  < 15.28579 to the left,  improve=0.13400510, (0 missing)
##       Step0.temperature < 9.812317 to the right, improve=0.09473891, (0 missing)
## 
## Node number 4: 35 observations,    complexity param=0.02619517
##   mean=52.95318, MSE=28.8939 
##   left son=8 (13 obs) right son=9 (22 obs)
##   Primary splits:
##       step.1.quality.  < 90.06    to the left,  improve=0.25556740, (0 missing)
##       Step5.yield      < 80.5     to the left,  improve=0.23845270, (0 missing)
##       Step0.tmpressure < 11.69608 to the left,  improve=0.15178610, (0 missing)
##       Step7.symmetry   < 1.645    to the left,  improve=0.09573133, (0 missing)
##       Step1.Resin      < 12326.45 to the left,  improve=0.06146094, (0 missing)
##   Surrogate splits:
##       Step5.yield      < 78.5     to the left,  agree=0.743, adj=0.308, (0 split)
##       Step0.tmpressure < 11.69608 to the left,  agree=0.714, adj=0.231, (0 split)
##       Step7.symmetry   < 1.8      to the right, agree=0.686, adj=0.154, (0 split)
##       Step1.Resin      < 11795.55 to the left,  agree=0.686, adj=0.154, (0 split)
##       step0.output.pH  < 7.257216 to the right, agree=0.657, adj=0.077, (0 split)
## 
## Node number 5: 119 observations,    complexity param=0.03741543
##   mean=59.6186, MSE=20.43363 
##   left son=10 (111 obs) right son=11 (8 obs)
##   Primary splits:
##       Step5.yield       < 82.5     to the left,  improve=0.15181570, (0 missing)
##       step.1.quality.   < 88.11333 to the left,  improve=0.13551610, (0 missing)
##       step0.input.pH    < 7.148436 to the left,  improve=0.09762502, (0 missing)
##       Step0.temperature < 10.11453 to the right, improve=0.07675249, (0 missing)
##       Step7.symmetry    < 1.525    to the left,  improve=0.07043341, (0 missing)
## 
## Node number 6: 108 observations,    complexity param=0.04176818
##   mean=63.95689, MSE=17.1909 
##   left son=12 (7 obs) right son=13 (101 obs)
##   Primary splits:
##       Step1.Resin      < 11697.75 to the left,  improve=0.22196350, (0 missing)
##       step0.input.pH   < 7.109916 to the left,  improve=0.19551480, (0 missing)
##       Step5.yield      < 83.5     to the left,  improve=0.09623668, (0 missing)
##       Step0.tmpressure < 15.28579 to the left,  improve=0.08981585, (0 missing)
##       step.1.quality.  < 87.775   to the left,  improve=0.07204267, (0 missing)
## 
## Node number 7: 8 observations
##   mean=72.43206, MSE=11.03769 
## 
## Node number 8: 13 observations
##   mean=49.41813, MSE=31.68906 
## 
## Node number 9: 22 observations,    complexity param=0.01509449
##   mean=55.04207, MSE=15.4944 
##   left son=18 (7 obs) right son=19 (15 obs)
##   Primary splits:
##       Step0.tmpressure < 12.13498 to the left,  improve=0.4368973, (0 missing)
##       Step1.Resin      < 12309.65 to the left,  improve=0.4230592, (0 missing)
##       Step5.yield      < 80.5     to the left,  improve=0.3781286, (0 missing)
##       step.1.quality.  < 93.00179 to the left,  improve=0.3153516, (0 missing)
##       step0.output.pH  < 7.254509 to the left,  improve=0.1701276, (0 missing)
##   Surrogate splits:
##       step0.input.pH < 7.203334 to the right, agree=0.864, adj=0.571, (0 split)
##       Step7.symmetry < 1.465    to the left,  agree=0.727, adj=0.143, (0 split)
## 
## Node number 10: 111 observations,    complexity param=0.029421
##   mean=59.14576, MSE=16.74951 
##   left son=20 (19 obs) right son=21 (92 obs)
##   Primary splits:
##       step.1.quality.   < 88.045   to the left,  improve=0.15613160, (0 missing)
##       Step0.temperature < 10.03571 to the right, improve=0.14071740, (0 missing)
##       Step0.tmpressure  < 15.9099  to the right, improve=0.08834975, (0 missing)
##       step0.input.pH    < 7.148436 to the left,  improve=0.08538924, (0 missing)
##       Step7.symmetry    < 1.565    to the left,  improve=0.08225724, (0 missing)
## 
## Node number 11: 8 observations
##   mean=66.17926, MSE=25.40629 
## 
## Node number 12: 7 observations
##   mean=56.53693, MSE=12.97275 
## 
## Node number 13: 101 observations,    complexity param=0.01947945
##   mean=64.47115, MSE=13.40304 
##   left son=26 (90 obs) right son=27 (11 obs)
##   Primary splits:
##       Step0.tmpressure  < 15.28579 to the left,  improve=0.14197460, (0 missing)
##       step0.input.pH    < 7.108064 to the left,  improve=0.11890590, (0 missing)
##       Step5.yield       < 83.5     to the left,  improve=0.09538495, (0 missing)
##       Step0.temperature < 9.9214   to the right, improve=0.07340118, (0 missing)
##       step.1.quality.   < 87.66184 to the left,  improve=0.06799471, (0 missing)
## 
## Node number 18: 7 observations
##   mean=51.2334, MSE=4.023933 
## 
## Node number 19: 15 observations
##   mean=56.81945, MSE=10.91874 
## 
## Node number 20: 19 observations
##   mean=55.58729, MSE=17.89809 
## 
## Node number 21: 92 observations,    complexity param=0.01527325
##   mean=59.88066, MSE=13.3571 
##   left son=42 (65 obs) right son=43 (27 obs)
##   Primary splits:
##       Step0.temperature < 10.03571 to the right, improve=0.12262810, (0 missing)
##       Step7.symmetry    < 1.565    to the left,  improve=0.11603610, (0 missing)
##       TreeSite          splits as  LR-,          improve=0.08158899, (0 missing)
##       step0.input.pH    < 7.117524 to the left,  improve=0.07876424, (0 missing)
##       Step5.yield       < 80.89818 to the left,  improve=0.05826906, (0 missing)
##   Surrogate splits:
##       TreeSite        splits as  LR-,          agree=0.859, adj=0.519, (0 split)
##       step0.output.pH < 7.296482 to the left,  agree=0.772, adj=0.222, (0 split)
##       Step1.Resin     < 14608.75 to the left,  agree=0.750, adj=0.148, (0 split)
##       step.1.quality. < 88.38182 to the right, agree=0.717, adj=0.037, (0 split)
## 
## Node number 26: 90 observations,    complexity param=0.01704187
##   mean=63.98889, MSE=11.98437 
##   left son=52 (57 obs) right son=53 (33 obs)
##   Primary splits:
##       Step0.temperature < 9.9214   to the right, improve=0.15553330, (0 missing)
##       step0.input.pH    < 7.108064 to the left,  improve=0.11215220, (0 missing)
##       Step1.Resin       < 14924.45 to the left,  improve=0.06918046, (0 missing)
##       step.1.quality.   < 87.7208  to the left,  improve=0.06258108, (0 missing)
##       Step7.symmetry    < 5.77     to the right, improve=0.05956377, (0 missing)
##   Surrogate splits:
##       Step0.tmpressure < 13.14263 to the right, agree=0.678, adj=0.121, (0 split)
##       step0.output.pH  < 7.326111 to the left,  agree=0.667, adj=0.091, (0 split)
##       Step7.symmetry   < 1.16     to the right, agree=0.656, adj=0.061, (0 split)
##       Step5.yield      < 77.5     to the right, agree=0.656, adj=0.061, (0 split)
##       Step1.Resin      < 12782.95 to the right, agree=0.656, adj=0.061, (0 split)
## 
## Node number 27: 11 observations
##   mean=68.41692, MSE=7.538337 
## 
## Node number 42: 65 observations
##   mean=59.05581, MSE=10.25407 
## 
## Node number 43: 27 observations,    complexity param=0.01155538
##   mean=61.86642, MSE=15.24616 
##   left son=86 (13 obs) right son=87 (14 obs)
##   Primary splits:
##       Step5.yield       < 80.5     to the left,  improve=0.27696100, (0 missing)
##       Step0.temperature < 9.8375   to the left,  improve=0.22645120, (0 missing)
##       step0.input.pH    < 7.190474 to the left,  improve=0.21673030, (0 missing)
##       Step0.tmpressure  < 13.105   to the left,  improve=0.19081820, (0 missing)
##       Step7.symmetry    < 1.565    to the left,  improve=0.08982249, (0 missing)
##   Surrogate splits:
##       Step0.tmpressure  < 14.23011 to the left,  agree=0.778, adj=0.538, (0 split)
##       step.1.quality.   < 90.67079 to the left,  agree=0.741, adj=0.462, (0 split)
##       Step7.symmetry    < 1.63     to the left,  agree=0.667, adj=0.308, (0 split)
##       step0.input.pH    < 7.190474 to the left,  agree=0.630, adj=0.231, (0 split)
##       Step0.temperature < 9.602564 to the left,  agree=0.630, adj=0.231, (0 split)
## 
## Node number 52: 57 observations,    complexity param=0.01704187
##   mean=62.95007, MSE=9.521646 
##   left son=104 (47 obs) right son=105 (10 obs)
##   Primary splits:
##       Step0.temperature < 10.58523 to the left,  improve=0.31051410, (0 missing)
##       Step1.Resin       < 14444.7  to the left,  improve=0.20484290, (0 missing)
##       step0.output.pH   < 7.312019 to the left,  improve=0.11522050, (0 missing)
##       step0.input.pH    < 7.108064 to the left,  improve=0.10291350, (0 missing)
##       Step5.yield       < 82.5     to the left,  improve=0.08845772, (0 missing)
##   Surrogate splits:
##       Step1.Resin     < 14516.1  to the left,  agree=0.930, adj=0.6, (0 split)
##       step.1.quality. < 95.3     to the left,  agree=0.842, adj=0.1, (0 split)
## 
## Node number 53: 33 observations
##   mean=65.78321, MSE=11.15461 
## 
## Node number 86: 13 observations
##   mean=59.73395, MSE=8.770849 
## 
## Node number 87: 14 observations
##   mean=63.84656, MSE=13.11537 
## 
## Node number 104: 47 observations
##   mean=62.15693, MSE=6.5464 
## 
## Node number 105: 10 observations
##   mean=66.67781, MSE=6.652656

## [1] 20.07133
##                 Length Class  Mode     
## call              3    -none- call     
## type              1    -none- character
## predicted       270    -none- numeric  
## mse             500    -none- numeric  
## rsq             500    -none- numeric  
## oob.times       270    -none- numeric  
## importance        9    -none- numeric  
## importanceSD      0    -none- NULL     
## localImportance   0    -none- NULL     
## proximity         0    -none- NULL     
## ntree             1    -none- numeric  
## mtry              1    -none- numeric  
## forest           11    -none- list     
## coefs             0    -none- NULL     
## y               270    -none- numeric  
## test              0    -none- NULL     
## inbag             0    -none- NULL     
## terms             3    terms  call
## 
## Call:
##  randomForest(formula = Final.Resin.Product ~ ., data = feature_train) 
##                Type of random forest: regression
##                      Number of trees: 500
## No. of variables tried at each split: 3
## 
##           Mean of squared residuals: 12.9876
##                     % Var explained: 64.46
##                   IncNodePurity
## step0.input.pH         685.5047
## Step0.tmpressure       908.2940
## Step7.symmetry         885.3149
## Step0.temperature      769.2187
## step0.output.pH        801.3864
## step.1.quality.        985.5914
## Step5.yield           1064.8589
## Step1.Resin           1651.1822
## TreeSite              1617.2818
## [1] 14.08814

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.