tee <- c(1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 6, 7, 7, 7, 7) #setting up the data
at1 <- c(1, 1, 1, 2, 2, 3, 4, 5, 5)
at2 <- c(6, 6, 7, 7, 7, 7)
bt1 <- c(1, 1, 1, 2, 2, 3, 4)
bt2 <- c(5, 5, 6, 6, 7, 7, 7, 7)
sdr_a <- sd(tee) - (length(at1) / length(tee) * sd(at1) + length(at2) / length(tee) * sd(at2)) #finding the sdr
sdr_b <- sd(tee) - (length(bt1) / length(tee) * sd(bt1) + length(bt2) / length(tee) * sd(bt2))
sdr_a
## [1] 1.202815
sdr_b
## [1] 1.392751
#sdr b is higher than sdr a
wine <- read.csv("whitewines.csv")
str(wine) #shows caracterisitcs of csv
## 'data.frame': 4898 obs. of 12 variables:
## $ fixed.acidity : num 6.7 5.7 5.9 5.3 6.4 7 7.9 6.6 7 6.5 ...
## $ volatile.acidity : num 0.62 0.22 0.19 0.47 0.29 0.14 0.12 0.38 0.16 0.37 ...
## $ citric.acid : num 0.24 0.2 0.26 0.1 0.21 0.41 0.49 0.28 0.3 0.33 ...
## $ residual.sugar : num 1.1 16 7.4 1.3 9.65 0.9 5.2 2.8 2.6 3.9 ...
## $ chlorides : num 0.039 0.044 0.034 0.036 0.041 0.037 0.049 0.043 0.043 0.027 ...
## $ free.sulfur.dioxide : num 6 41 33 11 36 22 33 17 34 40 ...
## $ total.sulfur.dioxide: num 62 113 123 74 119 95 152 67 90 130 ...
## $ density : num 0.993 0.999 0.995 0.991 0.993 ...
## $ pH : num 3.41 3.22 3.49 3.48 2.99 3.25 3.18 3.21 2.88 3.28 ...
## $ sulphates : num 0.32 0.46 0.42 0.54 0.34 0.43 0.47 0.47 0.47 0.39 ...
## $ alcohol : num 10.4 8.9 10.1 11.2 10.9 ...
## $ quality : int 5 6 6 4 6 6 6 6 6 7 ...
hist(wine$quality) #makes a histogram of the wine quality ratings, which shows most between 4.5 and 7

summary(wine) #summary stats of the different features of the csv
## fixed.acidity volatile.acidity citric.acid residual.sugar
## Min. : 3.800 Min. :0.0800 Min. :0.0000 Min. : 0.600
## 1st Qu.: 6.300 1st Qu.:0.2100 1st Qu.:0.2700 1st Qu.: 1.700
## Median : 6.800 Median :0.2600 Median :0.3200 Median : 5.200
## Mean : 6.855 Mean :0.2782 Mean :0.3342 Mean : 6.391
## 3rd Qu.: 7.300 3rd Qu.:0.3200 3rd Qu.:0.3900 3rd Qu.: 9.900
## Max. :14.200 Max. :1.1000 Max. :1.6600 Max. :65.800
## chlorides free.sulfur.dioxide total.sulfur.dioxide density
## Min. :0.00900 Min. : 2.00 Min. : 9.0 Min. :0.9871
## 1st Qu.:0.03600 1st Qu.: 23.00 1st Qu.:108.0 1st Qu.:0.9917
## Median :0.04300 Median : 34.00 Median :134.0 Median :0.9937
## Mean :0.04577 Mean : 35.31 Mean :138.4 Mean :0.9940
## 3rd Qu.:0.05000 3rd Qu.: 46.00 3rd Qu.:167.0 3rd Qu.:0.9961
## Max. :0.34600 Max. :289.00 Max. :440.0 Max. :1.0390
## pH sulphates alcohol quality
## Min. :2.720 Min. :0.2200 Min. : 8.00 Min. :3.000
## 1st Qu.:3.090 1st Qu.:0.4100 1st Qu.: 9.50 1st Qu.:5.000
## Median :3.180 Median :0.4700 Median :10.40 Median :6.000
## Mean :3.188 Mean :0.4898 Mean :10.51 Mean :5.878
## 3rd Qu.:3.280 3rd Qu.:0.5500 3rd Qu.:11.40 3rd Qu.:6.000
## Max. :3.820 Max. :1.0800 Max. :14.20 Max. :9.000
wine_train <- wine[1:3750, ]
wine_test <- wine[3751:4898, ] #making two subsets
library(rpart)
m.rpart <- rpart(quality ~ ., data = wine_test) #makes a regression tree
m.rpart #shows details of the regression tree, such as the different splits
## n= 1148
##
## node), split, n, deviance, yval
## * denotes terminal node
##
## 1) root 1148 894.679400 5.900697
## 2) alcohol< 10.85 713 426.042100 5.607293
## 4) volatile.acidity>=0.2725 306 123.558800 5.264706
## 8) free.sulfur.dioxide< 9.5 12 2.666667 4.333333 *
## 9) free.sulfur.dioxide>=9.5 294 110.057800 5.302721 *
## 5) volatile.acidity< 0.2725 407 239.567600 5.864865
## 10) alcohol< 10.45 331 182.616300 5.791541
## 20) volatile.acidity>=0.205 193 88.082900 5.678756 *
## 21) volatile.acidity< 0.205 138 88.644930 5.949275
## 42) residual.sugar< 12.65 107 54.056070 5.785047 *
## 43) residual.sugar>=12.65 31 21.741940 6.516129 *
## 11) alcohol>=10.45 76 47.421050 6.184211 *
## 3) alcohol>=10.85 435 306.652900 6.381609
## 6) alcohol< 12.55 362 228.618800 6.254144
## 12) free.sulfur.dioxide< 19.5 76 72.776320 5.828947
## 24) density>=0.990965 47 37.744680 5.489362 *
## 25) density< 0.990965 29 20.827590 6.379310 *
## 13) free.sulfur.dioxide>=19.5 286 138.451000 6.367133 *
## 7) alcohol>=12.55 73 42.986300 7.013699 *
summary(m.rpart) #all the MSEs are under 1 in the summary
## Call:
## rpart(formula = quality ~ ., data = wine_test)
## n= 1148
##
## CP nsplit rel error xerror xstd
## 1 0.18105311 0 1.0000000 1.0017559 0.04304132
## 2 0.07032204 1 0.8189469 0.8349555 0.03934502
## 3 0.03917357 2 0.7486249 0.7747862 0.03801440
## 4 0.01943872 3 0.7094513 0.7375962 0.03611179
## 5 0.01587613 4 0.6900126 0.7337545 0.03593710
## 6 0.01210974 5 0.6741364 0.7386114 0.03600826
## 7 0.01065208 6 0.6620267 0.7356331 0.03585737
## 8 0.01047046 7 0.6513746 0.7360867 0.03586509
## 9 0.01000000 9 0.6304337 0.7385574 0.03613709
##
## Variable importance
## alcohol density volatile.acidity
## 34 21 11
## chlorides total.sulfur.dioxide residual.sugar
## 10 8 6
## free.sulfur.dioxide citric.acid sulphates
## 5 2 1
## fixed.acidity
## 1
##
## Node number 1: 1148 observations, complexity param=0.1810531
## mean=5.900697, MSE=0.7793375
## left son=2 (713 obs) right son=3 (435 obs)
## Primary splits:
## alcohol < 10.85 to the left, improve=0.18105310, (0 missing)
## density < 0.99149 to the right, improve=0.13767860, (0 missing)
## chlorides < 0.0375 to the right, improve=0.08459645, (0 missing)
## total.sulfur.dioxide < 153.5 to the right, improve=0.06179834, (0 missing)
## free.sulfur.dioxide < 11.75 to the left, improve=0.05120902, (0 missing)
## Surrogate splits:
## density < 0.99203 to the right, agree=0.856, adj=0.621, (0 split)
## chlorides < 0.0345 to the right, agree=0.750, adj=0.340, (0 split)
## total.sulfur.dioxide < 115.5 to the right, agree=0.709, adj=0.232, (0 split)
## residual.sugar < 4.65 to the right, agree=0.671, adj=0.131, (0 split)
## sulphates < 0.355 to the right, agree=0.639, adj=0.046, (0 split)
##
## Node number 2: 713 observations, complexity param=0.07032204
## mean=5.607293, MSE=0.5975345
## left son=4 (306 obs) right son=5 (407 obs)
## Primary splits:
## volatile.acidity < 0.2725 to the right, improve=0.14767480, (0 missing)
## free.sulfur.dioxide < 15.5 to the left, improve=0.06507032, (0 missing)
## alcohol < 10.25 to the left, improve=0.03470171, (0 missing)
## citric.acid < 0.235 to the left, improve=0.03119571, (0 missing)
## total.sulfur.dioxide < 70.5 to the left, improve=0.02682670, (0 missing)
## Surrogate splits:
## citric.acid < 0.245 to the left, agree=0.661, adj=0.209, (0 split)
## free.sulfur.dioxide < 16.5 to the left, agree=0.606, adj=0.082, (0 split)
## total.sulfur.dioxide < 173.5 to the right, agree=0.599, adj=0.065, (0 split)
## chlorides < 0.0645 to the right, agree=0.592, adj=0.049, (0 split)
## alcohol < 8.75 to the left, agree=0.581, adj=0.023, (0 split)
##
## Node number 3: 435 observations, complexity param=0.03917357
## mean=6.381609, MSE=0.7049491
## left son=6 (362 obs) right son=7 (73 obs)
## Primary splits:
## alcohol < 12.55 to the left, improve=0.11429140, (0 missing)
## free.sulfur.dioxide < 18.5 to the left, improve=0.08527668, (0 missing)
## density < 0.991225 to the right, improve=0.05019639, (0 missing)
## fixed.acidity < 7.85 to the right, improve=0.04226104, (0 missing)
## pH < 3.295 to the left, improve=0.03641235, (0 missing)
## Surrogate splits:
## density < 0.989605 to the right, agree=0.867, adj=0.205, (0 split)
## sulphates < 0.275 to the right, agree=0.841, adj=0.055, (0 split)
## volatile.acidity < 0.445 to the left, agree=0.837, adj=0.027, (0 split)
## chlorides < 0.0165 to the right, agree=0.834, adj=0.014, (0 split)
##
## Node number 4: 306 observations, complexity param=0.01210974
## mean=5.264706, MSE=0.403787
## left son=8 (12 obs) right son=9 (294 obs)
## Primary splits:
## free.sulfur.dioxide < 9.5 to the left, improve=0.08768563, (0 missing)
## total.sulfur.dioxide < 62 to the left, improve=0.07296979, (0 missing)
## volatile.acidity < 0.5 to the right, improve=0.05682467, (0 missing)
## chlorides < 0.0315 to the right, improve=0.05376385, (0 missing)
## sulphates < 0.345 to the left, improve=0.04549337, (0 missing)
## Surrogate splits:
## total.sulfur.dioxide < 43.5 to the left, agree=0.964, adj=0.083, (0 split)
##
## Node number 5: 407 observations, complexity param=0.01065208
## mean=5.864865, MSE=0.5886181
## left son=10 (331 obs) right son=11 (76 obs)
## Primary splits:
## alcohol < 10.45 to the left, improve=0.03978085, (0 missing)
## sulphates < 0.455 to the left, improve=0.03585709, (0 missing)
## free.sulfur.dioxide < 15.5 to the left, improve=0.02901346, (0 missing)
## density < 0.99398 to the right, improve=0.02676942, (0 missing)
## volatile.acidity < 0.235 to the right, improve=0.02572039, (0 missing)
## Surrogate splits:
## density < 0.99191 to the right, agree=0.830, adj=0.092, (0 split)
## chlorides < 0.0295 to the right, agree=0.828, adj=0.079, (0 split)
## residual.sugar < 1.05 to the right, agree=0.821, adj=0.039, (0 split)
##
## Node number 6: 362 observations, complexity param=0.01943872
## mean=6.254144, MSE=0.6315436
## left son=12 (76 obs) right son=13 (286 obs)
## Primary splits:
## free.sulfur.dioxide < 19.5 to the left, improve=0.07607170, (0 missing)
## pH < 3.245 to the left, improve=0.05133231, (0 missing)
## fixed.acidity < 7.85 to the right, improve=0.04515774, (0 missing)
## volatile.acidity < 0.4825 to the right, improve=0.03608071, (0 missing)
## sulphates < 0.585 to the left, improve=0.03409050, (0 missing)
## Surrogate splits:
## total.sulfur.dioxide < 77 to the left, agree=0.840, adj=0.237, (0 split)
## volatile.acidity < 0.4825 to the right, agree=0.801, adj=0.053, (0 split)
## fixed.acidity < 8.15 to the right, agree=0.793, adj=0.013, (0 split)
##
## Node number 7: 73 observations
## mean=7.013699, MSE=0.5888534
##
## Node number 8: 12 observations
## mean=4.333333, MSE=0.2222222
##
## Node number 9: 294 observations
## mean=5.302721, MSE=0.3743463
##
## Node number 10: 331 observations, complexity param=0.01047046
## mean=5.791541, MSE=0.5517109
## left son=20 (193 obs) right son=21 (138 obs)
## Primary splits:
## volatile.acidity < 0.205 to the right, improve=0.03224512, (0 missing)
## residual.sugar < 12.65 to the left, improve=0.03170606, (0 missing)
## fixed.acidity < 6.25 to the left, improve=0.02999807, (0 missing)
## sulphates < 0.455 to the left, improve=0.02937037, (0 missing)
## free.sulfur.dioxide < 14.5 to the left, improve=0.02428061, (0 missing)
## Surrogate splits:
## residual.sugar < 6.45 to the right, agree=0.668, adj=0.203, (0 split)
## density < 0.99471 to the right, agree=0.650, adj=0.159, (0 split)
## total.sulfur.dioxide < 127.5 to the right, agree=0.644, adj=0.145, (0 split)
## free.sulfur.dioxide < 26.5 to the right, agree=0.637, adj=0.130, (0 split)
## pH < 3.265 to the left, agree=0.622, adj=0.094, (0 split)
##
## Node number 11: 76 observations
## mean=6.184211, MSE=0.6239612
##
## Node number 12: 76 observations, complexity param=0.01587613
## mean=5.828947, MSE=0.9575831
## left son=24 (47 obs) right son=25 (29 obs)
## Primary splits:
## density < 0.990965 to the right, improve=0.19517410, (0 missing)
## fixed.acidity < 6.65 to the right, improve=0.15112130, (0 missing)
## volatile.acidity < 0.1575 to the right, improve=0.13443480, (0 missing)
## sulphates < 0.335 to the left, improve=0.13163110, (0 missing)
## pH < 3.245 to the left, improve=0.08899868, (0 missing)
## Surrogate splits:
## fixed.acidity < 5.95 to the right, agree=0.750, adj=0.345, (0 split)
## alcohol < 11.875 to the left, agree=0.750, adj=0.345, (0 split)
## chlorides < 0.0335 to the right, agree=0.737, adj=0.310, (0 split)
## residual.sugar < 2.25 to the right, agree=0.711, adj=0.241, (0 split)
## total.sulfur.dioxide < 66.5 to the right, agree=0.671, adj=0.138, (0 split)
##
## Node number 13: 286 observations
## mean=6.367133, MSE=0.4840946
##
## Node number 20: 193 observations
## mean=5.678756, MSE=0.4563881
##
## Node number 21: 138 observations, complexity param=0.01047046
## mean=5.949275, MSE=0.6423545
## left son=42 (107 obs) right son=43 (31 obs)
## Primary splits:
## residual.sugar < 12.65 to the left, improve=0.14492560, (0 missing)
## density < 0.99674 to the left, improve=0.11330300, (0 missing)
## free.sulfur.dioxide < 12 to the left, improve=0.09934807, (0 missing)
## total.sulfur.dioxide < 211.5 to the left, improve=0.06856412, (0 missing)
## alcohol < 9.05 to the right, improve=0.05810162, (0 missing)
## Surrogate splits:
## density < 0.99723 to the left, agree=0.935, adj=0.710, (0 split)
## alcohol < 9.15 to the right, agree=0.841, adj=0.290, (0 split)
## pH < 2.91 to the right, agree=0.790, adj=0.065, (0 split)
## free.sulfur.dioxide < 67.25 to the left, agree=0.783, adj=0.032, (0 split)
##
## Node number 24: 47 observations
## mean=5.489362, MSE=0.8030783
##
## Node number 25: 29 observations
## mean=6.37931, MSE=0.7181926
##
## Node number 42: 107 observations
## mean=5.785047, MSE=0.505197
##
## Node number 43: 31 observations
## mean=6.516129, MSE=0.7013528
install.packages("rpart.plot")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.5'
## (as 'lib' is unspecified)
library(rpart.plot)
rpart.plot(m.rpart, digits = 3) #plots the regression tree. The highest percentage of wines have alchol below 10.9, volatile acidity above 0.273, and free sulfur dioxide above 9.5

rpart.plot(m.rpart, digits = 4, fallen.leaves = TRUE, type = 3, extra = 101) #makes the regression tree plot easier to interpret

p.rpart <- predict(m.rpart, wine_test) #makes predicition for the testing set as a way to evaluate the tree
summary(p.rpart) #summary of the predicitons
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 4.333 5.303 5.785 5.901 6.367 7.014
summary(wine_test$quality) #the actual results have a slightly higher median, and a larger range
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3.000 5.000 6.000 5.901 6.000 9.000
cor(p.rpart, wine_test$quality) #shows the correlation between the predictions
## [1] 0.6079196
MAE <- function(actual, predicted) {
mean(abs(actual- predicted))
}
MAE(p.rpart, wine_test$quality) #shows the mean absolute error between the prdictions and actuals
## [1] 0.574808
mean(wine_train$quality) #5.871
## [1] 5.870933
MAE(5.87, wine_test$quality) #showss the MAE between the mean and the actual. higer than the first one
## [1] 0.6722474
library(Cubist)
## Loading required package: lattice
m.cubist <- cubist(x = wine_train[-12], y = wine_train$quality) #making cubist model tree
m.cubist #info on cubist model
##
## Call:
## cubist.default(x = wine_train[-12], y = wine_train$quality)
##
## Number of samples: 3750
## Number of predictors: 11
##
## Number of committees: 1
## Number of rules: 25
summary(m.cubist) #shows the number of cases that fall into each node and leaf in the decision tree
##
## Call:
## cubist.default(x = wine_train[-12], y = wine_train$quality)
##
##
## Cubist [Release 2.07 GPL Edition] Tue Feb 24 00:26:52 2026
## ---------------------------------
##
## Target attribute `outcome'
##
## Read 3750 cases (12 attributes) from undefined.data
##
## Model:
##
## Rule 1: [21 cases, mean 5.0, range 4 to 6, est err 0.5]
##
## if
## free.sulfur.dioxide > 30
## total.sulfur.dioxide > 195
## total.sulfur.dioxide <= 235
## sulphates > 0.64
## alcohol > 9.1
## then
## outcome = 573.6 + 0.0478 total.sulfur.dioxide - 573 density
## - 0.788 alcohol + 0.186 residual.sugar - 4.73 volatile.acidity
##
## Rule 2: [28 cases, mean 5.0, range 4 to 8, est err 0.7]
##
## if
## volatile.acidity > 0.31
## citric.acid <= 0.36
## residual.sugar <= 1.45
## total.sulfur.dioxide <= 97
## alcohol > 9.1
## then
## outcome = 168.2 + 4.75 citric.acid + 0.0123 total.sulfur.dioxide
## - 170 density + 0.057 residual.sugar - 6.4 chlorides + 0.84 pH
## + 0.14 fixed.acidity
##
## Rule 3: [171 cases, mean 5.1, range 3 to 6, est err 0.3]
##
## if
## volatile.acidity > 0.205
## chlorides <= 0.054
## density <= 0.99839
## alcohol <= 9.1
## then
## outcome = 147.4 - 144 density + 0.08 residual.sugar + 0.117 alcohol
## - 0.87 volatile.acidity - 0.09 pH - 0.01 fixed.acidity
##
## Rule 4: [37 cases, mean 5.3, range 3 to 6, est err 0.5]
##
## if
## free.sulfur.dioxide > 30
## total.sulfur.dioxide > 235
## alcohol > 9.1
## then
## outcome = 19.5 - 0.013 total.sulfur.dioxide - 2.7 volatile.acidity
## - 10 density + 0.005 residual.sugar + 0.008 alcohol
##
## Rule 5: [64 cases, mean 5.3, range 5 to 6, est err 0.3]
##
## if
## volatile.acidity > 0.205
## residual.sugar > 17.85
## then
## outcome = -23.6 + 0.233 alcohol - 5.2 chlorides - 0.75 citric.acid
## + 28 density - 0.81 volatile.acidity - 0.19 pH
## - 0.002 residual.sugar
##
## Rule 6: [56 cases, mean 5.3, range 4 to 7, est err 0.6]
##
## if
## fixed.acidity <= 7.1
## volatile.acidity > 0.205
## chlorides > 0.054
## density <= 0.99839
## alcohol <= 9.1
## then
## outcome = 40.6 + 0.374 alcohol - 1.62 volatile.acidity
## + 0.026 residual.sugar - 38 density - 0.21 pH
## - 0.01 fixed.acidity
##
## Rule 7: [337 cases, mean 5.3, range 3 to 7, est err 0.4]
##
## if
## fixed.acidity <= 7.8
## volatile.acidity > 0.305
## chlorides <= 0.09
## free.sulfur.dioxide <= 82.5
## total.sulfur.dioxide > 130
## total.sulfur.dioxide <= 235
## sulphates <= 0.64
## alcohol <= 10.4
## then
## outcome = -32.1 + 0.233 alcohol - 9.7 chlorides
## + 0.0038 total.sulfur.dioxide - 0.0081 free.sulfur.dioxide
## + 35 density + 0.81 volatile.acidity
##
## Rule 8: [30 cases, mean 5.5, range 3 to 7, est err 0.5]
##
## if
## fixed.acidity > 7.1
## volatile.acidity > 0.205
## chlorides > 0.054
## density <= 0.99839
## alcohol <= 9.1
## then
## outcome = 244 - 1.56 fixed.acidity - 228 density
## + 0.0252 free.sulfur.dioxide - 7.3 chlorides
## - 0.19 volatile.acidity + 0.003 residual.sugar
##
## Rule 9: [98 cases, mean 5.5, range 4 to 8, est err 0.5]
##
## if
## volatile.acidity > 0.155
## chlorides > 0.09
## total.sulfur.dioxide <= 235
## sulphates <= 0.64
## then
## outcome = 55.9 - 3.85 volatile.acidity - 52 density
## + 0.023 residual.sugar + 0.092 alcohol + 0.35 pH
## + 0.05 fixed.acidity + 0.3 sulphates
## + 0.001 free.sulfur.dioxide
##
## Rule 10: [446 cases, mean 5.6, range 4 to 8, est err 0.5]
##
## if
## fixed.acidity <= 7.8
## volatile.acidity > 0.155
## volatile.acidity <= 0.305
## chlorides <= 0.09
## free.sulfur.dioxide <= 82.5
## total.sulfur.dioxide > 130
## total.sulfur.dioxide <= 235
## sulphates <= 0.64
## alcohol > 9.1
## alcohol <= 10.4
## then
## outcome = 15.1 + 0.35 alcohol - 3.09 volatile.acidity - 14.7 chlorides
## + 1.16 sulphates - 0.0022 total.sulfur.dioxide
## + 0.11 fixed.acidity + 0.45 pH + 0.5 citric.acid - 14 density
## + 0.006 residual.sugar
##
## Rule 11: [31 cases, mean 5.6, range 3 to 8, est err 0.8]
##
## if
## volatile.acidity > 0.31
## citric.acid > 0.36
## free.sulfur.dioxide <= 30
## total.sulfur.dioxide <= 97
## then
## outcome = 3.2 + 0.0584 total.sulfur.dioxide + 7.77 volatile.acidity
## + 0.328 alcohol - 9 density + 0.003 residual.sugar
##
## Rule 12: [20 cases, mean 5.7, range 3 to 8, est err 0.9]
##
## if
## free.sulfur.dioxide > 82.5
## total.sulfur.dioxide <= 235
## sulphates <= 0.64
## alcohol > 9.1
## then
## outcome = -8.9 + 109.3 chlorides + 0.948 alcohol
##
## Rule 13: [331 cases, mean 5.8, range 4 to 8, est err 0.5]
##
## if
## volatile.acidity > 0.31
## free.sulfur.dioxide <= 30
## total.sulfur.dioxide > 97
## alcohol > 9.1
## then
## outcome = 89.8 + 0.0234 free.sulfur.dioxide + 0.324 alcohol
## + 0.07 residual.sugar - 90 density - 1.47 volatile.acidity
## + 0.48 pH
##
## Rule 14: [116 cases, mean 5.8, range 3 to 8, est err 0.6]
##
## if
## fixed.acidity > 7.8
## volatile.acidity > 0.155
## free.sulfur.dioxide > 30
## total.sulfur.dioxide > 130
## total.sulfur.dioxide <= 235
## sulphates <= 0.64
## alcohol > 9.1
## then
## outcome = 6 + 0.346 alcohol - 0.41 fixed.acidity - 1.69 volatile.acidity
## - 2.9 chlorides + 0.19 sulphates + 0.07 pH
##
## Rule 15: [115 cases, mean 5.8, range 4 to 7, est err 0.5]
##
## if
## volatile.acidity > 0.205
## residual.sugar <= 17.85
## density > 0.99839
## alcohol <= 9.1
## then
## outcome = -110.2 + 120 density - 3.46 volatile.acidity - 0.97 pH
## - 0.022 residual.sugar + 0.088 alcohol - 0.6 citric.acid
## - 0.01 fixed.acidity
##
## Rule 16: [986 cases, mean 5.9, range 3 to 9, est err 0.6]
##
## if
## volatile.acidity <= 0.31
## free.sulfur.dioxide <= 30
## alcohol > 9.1
## then
## outcome = 280.4 - 282 density + 0.128 residual.sugar
## + 0.0264 free.sulfur.dioxide - 3 volatile.acidity + 1.2 pH
## + 0.65 citric.acid + 0.09 fixed.acidity + 0.56 sulphates
## + 0.015 alcohol
##
## Rule 17: [49 cases, mean 6.0, range 5 to 8, est err 0.5]
##
## if
## volatile.acidity > 0.155
## residual.sugar > 8.8
## free.sulfur.dioxide > 30
## total.sulfur.dioxide <= 130
## pH <= 3.26
## alcohol > 9.1
## then
## outcome = 173.5 - 169 density + 0.055 alcohol + 0.38 sulphates
## + 0.002 residual.sugar
##
## Rule 18: [114 cases, mean 6.1, range 3 to 9, est err 0.6]
##
## if
## volatile.acidity > 0.31
## citric.acid <= 0.36
## residual.sugar > 1.45
## total.sulfur.dioxide <= 97
## alcohol > 9.1
## then
## outcome = 302.3 - 305 density + 0.0128 total.sulfur.dioxide
## + 0.096 residual.sugar + 1.94 citric.acid + 1.05 pH
## + 0.17 fixed.acidity - 6.7 chlorides
## + 0.0022 free.sulfur.dioxide - 0.21 volatile.acidity
## + 0.013 alcohol + 0.09 sulphates
##
## Rule 19: [145 cases, mean 6.1, range 5 to 8, est err 0.6]
##
## if
## volatile.acidity > 0.155
## free.sulfur.dioxide > 30
## total.sulfur.dioxide <= 195
## sulphates > 0.64
## then
## outcome = 206 - 209 density + 0.069 residual.sugar + 0.38 fixed.acidity
## + 2.79 sulphates + 0.0155 free.sulfur.dioxide
## - 0.0051 total.sulfur.dioxide - 1.71 citric.acid + 1.04 pH
##
## Rule 20: [555 cases, mean 6.1, range 3 to 9, est err 0.6]
##
## if
## total.sulfur.dioxide > 130
## total.sulfur.dioxide <= 235
## sulphates <= 0.64
## alcohol > 10.4
## then
## outcome = 108 + 0.276 alcohol - 109 density + 0.05 residual.sugar
## + 0.77 pH - 1.02 volatile.acidity - 4.2 chlorides
## + 0.78 sulphates + 0.08 fixed.acidity
## + 0.0016 free.sulfur.dioxide - 0.0003 total.sulfur.dioxide
##
## Rule 21: [73 cases, mean 6.2, range 4 to 8, est err 0.4]
##
## if
## volatile.acidity > 0.155
## citric.acid <= 0.28
## residual.sugar <= 8.8
## free.sulfur.dioxide > 30
## total.sulfur.dioxide <= 130
## pH <= 3.26
## sulphates <= 0.64
## alcohol > 9.1
## then
## outcome = 4.2 + 0.147 residual.sugar + 0.47 alcohol + 3.75 sulphates
## - 2.5 volatile.acidity - 5 density
##
## Rule 22: [244 cases, mean 6.3, range 4 to 8, est err 0.6]
##
## if
## citric.acid > 0.28
## residual.sugar <= 8.8
## free.sulfur.dioxide > 30
## total.sulfur.dioxide <= 130
## pH <= 3.26
## then
## outcome = 40.1 + 0.278 alcohol + 1.3 sulphates - 39 density
## + 0.017 residual.sugar + 0.001 total.sulfur.dioxide + 0.17 pH
## + 0.03 fixed.acidity
##
## Rule 23: [106 cases, mean 6.3, range 4 to 8, est err 0.6]
##
## if
## volatile.acidity <= 0.155
## free.sulfur.dioxide > 30
## then
## outcome = 139.1 - 138 density + 0.058 residual.sugar + 0.71 pH
## + 0.92 sulphates + 0.11 fixed.acidity - 0.73 volatile.acidity
## + 0.055 alcohol - 0.0012 total.sulfur.dioxide
## + 0.0007 free.sulfur.dioxide
##
## Rule 24: [137 cases, mean 6.5, range 4 to 9, est err 0.6]
##
## if
## volatile.acidity > 0.155
## free.sulfur.dioxide > 30
## total.sulfur.dioxide <= 130
## pH > 3.26
## sulphates <= 0.64
## alcohol > 9.1
## then
## outcome = 114.2 + 0.0142 total.sulfur.dioxide - 107 density
## - 11.8 chlorides - 1.57 pH + 0.124 alcohol + 1.21 sulphates
## + 1.16 volatile.acidity + 0.021 residual.sugar
## + 0.04 fixed.acidity
##
## Rule 25: [92 cases, mean 6.5, range 4 to 8, est err 0.6]
##
## if
## volatile.acidity <= 0.205
## alcohol <= 9.1
## then
## outcome = -200.7 + 210 density + 5.88 volatile.acidity + 23.9 chlorides
## - 2.83 citric.acid - 1.17 pH
##
##
## Evaluation on training data (3750 cases):
##
## Average |error| 0.5
## Relative |error| 0.67
## Correlation coefficient 0.66
##
##
## Attribute usage:
## Conds Model
##
## 84% 93% alcohol
## 80% 89% volatile.acidity
## 70% 61% free.sulfur.dioxide
## 63% 50% total.sulfur.dioxide
## 44% 70% sulphates
## 26% 44% chlorides
## 22% 76% fixed.acidity
## 16% 87% residual.sugar
## 11% 86% pH
## 11% 45% citric.acid
## 8% 97% density
##
##
## Time: 0.2 secs
p.cubist <- predict(m.cubist, wine_test) #making model predicitons
summary(p.cubist) #lower mean than the first predictions, but higher median
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3.677 5.416 5.906 5.848 6.238 7.393
cor(p.cubist, wine_test$quality) #higher correlation than the first model
## [1] 0.6201015
MAE(wine_test$quality, p.cubist) #lower MAE than the first model, which helps show betetr performance
## [1] 0.5339725