Classification analysis consists of various techniques that are best suited in analyzing a qualitative response. The purpose of this analysis is understand the buying patterns of customers from a wholesale distributor. Therefore classification analysis will be used to study the associations between a set of predictors and a categorical target while diving these entities into classes. The wholesale dataset documents customers of a wholesaler into two classes: [1] Horeca (Hotels/Restaurants/Cafes) and [2] Retail (regular stores) and captures the spending amounts on fresh grocery products.

There are many possible classification techniques that one can use to predict a qualitative response. This analysis will focus on the buying patterns of customers from a wholesale distributor. Classification analysis, a supervised learning technique, we will study the association between a set predictors and a categorical target while dividing these entities into classes. In our wholesale dataset, the customers of a wholesaler are divided into two classes, Horeca (Hotels/Restaurants/Cafes) and Retail (regular stores) and the spending amounts on fresh grocery products.

The aim of Utilizing logistic regression and linear discriminant analysis, is to understand if there are different spending patterns for the two groups of customers, Horeca and Retail. The discriminant analysis between Horeca and Retail customers will be used to answer our question. If potential differences in spending patterns are found this information can be used to redirect marketing assets, update in store layouts, optimize inventory controls, reduce shrinkage, etc…

Step 1 Load the data and run numerical summaries

Step 2 Split the dat into training and testing data

Step 3 Fit the logistic regression model, LDA, PCA, KNN, Decision Trees

Step 4 Use the fitted model to do predictions of the test data

Install packages and prem for Algorithms

## Loading required package: ISLR
## Warning: package 'ISLR' was built under R version 3.0.3
## Loading required package: C50
## Warning: package 'C50' was built under R version 3.0.3
## Loading required package: rpart
## Warning: package 'rpart' was built under R version 3.0.3
## Loading required package: rpart.plot
## Warning: package 'rpart.plot' was built under R version 3.0.3
## Loading required package: fancyRpartplot
## Warning in library(package, lib.loc = lib.loc, character.only = TRUE,
## logical.return = TRUE, : there is no package called 'fancyRpartplot'
## Loading required package: MASS
## Warning: package 'MASS' was built under R version 3.0.3
## Loading required package: class
## Warning: package 'class' was built under R version 3.0.3
## Loading required package: rattle
## Warning: package 'rattle' was built under R version 3.0.3
## Rattle: A free graphical interface for data mining with R.
## Version 3.4.1 Copyright (c) 2006-2014 Togaware Pty Ltd.
## Type 'rattle()' to shake, rattle, and roll your data.
## Loading required package: randomForest
## Warning: package 'randomForest' was built under R version 3.0.3
## randomForest 4.6-10
## Type rfNews() to see new features/changes/bug fixes.
## Loading required package: gclus
## Warning: package 'gclus' was built under R version 3.0.3
## Loading required package: cluster
## Loading required package: car
## Warning: package 'car' was built under R version 3.0.3
## Loading required package: caret
## Warning: package 'caret' was built under R version 3.0.3
## Loading required package: lattice
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.0.3
## Loading required package: e1071
## Warning: package 'e1071' was built under R version 3.0.3
## Loading required package: tree
## Warning: package 'tree' was built under R version 3.0.3

Read the data into R.

Complete preprocessing steps and convert Channel and Region to categorial Variables. Convert Channel to y values must be 0 <= y <= 1 for logistic regression. y=Channel 0=Retail, 1=Horeca

We will use Channel as our response variable and see if we can predict it as a binary response using logistic regression.

Plot our data first. Then plot rearrange by variables so that those with higher correlations are closer to the principal diagonal.

wholesale <- read.csv("~/UChicago MScA/Adv Data Mining II/Final Project/wholesale1.csv")
wholesaled <- read.csv("~/UChicago MScA/Adv Data Mining II/Final Project/wholesale.csv")
names(wholesale)
## [1] "Channel"          "Region"           "Fresh"           
## [4] "Milk"             "Grocery"          "Frozen"          
## [7] "Detergents_Paper" "Delicassen"
View(wholesale)
View(wholesaled)
as.data.frame(wholesale)
##     Channel Region  Fresh  Milk Grocery Frozen Detergents_Paper Delicassen
## 1         0      3  12669  9656    7561    214             2674       1338
## 2         0      3   7057  9810    9568   1762             3293       1776
## 3         0      3   6353  8808    7684   2405             3516       7844
## 4         1      3  13265  1196    4221   6404              507       1788
## 5         0      3  22615  5410    7198   3915             1777       5185
## 6         0      3   9413  8259    5126    666             1795       1451
## 7         0      3  12126  3199    6975    480             3140        545
## 8         0      3   7579  4956    9426   1669             3321       2566
## 9         1      3   5963  3648    6192    425             1716        750
## 10        0      3   6006 11093   18881   1159             7425       2098
## 11        0      3   3366  5403   12974   4400             5977       1744
## 12        0      3  13146  1124    4523   1420              549        497
## 13        0      3  31714 12319   11757    287             3881       2931
## 14        0      3  21217  6208   14982   3095             6707        602
## 15        0      3  24653  9465   12091    294             5058       2168
## 16        1      3  10253  1114    3821    397              964        412
## 17        0      3   1020  8816   12121    134             4508       1080
## 18        1      3   5876  6157    2933    839              370       4478
## 19        0      3  18601  6327   10099   2205             2767       3181
## 20        1      3   7780  2495    9464    669             2518        501
## 21        0      3  17546  4519    4602   1066             2259       2124
## 22        1      3   5567   871    2010   3383              375        569
## 23        1      3  31276  1917    4469   9408             2381       4334
## 24        0      3  26373 36423   22019   5154             4337      16523
## 25        0      3  22647  9776   13792   2915             4482       5778
## 26        0      3  16165  4230    7595    201             4003         57
## 27        1      3   9898   961    2861   3151              242        833
## 28        1      3  14276   803    3045    485              100        518
## 29        0      3   4113 20484   25957   1158             8604       5206
## 30        1      3  43088  2100    2609   1200             1107        823
## 31        1      3  18815  3610   11107   1148             2134       2963
## 32        1      3   2612  4339    3133   2088              820        985
## 33        1      3  21632  1318    2886    266              918        405
## 34        1      3  29729  4786    7326   6130              361       1083
## 35        1      3   1502  1979    2262    425              483        395
## 36        0      3    688  5491   11091    833             4239        436
## 37        1      3  29955  4362    5428   1729              862       4626
## 38        0      3  15168 10556   12477   1920             6506        714
## 39        0      3   4591 15729   16709     33             6956        433
## 40        1      3  56159   555     902  10002              212       2916
## 41        1      3  24025  4332    4757   9510             1145       5864
## 42        1      3  19176  3065    5956   2033             2575       2802
## 43        0      3  10850  7555   14961    188             6899         46
## 44        0      3    630 11095   23998    787             9529         72
## 45        0      3   9670  7027   10471    541             4618         65
## 46        0      3   5181 22044   21531   1740             7353       4985
## 47        0      3   3103 14069   21955   1668             6792       1452
## 48        0      3  44466 54259   55571   7782            24171       6465
## 49        0      3  11519  6152   10868    584             5121       1476
## 50        0      3   4967 21412   28921   1798            13583       1163
## 51        1      3   6269  1095    1980   3860              609       2162
## 52        1      3   3347  4051    6996    239             1538        301
## 53        0      3  40721  3916    5876    532             2587       1278
## 54        0      3    491 10473   11532    744             5611        224
## 55        1      3  27329  1449    1947   2436              204       1333
## 56        1      3   5264  3683    5005   1057             2024       1130
## 57        0      3   4098 29892   26866   2616            17740       1340
## 58        0      3   5417  9933   10487     38             7572       1282
## 59        1      3  13779  1970    1648    596              227        436
## 60        1      3   6137  5360    8040    129             3084       1603
## 61        0      3   8590  3045    7854     96             4095        225
## 62        0      3  35942 38369   59598   3254            26701       2017
## 63        0      3   7823  6245    6544   4154             4074        964
## 64        0      3   9396 11601   15775   2896             7677       1295
## 65        1      3   4760  1227    3250   3724             1247       1145
## 66        0      3     85 20959   45828     36            24231       1423
## 67        1      3      9  1534    7417    175             3468         27
## 68        0      3  19913  6759   13462   1256             5141        834
## 69        1      3   2446  7260    3993   5870              788       3095
## 70        1      3   8352  2820    1293    779              656        144
## 71        1      3  16705  2037    3202  10643              116       1365
## 72        1      3  18291  1266   21042   5373             4173      14472
## 73        1      3   4420  5139    2661   8872             1321        181
## 74        0      3  19899  5332    8713   8132              764        648
## 75        0      3   8190  6343    9794   1285             1901       1780
## 76        1      3  20398  1137       3   4407                3        975
## 77        1      3    717  3587    6532   7530              529        894
## 78        0      3  12205 12697   28540    869            12034       1009
## 79        1      3  10766  1175    2067   2096              301        167
## 80        1      3   1640  3259    3655    868             1202       1653
## 81        1      3   7005   829    3009    430              610        529
## 82        0      3    219  9540   14403    283             7818        156
## 83        0      3  10362  9232   11009    737             3537       2342
## 84        1      3  20874  1563    1783   2320              550        772
## 85        0      3  11867  3327    4814   1178             3837        120
## 86        0      3  16117 46197   92780   1026            40827       2944
## 87        0      3  22925 73498   32114    987            20070        903
## 88        1      3  43265  5025    8117   6312             1579      14351
## 89        1      3   7864   542    4042   9735              165         46
## 90        1      3  24904  3836    5330   3443              454       3178
## 91        1      3  11405   596    1638   3347               69        360
## 92        1      3  12754  2762    2530   8693              627       1117
## 93        0      3   9198 27472   32034   3232            18906       5130
## 94        1      3  11314  3090    2062  35009               71       2698
## 95        0      3   5626 12220   11323    206             5038        244
## 96        1      3      3  2920    6252    440              223        709
## 97        0      3     23  2616    8118    145             3874        217
## 98        1      3    403   254     610    774               54         63
## 99        1      3    503   112     778    895               56        132
## 100       1      3   9658  2182    1909   5639              215        323
## 101       0      3  11594  7779   12144   3252             8035       3029
## 102       0      3   1420 10810   16267   1593             6766       1838
## 103       0      3   2932  6459    7677   2561             4573       1386
## 104       1      3  56082  3504    8906  18028             1480       2498
## 105       1      3  14100  2132    3445   1336             1491        548
## 106       1      3  15587  1014    3970    910              139       1378
## 107       0      3   1454  6337   10704    133             6830       1831
## 108       0      3   8797 10646   14886   2471             8969       1438
## 109       0      3   1531  8397    6981    247             2505       1236
## 110       0      3   1406 16729   28986    673              836          3
## 111       1      3  11818  1648    1694   2276              169       1647
## 112       0      3  12579 11114   17569    805             6457       1519
## 113       1      3  19046  2770    2469   8853              483       2708
## 114       1      3  14438  2295    1733   3220              585       1561
## 115       1      3  18044  1080    2000   2555              118       1266
## 116       1      3  11134   793    2988   2715              276        610
## 117       1      3  11173  2521    3355   1517              310        222
## 118       1      3   6990  3880    5380   1647              319       1160
## 119       1      3  20049  1891    2362   5343              411        933
## 120       1      3   8258  2344    2147   3896              266        635
## 121       1      3  17160  1200    3412   2417              174       1136
## 122       1      3   4020  3234    1498   2395              264        255
## 123       1      3  12212   201     245   1991               25        860
## 124       0      3  11170 10769    8814   2194             1976        143
## 125       1      3  36050  1642    2961   4787              500       1621
## 126       1      3  76237  3473    7102  16538              778        918
## 127       1      3  19219  1840    1658   8195              349        483
## 128       0      3  21465  7243   10685    880             2386       2749
## 129       1      3    140  8847    3823    142             1062          3
## 130       1      3  42312   926    1510   1718              410       1819
## 131       1      3   7149  2428     699   6316              395        911
## 132       1      3   2101   589     314    346               70        310
## 133       1      3  14903  2032    2479    576              955        328
## 134       1      3   9434  1042    1235    436              256        396
## 135       1      3   7388  1882    2174    720               47        537
## 136       1      3   6300  1289    2591   1170              199        326
## 137       1      3   4625  8579    7030   4575             2447       1542
## 138       1      3   3087  8080    8282    661              721         36
## 139       1      3  13537  4257    5034    155              249       3271
## 140       1      3   5387  4979    3343    825              637        929
## 141       1      3  17623  4280    7305   2279              960       2616
## 142       1      3  30379 13252    5189    321               51       1450
## 143       1      3  37036  7152    8253   2995               20          3
## 144       1      3  10405  1596    1096   8425              399        318
## 145       1      3  18827  3677    1988    118              516        201
## 146       0      3  22039  8384   34792     42            12591       4430
## 147       1      3   7769  1936    2177    926               73        520
## 148       1      3   9203  3373    2707   1286             1082        526
## 149       1      3   5924   584     542   4052              283        434
## 150       1      3  31812  1433    1651    800              113       1440
## 151       1      3  16225  1825    1765    853              170       1067
## 152       1      3   1289  3328    2022    531              255       1774
## 153       1      3  18840  1371    3135   3001              352        184
## 154       1      3   3463  9250    2368    779              302       1627
## 155       1      3    622    55     137     75                7          8
## 156       0      3   1989 10690   19460    233            11577       2153
## 157       0      3   3830  5291   14855    317             6694       3182
## 158       1      3  17773  1366    2474   3378              811        418
## 159       0      3   2861  6570    9618    930             4004       1682
## 160       0      3    355  7704   14682    398             8077        303
## 161       0      3   1725  3651   12822    824             4424       2157
## 162       1      3  12434   540     283   1092                3       2233
## 163       1      3  15177  2024    3810   2665              232        610
## 164       0      3   5531 15726   26870   2367            13726        446
## 165       0      3   5224  7603    8584   2540             3674        238
## 166       0      3  15615 12653   19858   4425             7108       2379
## 167       0      3   4822  6721    9170    993             4973       3637
## 168       1      3   2926  3195    3268    405             1680        693
## 169       1      3   5809   735     803   1393               79        429
## 170       1      3   5414   717    2155   2399               69        750
## 171       0      3    260  8675   13430   1116             7015        323
## 172       0      3    200 25862   19816    651             8773       6250
## 173       1      3    955  5479    6536    333             2840        707
## 174       0      3    514  7677   19805    937             9836        716
## 175       1      3    286  1208    5241   2515              153       1442
## 176       0      3   2343  7845   11874     52             4196       1697
## 177       1      3  45640  6958    6536   7368             1532        230
## 178       1      3  12759  7330    4533   1752               20       2631
## 179       1      3  11002  7075    4945   1152              120        395
## 180       1      3   3157  4888    2500   4477              273       2165
## 181       1      3  12356  6036    8887    402             1382       2794
## 182       1      3 112151 29627   18148  16745             4948       8550
## 183       1      3    694  8533   10518    443             6907        156
## 184       1      3  36847 43950   20170  36534              239      47943
## 185       1      3    327   918    4710     74              334         11
## 186       1      3   8170  6448    1139   2181               58        247
## 187       1      3   3009   521     854   3470              949        727
## 188       1      3   2438  8002    9819   6269             3459          3
## 189       0      3   8040  7639   11687   2758             6839        404
## 190       0      3    834 11577   11522    275             4027       1856
## 191       1      3  16936  6250    1981   7332              118         64
## 192       1      3  13624   295    1381    890               43         84
## 193       1      3   5509  1461    2251    547              187        409
## 194       0      3    180  3485   20292    959             5618        666
## 195       1      3   7107  1012    2974    806              355       1142
## 196       1      3  17023  5139    5230   7888              330       1755
## 197       1      1  30624  7209    4897  18711              763       2876
## 198       0      1   2427  7097   10391   1127             4314       1468
## 199       1      1  11686  2154    6824   3527              592        697
## 200       1      1   9670  2280    2112    520              402        347
## 201       0      1   3067 13240   23127   3941             9959        731
## 202       0      1   4484 14399   24708   3549            14235       1681
## 203       1      1  25203 11487    9490   5065              284       6854
## 204       1      1    583   685    2216    469              954         18
## 205       1      1   1956   891    5226   1383                5       1328
## 206       0      1   1107 11711   23596    955             9265        710
## 207       1      1   6373   780     950    878              288        285
## 208       0      1   2541  4737    6089   2946             5316        120
## 209       1      1   1537  3748    5838   1859             3381        806
## 210       0      1   5550 12729   16767    864            12420        797
## 211       1      1  18567  1895    1393   1801              244       2100
## 212       0      1  12119 28326   39694   4736            19410       2870
## 213       1      1   7291  1012    2062   1291              240       1775
## 214       1      1   3317  6602    6861   1329             3961       1215
## 215       0      1   2362  6551   11364    913             5957        791
## 216       1      1   2806 10765   15538   1374             5828       2388
## 217       0      1   2532 16599   36486    179            13308        674
## 218       1      1  18044  1475    2046   2532              130       1158
## 219       0      1     18  7504   15205   1285             4797       6372
## 220       1      1   4155   367    1390   2306               86        130
## 221       1      1  14755   899    1382   1765               56        749
## 222       1      1   5396  7503   10646     91             4167        239
## 223       1      1   5041  1115    2856   7496              256        375
## 224       0      1   2790  2527    5265   5612              788       1360
## 225       1      1   7274   659    1499    784               70        659
## 226       1      1  12680  3243    4157    660              761        786
## 227       0      1  20782  5921    9212   1759             2568       1553
## 228       1      1   4042  2204    1563   2286              263        689
## 229       1      1   1869   577     572    950             4762        203
## 230       1      1   8656  2746    2501   6845              694        980
## 231       0      1  11072  5989    5615   8321              955       2137
## 232       1      1   2344 10678    3828   1439             1566        490
## 233       1      1  25962  1780    3838    638              284        834
## 234       1      1    964  4984    3316    937              409          7
## 235       1      1  15603  2703    3833   4260              325       2563
## 236       1      1   1838  6380    2824   1218             1216        295
## 237       1      1   8635   820    3047   2312              415        225
## 238       1      1  18692  3838     593   4634               28       1215
## 239       1      1   7363   475     585   1112               72        216
## 240       1      1  47493  2567    3779   5243              828       2253
## 241       1      1  22096  3575    7041  11422              343       2564
## 242       1      1  24929  1801    2475   2216              412       1047
## 243       1      1  18226   659    2914   3752              586        578
## 244       1      1  11210  3576    5119    561             1682       2398
## 245       1      1   6202  7775   10817   1183             3143       1970
## 246       0      1   3062  6154   13916    230             8933       2784
## 247       1      1   8885  2428    1777   1777              430        610
## 248       1      1  13569   346     489   2077               44        659
## 249       1      1  15671  5279    2406    559              562        572
## 250       1      1   8040  3795    2070   6340              918        291
## 251       1      1   3191  1993    1799   1730              234        710
## 252       0      1   6134 23133   33586   6746            18594       5121
## 253       1      1   6623  1860    4740   7683              205       1693
## 254       1      1  29526  7961   16966    432              363       1391
## 255       1      1  10379 17972    4748   4686             1547       3265
## 256       1      1  31614   489    1495   3242              111        615
## 257       1      1  11092  5008    5249    453              392        373
## 258       1      1   8475  1931    1883   5004             3593        987
## 259       1      1  56083  4563    2124   6422              730       3321
## 260       1      1  53205  4959    7336   3012              967        818
## 261       1      1   9193  4885    2157    327              780        548
## 262       1      1   7858  1110    1094   6818               49        287
## 263       1      1  23257  1372    1677    982              429        655
## 264       1      1   2153  1115    6684   4324             2894        411
## 265       0      1   1073  9679   15445     61             5980       1265
## 266       1      1   5909 23527   13699  10155              830       3636
## 267       0      1    572  9763   22182   2221             4882       2563
## 268       1      1  20893  1222    2576   3975              737       3628
## 269       0      1  11908  8053   19847   1069             6374        698
## 270       1      1  15218   258    1138   2516              333        204
## 271       1      1   4720  1032     975   5500              197         56
## 272       1      1   2083  5007    1563   1120              147       1550
## 273       1      1    514  8323    6869    529               93       1040
## 274       1      3  36817  3045    1493   4802              210       1824
## 275       1      3    894  1703    1841    744              759       1153
## 276       1      3    680  1610     223    862               96        379
## 277       1      3  27901  3749    6964   4479              603       2503
## 278       1      3   9061   829     683  16919              621        139
## 279       1      3  11693  2317    2543   5845              274       1409
## 280       0      3  17360  6200    9694   1293             3620       1721
## 281       1      3   3366  2884    2431    977              167       1104
## 282       0      3  12238  7108    6235   1093             2328       2079
## 283       1      3  49063  3965    4252   5970             1041       1404
## 284       1      3  25767  3613    2013  10303              314       1384
## 285       1      3  68951  4411   12609   8692              751       2406
## 286       1      3  40254   640    3600   1042              436         18
## 287       1      3   7149  2247    1242   1619             1226        128
## 288       1      3  15354  2102    2828   8366              386       1027
## 289       1      3  16260   594    1296    848              445        258
## 290       1      3  42786   286     471   1388               32         22
## 291       1      3   2708  2160    2642    502              965       1522
## 292       1      3   6022  3354    3261   2507              212        686
## 293       1      3   2838  3086    4329   3838              825       1060
## 294       0      2   3996 11103   12469    902             5952        741
## 295       1      2  21273  2013    6550    909              811       1854
## 296       0      2   7588  1897    5234    417             2208        254
## 297       1      2  19087  1304    3643   3045              710        898
## 298       0      2   8090  3199    6986   1455             3712        531
## 299       0      2   6758  4560    9965    934             4538       1037
## 300       1      2    444   879    2060    264              290        259
## 301       0      2  16448  6243    6360    824             2662       2005
## 302       0      2   5283 13316   20399   1809             8752        172
## 303       0      2   2886  5302    9785    364             6236        555
## 304       0      2   2599  3688   13829    492            10069         59
## 305       0      2    161  7460   24773    617            11783       2410
## 306       0      2    243 12939    8852    799             3909        211
## 307       0      2   6468 12867   21570   1840             7558       1543
## 308       1      2  17327  2374    2842   1149              351        925
## 309       1      2   6987  1020    3007    416              257        656
## 310       0      2    918 20655   13567   1465             6846        806
## 311       1      2   7034  1492    2405  12569              299       1117
## 312       1      2  29635  2335    8280   3046              371        117
## 313       0      2   2137  3737   19172   1274            17120        142
## 314       1      2   9784   925    2405   4447              183        297
## 315       1      2  10617  1795    7647   1483              857       1233
## 316       0      2   1479 14982   11924    662             3891       3508
## 317       1      2   7127  1375    2201   2679               83       1059
## 318       1      2   1182  3088    6114    978              821       1637
## 319       1      2  11800  2713    3558   2121              706         51
## 320       0      2   9759 25071   17645   1128            12408       1625
## 321       1      2   1774  3696    2280    514              275        834
## 322       1      2   9155  1897    5167   2714              228       1113
## 323       1      2  15881   713    3315   3703             1470        229
## 324       1      2  13360   944   11593    915             1679        573
## 325       1      2  25977  3587    2464   2369              140       1092
## 326       1      2  32717 16784   13626  60869             1272       5609
## 327       1      2   4414  1610    1431   3498              387        834
## 328       1      2    542   899    1664    414               88        522
## 329       1      2  16933  2209    3389   7849              210       1534
## 330       1      2   5113  1486    4583   5127              492        739
## 331       1      2   9790  1786    5109   3570              182       1043
## 332       0      2  11223 14881   26839   1234             9606       1102
## 333       1      2  22321  3216    1447   2208              178       2602
## 334       0      2   8565  4980   67298    131            38102       1215
## 335       0      2  16823   928    2743  11559              332       3486
## 336       0      2  27082  6817   10790   1365             4111       2139
## 337       1      2  13970  1511    1330    650              146        778
## 338       1      2   9351  1347    2611   8170              442        868
## 339       1      2      3   333    7021  15601               15        550
## 340       1      2   2617  1188    5332   9584              573       1942
## 341       0      3    381  4025    9670    388             7271       1371
## 342       0      3   2320  5763   11238    767             5162       2158
## 343       1      3    255  5758    5923    349             4595       1328
## 344       0      3   1689  6964   26316   1456            15469         37
## 345       1      3   3043  1172    1763   2234              217        379
## 346       1      3   1198  2602    8335    402             3843        303
## 347       0      3   2771  6939   15541   2693             6600       1115
## 348       0      3  27380  7184   12311   2809             4621       1022
## 349       1      3   3428  2380    2028   1341             1184        665
## 350       0      3   5981 14641   20521   2005            12218        445
## 351       1      3   3521  1099    1997   1796              173        995
## 352       0      3   1210 10044   22294   1741            12638       3137
## 353       1      3    608  1106    1533    830               90        195
## 354       0      3    117  6264   21203    228             8682       1111
## 355       1      3  14039  7393    2548   6386             1333       2341
## 356       1      3    190   727    2012    245              184        127
## 357       1      3  22686   134     218   3157                9        548
## 358       0      3     37  1275   22272    137             6747        110
## 359       1      3    759 18664    1660   6114              536       4100
## 360       1      3    796  5878    2109    340              232        776
## 361       1      3  19746  2872    2006   2601              468        503
## 362       1      3   4734   607     864   1206              159        405
## 363       1      3   2121  1601    2453    560              179        712
## 364       1      3   4627   997    4438    191             1335        314
## 365       1      3   2615   873    1524   1103              514        468
## 366       0      3   4692  6128    8025   1619             4515       3105
## 367       1      3   9561  2217    1664   1173              222        447
## 368       1      3   3477   894     534   1457              252        342
## 369       1      3  22335  1196    2406   2046              101        558
## 370       1      3   6211   337     683   1089               41        296
## 371       0      3  39679  3944    4955   1364              523       2235
## 372       1      3  20105  1887    1939   8164              716        790
## 373       1      3   3884  3801    1641    876              397       4829
## 374       0      3  15076  6257    7398   1504             1916       3113
## 375       1      3   6338  2256    1668   1492              311        686
## 376       1      3   5841  1450    1162    597              476         70
## 377       0      3   3136  8630   13586   5641             4666       1426
## 378       1      3  38793  3154    2648   1034               96       1242
## 379       1      3   3225  3294    1902    282               68       1114
## 380       0      3   4048  5164   10391    130              813        179
## 381       1      3  28257   944    2146   3881              600        270
## 382       1      3  17770  4591    1617   9927              246        532
## 383       1      3  34454  7435    8469   2540             1711       2893
## 384       1      3   1821  1364    3450   4006              397        361
## 385       1      3  10683 21858   15400   3635              282       5120
## 386       1      3  11635   922    1614   2583              192       1068
## 387       1      3   1206  3620    2857   1945              353        967
## 388       1      3  20918  1916    1573   1960              231        961
## 389       1      3   9785   848    1172   1677              200        406
## 390       1      3   9385  1530    1422   3019              227        684
## 391       1      3   3352  1181    1328   5502              311       1000
## 392       1      3   2647  2761    2313    907               95       1827
## 393       1      3    518  4180    3600    659              122        654
## 394       1      3  23632  6730    3842   8620              385        819
## 395       1      3  12377   865    3204   1398              149        452
## 396       1      3   9602  1316    1263   2921              841        290
## 397       0      3   4515 11991    9345   2644             3378       2213
## 398       1      3  11535  1666    1428   6838               64        743
## 399       1      3  11442  1032     582   5390               74        247
## 400       1      3   9612   577     935   1601              469        375
## 401       1      3   4446   906    1238   3576              153       1014
## 402       1      3  27167  2801    2128  13223               92       1902
## 403       1      3  26539  4753    5091    220               10        340
## 404       1      3  25606 11006    4604    127              632        288
## 405       1      3  18073  4613    3444   4324              914        715
## 406       1      3   6884  1046    1167   2069              593        378
## 407       1      3  25066  5010    5026   9806             1092        960
## 408       0      3   7362 12844   18683   2854             7883        553
## 409       0      3   8257  3880    6407   1646             2730        344
## 410       1      3   8708  3634    6100   2349             2123       5137
## 411       1      3   6633  2096    4563   1389             1860       1892
## 412       1      3   2126  3289    3281   1535              235       4365
## 413       1      3     97  3605   12400     98             2970         62
## 414       1      3   4983  4859    6633  17866              912       2435
## 415       1      3   5969  1990    3417   5679             1135        290
## 416       0      3   7842  6046    8552   1691             3540       1874
## 417       0      3   4389 10940   10908    848             6728        993
## 418       1      3   5065  5499   11055    364             3485       1063
## 419       0      3    660  8494   18622    133             6740        776
## 420       1      3   8861  3783    2223    633             1580       1521
## 421       1      3   4456  5266   13227     25             6818       1393
## 422       0      3  17063  4847    9053   1031             3415       1784
## 423       1      3  26400  1377    4172    830              948       1218
## 424       0      3  17565  3686    4657   1059             1803        668
## 425       0      3  16980  2884   12232    874             3213        249
## 426       1      3  11243  2408    2593  15348              108       1886
## 427       1      3  13134  9347   14316   3141             5079       1894
## 428       1      3  31012 16687    5429  15082              439       1163
## 429       1      3   3047  5970    4910   2198              850        317
## 430       1      3   8607  1750    3580     47               84       2501
## 431       1      3   3097  4230   16483    575              241       2080
## 432       1      3   8533  5506    5160  13486             1377       1498
## 433       1      3  21117  1162    4754    269             1328        395
## 434       1      3   1982  3218    1493   1541              356       1449
## 435       1      3  16731  3922    7994    688             2371        838
## 436       1      3  29703 12051   16027  13135              182       2204
## 437       1      3  39228  1431     764   4510               93       2346
## 438       0      3  14531 15488   30243    437            14841       1867
## 439       1      3  10290  1981    2232   1038              168       2125
## 440       1      3   2787  1698    2510     65              477         52
#Correlations

pairs(wholesale, col=wholesale$Channel)

plot(wholesale)

cor(wholesale)
##                      Channel       Region       Fresh       Milk
## Channel           1.00000000 -0.062027619  0.16917204 -0.4607203
## Region           -0.06202762  1.000000000  0.05528692  0.0322875
## Fresh             0.16917204  0.055286923  1.00000000  0.1005098
## Milk             -0.46072028  0.032287502  0.10050977  1.0000000
## Grocery          -0.60879225  0.007695777 -0.01185387  0.7283351
## Frozen            0.20204596 -0.021044215  0.34588146  0.1239938
## Detergents_Paper -0.63602637 -0.001482686 -0.10195294  0.6618157
## Delicassen       -0.05601143  0.045212107  0.24468997  0.4063683
##                       Grocery      Frozen Detergents_Paper  Delicassen
## Channel          -0.608792245  0.20204596     -0.636026367 -0.05601143
## Region            0.007695777 -0.02104421     -0.001482686  0.04521211
## Fresh            -0.011853875  0.34588146     -0.101952938  0.24468997
## Milk              0.728335118  0.12399376      0.661815679  0.40636832
## Grocery           1.000000000 -0.04019274      0.924640691  0.20549651
## Frozen           -0.040192737  1.00000000     -0.131524906  0.39094747
## Detergents_Paper  0.924640691 -0.13152491      1.000000000  0.06929130
## Delicassen        0.205496511  0.39094747      0.069291297  1.00000000
#Correlations by color and higher correlations are moved closer to the principle diagonal---

wholesalecor<-abs(cor(wholesale))
wholesale.color<-dmat.color(wholesalecor)
wholesale.order<-order.single(wholesalecor)
wholesale.pairs<-cpairs(wholesale, wholesale.order, panel.colors=wholesale.color, gap=.5,)

main="Variables Ordered and Colored by Correlation"

#Create Variables --------------------------------------------------------------------------

Channel <- wholesale[,1]
Region <- wholesale[,2]
Fresh <- wholesale[,3]
Milk <- wholesale[,4]
Grocery <- wholesale[,5]
Frozen <- wholesale[,6]
Detergents <- wholesale[,7]
Delicassen <- wholesale[,8]

#ENHANCED SCATTERPLOT-----------------------------------------------------------------------


#Makes sense that more people are purchashing frozen and fresh items at Retail Channels over Horeca (Hotels/Restaurants/Cafe).  However we can assume that people still eat out at Horeca (Hotels/Restaurants/Cafe) but, not purchase in large quantities. 

scatterplot( Fresh ~ Frozen | Channel, data=wholesaled, 
            xlab="Fresh", ylab="Frozen", 
            main="Scatter Plot: Horeca(Hotel/Restaurant/Cafe) vs. Retail Channel (Store)", 
            smoother=T, 
            lty=1, lwd=2, by.groups=T)

scatterplot( Fresh ~ Frozen | Region, data=wholesaled, 
            xlab="Frozen", ylab="Fresh", 
            main="Scatter Plot: Regions in Spain",
            smoother=T, 
            lty=1, lwd=2, by.groups=T)

scatterplot( Milk ~ Delicassen | Channel, data=wholesaled, 
            xlab="Delicassen", ylab="Milk", 
            main="Scatter Plot: Horeca(Hotel/Restaurant/Cafe) vs. Retail Channel (Store)", 
            smoother=T, 
            lty=1, lwd=2, by.groups=T)

scatterplot( Milk ~ Delicassen | Region, data=wholesaled, 
            xlab="Delicassen", ylab="Milk", 
            main="Scatter Plot: Regions in Spain", 
            smoother=T, 
            lty=1, lwd=2, by.groups=T)

#Of course we see consumers purchashing more Detergents_Paper products at Retail (Stores)
scatterplot( Detergents_Paper ~ Grocery | Channel, data=wholesaled, 
            xlab="Grocery", ylab="Detergents_Paper",
            main="Scatter Plot: Horeca(Hotel/Restaurant/Cafe) vs. Retail Channel (Store)", 
            smoother=T, 
            lty=1, lwd=2, by.groups=T)

scatterplot( Detergents_Paper ~ Grocery | Region, data=wholesaled, 
            xlab="Grocery", ylab="Detergents_Paper", 
            main="Scatter Plot: Regions in Spain", 
            smoother=T, 
            lty=1, lwd=2, by.groups=T)

Pre-process the data and take a look at some basic Summary Statistics, also make the data completely random.

head(wholesale)
##   Channel Region Fresh Milk Grocery Frozen Detergents_Paper Delicassen
## 1       0      3 12669 9656    7561    214             2674       1338
## 2       0      3  7057 9810    9568   1762             3293       1776
## 3       0      3  6353 8808    7684   2405             3516       7844
## 4       1      3 13265 1196    4221   6404              507       1788
## 5       0      3 22615 5410    7198   3915             1777       5185
## 6       0      3  9413 8259    5126    666             1795       1451
str(wholesale)
## 'data.frame':    440 obs. of  8 variables:
##  $ Channel         : int  0 0 0 1 0 0 0 0 1 0 ...
##  $ Region          : int  3 3 3 3 3 3 3 3 3 3 ...
##  $ Fresh           : int  12669 7057 6353 13265 22615 9413 12126 7579 5963 6006 ...
##  $ Milk            : int  9656 9810 8808 1196 5410 8259 3199 4956 3648 11093 ...
##  $ Grocery         : int  7561 9568 7684 4221 7198 5126 6975 9426 6192 18881 ...
##  $ Frozen          : int  214 1762 2405 6404 3915 666 480 1669 425 1159 ...
##  $ Detergents_Paper: int  2674 3293 3516 507 1777 1795 3140 3321 1716 7425 ...
##  $ Delicassen      : int  1338 1776 7844 1788 5185 1451 545 2566 750 2098 ...
dim(wholesale)
## [1] 440   8
set.seed(9850)
random<- runif(nrow(wholesale))
wholesaler<-wholesale[order(random),]
str(wholesaler)
## 'data.frame':    440 obs. of  8 variables:
##  $ Channel         : int  1 1 0 0 1 1 0 0 0 1 ...
##  $ Region          : int  1 3 2 3 3 1 3 3 3 3 ...
##  $ Fresh           : int  2806 18073 1479 2932 7780 20893 4822 7823 1020 3157 ...
##  $ Milk            : int  10765 4613 14982 6459 2495 1222 6721 6245 8816 4888 ...
##  $ Grocery         : int  15538 3444 11924 7677 9464 2576 9170 6544 12121 2500 ...
##  $ Frozen          : int  1374 4324 662 2561 669 3975 993 4154 134 4477 ...
##  $ Detergents_Paper: int  5828 914 3891 4573 2518 737 4973 4074 4508 273 ...
##  $ Delicassen      : int  2388 715 3508 1386 501 3628 3637 964 1080 2165 ...
plot(wholesaler)

Fit the Logistic Regression Model

We will use Channel as our response variable and see if we can predict it as a binary response using logistic regression.

glm.fit=glm(Channel~Region + Fresh + Milk + Grocery + Frozen + Detergents_Paper + Delicassen,
            data=wholesaler,family=binomial)
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
summary(glm.fit)
## 
## Call:
## glm(formula = Channel ~ Region + Fresh + Milk + Grocery + Frozen + 
##     Detergents_Paper + Delicassen, family = binomial, data = wholesaler)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -3.2518  -0.0455   0.2178   0.3116   2.8899  
## 
## Coefficients:
##                    Estimate Std. Error z value Pr(>|z|)    
## (Intercept)       4.791e+00  8.494e-01   5.640 1.70e-08 ***
## Region           -4.178e-01  2.666e-01  -1.567   0.1172    
## Fresh            -4.322e-06  1.743e-05  -0.248   0.8042    
## Milk             -7.730e-05  5.535e-05  -1.397   0.1625    
## Grocery          -1.124e-04  6.037e-05  -1.862   0.0626 .  
## Frozen            1.549e-04  9.158e-05   1.692   0.0907 .  
## Detergents_Paper -8.592e-04  1.375e-04  -6.248 4.16e-10 ***
## Delicassen        7.844e-05  1.084e-04   0.724   0.4693    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 553.44  on 439  degrees of freedom
## Residual deviance: 201.29  on 432  degrees of freedom
## AIC: 217.29
## 
## Number of Fisher Scoring iterations: 7
#Not as much significance, as I would have liked, but we still have more to explore.  We do see a huge difference in the Residual deviance and a 7 unit change degrees of freedom.   

glm.probs=predict(glm.fit,type="response") 
glm.probs[1:8]
##       216       405       316       103        20       268       167 
## 0.0560333 0.9344336 0.1803171 0.2209215 0.5566009 0.9847290 0.1339443 
##        63 
## 0.3786789
glm.pred=ifelse(glm.probs>0.5,"Hotel/Cafe/Restaurant","Retail")
attach(wholesaler)
## The following objects are masked _by_ .GlobalEnv:
## 
##     Channel, Delicassen, Fresh, Frozen, Grocery, Milk, Region
table(glm.pred,Channel)
##                        Channel
## glm.pred                  0   1
##   Hotel/Cafe/Restaurant 100 205
##   Retail                 42  93
mean(glm.pred==Channel)
## [1] 0
#The diagonals is where do do correct classification, and the off diagonals is where we predict mistakes. We see many mistakes here. 

Our initinal model yields an AIC of 218.29, and a huge delta in the residual deviance from 553.44 to 201.29.

Make training and test set

testDF<-list(wholesale[1:8])
as.data.frame(testDF)
##     Channel Region  Fresh  Milk Grocery Frozen Detergents_Paper Delicassen
## 1         0      3  12669  9656    7561    214             2674       1338
## 2         0      3   7057  9810    9568   1762             3293       1776
## 3         0      3   6353  8808    7684   2405             3516       7844
## 4         1      3  13265  1196    4221   6404              507       1788
## 5         0      3  22615  5410    7198   3915             1777       5185
## 6         0      3   9413  8259    5126    666             1795       1451
## 7         0      3  12126  3199    6975    480             3140        545
## 8         0      3   7579  4956    9426   1669             3321       2566
## 9         1      3   5963  3648    6192    425             1716        750
## 10        0      3   6006 11093   18881   1159             7425       2098
## 11        0      3   3366  5403   12974   4400             5977       1744
## 12        0      3  13146  1124    4523   1420              549        497
## 13        0      3  31714 12319   11757    287             3881       2931
## 14        0      3  21217  6208   14982   3095             6707        602
## 15        0      3  24653  9465   12091    294             5058       2168
## 16        1      3  10253  1114    3821    397              964        412
## 17        0      3   1020  8816   12121    134             4508       1080
## 18        1      3   5876  6157    2933    839              370       4478
## 19        0      3  18601  6327   10099   2205             2767       3181
## 20        1      3   7780  2495    9464    669             2518        501
## 21        0      3  17546  4519    4602   1066             2259       2124
## 22        1      3   5567   871    2010   3383              375        569
## 23        1      3  31276  1917    4469   9408             2381       4334
## 24        0      3  26373 36423   22019   5154             4337      16523
## 25        0      3  22647  9776   13792   2915             4482       5778
## 26        0      3  16165  4230    7595    201             4003         57
## 27        1      3   9898   961    2861   3151              242        833
## 28        1      3  14276   803    3045    485              100        518
## 29        0      3   4113 20484   25957   1158             8604       5206
## 30        1      3  43088  2100    2609   1200             1107        823
## 31        1      3  18815  3610   11107   1148             2134       2963
## 32        1      3   2612  4339    3133   2088              820        985
## 33        1      3  21632  1318    2886    266              918        405
## 34        1      3  29729  4786    7326   6130              361       1083
## 35        1      3   1502  1979    2262    425              483        395
## 36        0      3    688  5491   11091    833             4239        436
## 37        1      3  29955  4362    5428   1729              862       4626
## 38        0      3  15168 10556   12477   1920             6506        714
## 39        0      3   4591 15729   16709     33             6956        433
## 40        1      3  56159   555     902  10002              212       2916
## 41        1      3  24025  4332    4757   9510             1145       5864
## 42        1      3  19176  3065    5956   2033             2575       2802
## 43        0      3  10850  7555   14961    188             6899         46
## 44        0      3    630 11095   23998    787             9529         72
## 45        0      3   9670  7027   10471    541             4618         65
## 46        0      3   5181 22044   21531   1740             7353       4985
## 47        0      3   3103 14069   21955   1668             6792       1452
## 48        0      3  44466 54259   55571   7782            24171       6465
## 49        0      3  11519  6152   10868    584             5121       1476
## 50        0      3   4967 21412   28921   1798            13583       1163
## 51        1      3   6269  1095    1980   3860              609       2162
## 52        1      3   3347  4051    6996    239             1538        301
## 53        0      3  40721  3916    5876    532             2587       1278
## 54        0      3    491 10473   11532    744             5611        224
## 55        1      3  27329  1449    1947   2436              204       1333
## 56        1      3   5264  3683    5005   1057             2024       1130
## 57        0      3   4098 29892   26866   2616            17740       1340
## 58        0      3   5417  9933   10487     38             7572       1282
## 59        1      3  13779  1970    1648    596              227        436
## 60        1      3   6137  5360    8040    129             3084       1603
## 61        0      3   8590  3045    7854     96             4095        225
## 62        0      3  35942 38369   59598   3254            26701       2017
## 63        0      3   7823  6245    6544   4154             4074        964
## 64        0      3   9396 11601   15775   2896             7677       1295
## 65        1      3   4760  1227    3250   3724             1247       1145
## 66        0      3     85 20959   45828     36            24231       1423
## 67        1      3      9  1534    7417    175             3468         27
## 68        0      3  19913  6759   13462   1256             5141        834
## 69        1      3   2446  7260    3993   5870              788       3095
## 70        1      3   8352  2820    1293    779              656        144
## 71        1      3  16705  2037    3202  10643              116       1365
## 72        1      3  18291  1266   21042   5373             4173      14472
## 73        1      3   4420  5139    2661   8872             1321        181
## 74        0      3  19899  5332    8713   8132              764        648
## 75        0      3   8190  6343    9794   1285             1901       1780
## 76        1      3  20398  1137       3   4407                3        975
## 77        1      3    717  3587    6532   7530              529        894
## 78        0      3  12205 12697   28540    869            12034       1009
## 79        1      3  10766  1175    2067   2096              301        167
## 80        1      3   1640  3259    3655    868             1202       1653
## 81        1      3   7005   829    3009    430              610        529
## 82        0      3    219  9540   14403    283             7818        156
## 83        0      3  10362  9232   11009    737             3537       2342
## 84        1      3  20874  1563    1783   2320              550        772
## 85        0      3  11867  3327    4814   1178             3837        120
## 86        0      3  16117 46197   92780   1026            40827       2944
## 87        0      3  22925 73498   32114    987            20070        903
## 88        1      3  43265  5025    8117   6312             1579      14351
## 89        1      3   7864   542    4042   9735              165         46
## 90        1      3  24904  3836    5330   3443              454       3178
## 91        1      3  11405   596    1638   3347               69        360
## 92        1      3  12754  2762    2530   8693              627       1117
## 93        0      3   9198 27472   32034   3232            18906       5130
## 94        1      3  11314  3090    2062  35009               71       2698
## 95        0      3   5626 12220   11323    206             5038        244
## 96        1      3      3  2920    6252    440              223        709
## 97        0      3     23  2616    8118    145             3874        217
## 98        1      3    403   254     610    774               54         63
## 99        1      3    503   112     778    895               56        132
## 100       1      3   9658  2182    1909   5639              215        323
## 101       0      3  11594  7779   12144   3252             8035       3029
## 102       0      3   1420 10810   16267   1593             6766       1838
## 103       0      3   2932  6459    7677   2561             4573       1386
## 104       1      3  56082  3504    8906  18028             1480       2498
## 105       1      3  14100  2132    3445   1336             1491        548
## 106       1      3  15587  1014    3970    910              139       1378
## 107       0      3   1454  6337   10704    133             6830       1831
## 108       0      3   8797 10646   14886   2471             8969       1438
## 109       0      3   1531  8397    6981    247             2505       1236
## 110       0      3   1406 16729   28986    673              836          3
## 111       1      3  11818  1648    1694   2276              169       1647
## 112       0      3  12579 11114   17569    805             6457       1519
## 113       1      3  19046  2770    2469   8853              483       2708
## 114       1      3  14438  2295    1733   3220              585       1561
## 115       1      3  18044  1080    2000   2555              118       1266
## 116       1      3  11134   793    2988   2715              276        610
## 117       1      3  11173  2521    3355   1517              310        222
## 118       1      3   6990  3880    5380   1647              319       1160
## 119       1      3  20049  1891    2362   5343              411        933
## 120       1      3   8258  2344    2147   3896              266        635
## 121       1      3  17160  1200    3412   2417              174       1136
## 122       1      3   4020  3234    1498   2395              264        255
## 123       1      3  12212   201     245   1991               25        860
## 124       0      3  11170 10769    8814   2194             1976        143
## 125       1      3  36050  1642    2961   4787              500       1621
## 126       1      3  76237  3473    7102  16538              778        918
## 127       1      3  19219  1840    1658   8195              349        483
## 128       0      3  21465  7243   10685    880             2386       2749
## 129       1      3    140  8847    3823    142             1062          3
## 130       1      3  42312   926    1510   1718              410       1819
## 131       1      3   7149  2428     699   6316              395        911
## 132       1      3   2101   589     314    346               70        310
## 133       1      3  14903  2032    2479    576              955        328
## 134       1      3   9434  1042    1235    436              256        396
## 135       1      3   7388  1882    2174    720               47        537
## 136       1      3   6300  1289    2591   1170              199        326
## 137       1      3   4625  8579    7030   4575             2447       1542
## 138       1      3   3087  8080    8282    661              721         36
## 139       1      3  13537  4257    5034    155              249       3271
## 140       1      3   5387  4979    3343    825              637        929
## 141       1      3  17623  4280    7305   2279              960       2616
## 142       1      3  30379 13252    5189    321               51       1450
## 143       1      3  37036  7152    8253   2995               20          3
## 144       1      3  10405  1596    1096   8425              399        318
## 145       1      3  18827  3677    1988    118              516        201
## 146       0      3  22039  8384   34792     42            12591       4430
## 147       1      3   7769  1936    2177    926               73        520
## 148       1      3   9203  3373    2707   1286             1082        526
## 149       1      3   5924   584     542   4052              283        434
## 150       1      3  31812  1433    1651    800              113       1440
## 151       1      3  16225  1825    1765    853              170       1067
## 152       1      3   1289  3328    2022    531              255       1774
## 153       1      3  18840  1371    3135   3001              352        184
## 154       1      3   3463  9250    2368    779              302       1627
## 155       1      3    622    55     137     75                7          8
## 156       0      3   1989 10690   19460    233            11577       2153
## 157       0      3   3830  5291   14855    317             6694       3182
## 158       1      3  17773  1366    2474   3378              811        418
## 159       0      3   2861  6570    9618    930             4004       1682
## 160       0      3    355  7704   14682    398             8077        303
## 161       0      3   1725  3651   12822    824             4424       2157
## 162       1      3  12434   540     283   1092                3       2233
## 163       1      3  15177  2024    3810   2665              232        610
## 164       0      3   5531 15726   26870   2367            13726        446
## 165       0      3   5224  7603    8584   2540             3674        238
## 166       0      3  15615 12653   19858   4425             7108       2379
## 167       0      3   4822  6721    9170    993             4973       3637
## 168       1      3   2926  3195    3268    405             1680        693
## 169       1      3   5809   735     803   1393               79        429
## 170       1      3   5414   717    2155   2399               69        750
## 171       0      3    260  8675   13430   1116             7015        323
## 172       0      3    200 25862   19816    651             8773       6250
## 173       1      3    955  5479    6536    333             2840        707
## 174       0      3    514  7677   19805    937             9836        716
## 175       1      3    286  1208    5241   2515              153       1442
## 176       0      3   2343  7845   11874     52             4196       1697
## 177       1      3  45640  6958    6536   7368             1532        230
## 178       1      3  12759  7330    4533   1752               20       2631
## 179       1      3  11002  7075    4945   1152              120        395
## 180       1      3   3157  4888    2500   4477              273       2165
## 181       1      3  12356  6036    8887    402             1382       2794
## 182       1      3 112151 29627   18148  16745             4948       8550
## 183       1      3    694  8533   10518    443             6907        156
## 184       1      3  36847 43950   20170  36534              239      47943
## 185       1      3    327   918    4710     74              334         11
## 186       1      3   8170  6448    1139   2181               58        247
## 187       1      3   3009   521     854   3470              949        727
## 188       1      3   2438  8002    9819   6269             3459          3
## 189       0      3   8040  7639   11687   2758             6839        404
## 190       0      3    834 11577   11522    275             4027       1856
## 191       1      3  16936  6250    1981   7332              118         64
## 192       1      3  13624   295    1381    890               43         84
## 193       1      3   5509  1461    2251    547              187        409
## 194       0      3    180  3485   20292    959             5618        666
## 195       1      3   7107  1012    2974    806              355       1142
## 196       1      3  17023  5139    5230   7888              330       1755
## 197       1      1  30624  7209    4897  18711              763       2876
## 198       0      1   2427  7097   10391   1127             4314       1468
## 199       1      1  11686  2154    6824   3527              592        697
## 200       1      1   9670  2280    2112    520              402        347
## 201       0      1   3067 13240   23127   3941             9959        731
## 202       0      1   4484 14399   24708   3549            14235       1681
## 203       1      1  25203 11487    9490   5065              284       6854
## 204       1      1    583   685    2216    469              954         18
## 205       1      1   1956   891    5226   1383                5       1328
## 206       0      1   1107 11711   23596    955             9265        710
## 207       1      1   6373   780     950    878              288        285
## 208       0      1   2541  4737    6089   2946             5316        120
## 209       1      1   1537  3748    5838   1859             3381        806
## 210       0      1   5550 12729   16767    864            12420        797
## 211       1      1  18567  1895    1393   1801              244       2100
## 212       0      1  12119 28326   39694   4736            19410       2870
## 213       1      1   7291  1012    2062   1291              240       1775
## 214       1      1   3317  6602    6861   1329             3961       1215
## 215       0      1   2362  6551   11364    913             5957        791
## 216       1      1   2806 10765   15538   1374             5828       2388
## 217       0      1   2532 16599   36486    179            13308        674
## 218       1      1  18044  1475    2046   2532              130       1158
## 219       0      1     18  7504   15205   1285             4797       6372
## 220       1      1   4155   367    1390   2306               86        130
## 221       1      1  14755   899    1382   1765               56        749
## 222       1      1   5396  7503   10646     91             4167        239
## 223       1      1   5041  1115    2856   7496              256        375
## 224       0      1   2790  2527    5265   5612              788       1360
## 225       1      1   7274   659    1499    784               70        659
## 226       1      1  12680  3243    4157    660              761        786
## 227       0      1  20782  5921    9212   1759             2568       1553
## 228       1      1   4042  2204    1563   2286              263        689
## 229       1      1   1869   577     572    950             4762        203
## 230       1      1   8656  2746    2501   6845              694        980
## 231       0      1  11072  5989    5615   8321              955       2137
## 232       1      1   2344 10678    3828   1439             1566        490
## 233       1      1  25962  1780    3838    638              284        834
## 234       1      1    964  4984    3316    937              409          7
## 235       1      1  15603  2703    3833   4260              325       2563
## 236       1      1   1838  6380    2824   1218             1216        295
## 237       1      1   8635   820    3047   2312              415        225
## 238       1      1  18692  3838     593   4634               28       1215
## 239       1      1   7363   475     585   1112               72        216
## 240       1      1  47493  2567    3779   5243              828       2253
## 241       1      1  22096  3575    7041  11422              343       2564
## 242       1      1  24929  1801    2475   2216              412       1047
## 243       1      1  18226   659    2914   3752              586        578
## 244       1      1  11210  3576    5119    561             1682       2398
## 245       1      1   6202  7775   10817   1183             3143       1970
## 246       0      1   3062  6154   13916    230             8933       2784
## 247       1      1   8885  2428    1777   1777              430        610
## 248       1      1  13569   346     489   2077               44        659
## 249       1      1  15671  5279    2406    559              562        572
## 250       1      1   8040  3795    2070   6340              918        291
## 251       1      1   3191  1993    1799   1730              234        710
## 252       0      1   6134 23133   33586   6746            18594       5121
## 253       1      1   6623  1860    4740   7683              205       1693
## 254       1      1  29526  7961   16966    432              363       1391
## 255       1      1  10379 17972    4748   4686             1547       3265
## 256       1      1  31614   489    1495   3242              111        615
## 257       1      1  11092  5008    5249    453              392        373
## 258       1      1   8475  1931    1883   5004             3593        987
## 259       1      1  56083  4563    2124   6422              730       3321
## 260       1      1  53205  4959    7336   3012              967        818
## 261       1      1   9193  4885    2157    327              780        548
## 262       1      1   7858  1110    1094   6818               49        287
## 263       1      1  23257  1372    1677    982              429        655
## 264       1      1   2153  1115    6684   4324             2894        411
## 265       0      1   1073  9679   15445     61             5980       1265
## 266       1      1   5909 23527   13699  10155              830       3636
## 267       0      1    572  9763   22182   2221             4882       2563
## 268       1      1  20893  1222    2576   3975              737       3628
## 269       0      1  11908  8053   19847   1069             6374        698
## 270       1      1  15218   258    1138   2516              333        204
## 271       1      1   4720  1032     975   5500              197         56
## 272       1      1   2083  5007    1563   1120              147       1550
## 273       1      1    514  8323    6869    529               93       1040
## 274       1      3  36817  3045    1493   4802              210       1824
## 275       1      3    894  1703    1841    744              759       1153
## 276       1      3    680  1610     223    862               96        379
## 277       1      3  27901  3749    6964   4479              603       2503
## 278       1      3   9061   829     683  16919              621        139
## 279       1      3  11693  2317    2543   5845              274       1409
## 280       0      3  17360  6200    9694   1293             3620       1721
## 281       1      3   3366  2884    2431    977              167       1104
## 282       0      3  12238  7108    6235   1093             2328       2079
## 283       1      3  49063  3965    4252   5970             1041       1404
## 284       1      3  25767  3613    2013  10303              314       1384
## 285       1      3  68951  4411   12609   8692              751       2406
## 286       1      3  40254   640    3600   1042              436         18
## 287       1      3   7149  2247    1242   1619             1226        128
## 288       1      3  15354  2102    2828   8366              386       1027
## 289       1      3  16260   594    1296    848              445        258
## 290       1      3  42786   286     471   1388               32         22
## 291       1      3   2708  2160    2642    502              965       1522
## 292       1      3   6022  3354    3261   2507              212        686
## 293       1      3   2838  3086    4329   3838              825       1060
## 294       0      2   3996 11103   12469    902             5952        741
## 295       1      2  21273  2013    6550    909              811       1854
## 296       0      2   7588  1897    5234    417             2208        254
## 297       1      2  19087  1304    3643   3045              710        898
## 298       0      2   8090  3199    6986   1455             3712        531
## 299       0      2   6758  4560    9965    934             4538       1037
## 300       1      2    444   879    2060    264              290        259
## 301       0      2  16448  6243    6360    824             2662       2005
## 302       0      2   5283 13316   20399   1809             8752        172
## 303       0      2   2886  5302    9785    364             6236        555
## 304       0      2   2599  3688   13829    492            10069         59
## 305       0      2    161  7460   24773    617            11783       2410
## 306       0      2    243 12939    8852    799             3909        211
## 307       0      2   6468 12867   21570   1840             7558       1543
## 308       1      2  17327  2374    2842   1149              351        925
## 309       1      2   6987  1020    3007    416              257        656
## 310       0      2    918 20655   13567   1465             6846        806
## 311       1      2   7034  1492    2405  12569              299       1117
## 312       1      2  29635  2335    8280   3046              371        117
## 313       0      2   2137  3737   19172   1274            17120        142
## 314       1      2   9784   925    2405   4447              183        297
## 315       1      2  10617  1795    7647   1483              857       1233
## 316       0      2   1479 14982   11924    662             3891       3508
## 317       1      2   7127  1375    2201   2679               83       1059
## 318       1      2   1182  3088    6114    978              821       1637
## 319       1      2  11800  2713    3558   2121              706         51
## 320       0      2   9759 25071   17645   1128            12408       1625
## 321       1      2   1774  3696    2280    514              275        834
## 322       1      2   9155  1897    5167   2714              228       1113
## 323       1      2  15881   713    3315   3703             1470        229
## 324       1      2  13360   944   11593    915             1679        573
## 325       1      2  25977  3587    2464   2369              140       1092
## 326       1      2  32717 16784   13626  60869             1272       5609
## 327       1      2   4414  1610    1431   3498              387        834
## 328       1      2    542   899    1664    414               88        522
## 329       1      2  16933  2209    3389   7849              210       1534
## 330       1      2   5113  1486    4583   5127              492        739
## 331       1      2   9790  1786    5109   3570              182       1043
## 332       0      2  11223 14881   26839   1234             9606       1102
## 333       1      2  22321  3216    1447   2208              178       2602
## 334       0      2   8565  4980   67298    131            38102       1215
## 335       0      2  16823   928    2743  11559              332       3486
## 336       0      2  27082  6817   10790   1365             4111       2139
## 337       1      2  13970  1511    1330    650              146        778
## 338       1      2   9351  1347    2611   8170              442        868
## 339       1      2      3   333    7021  15601               15        550
## 340       1      2   2617  1188    5332   9584              573       1942
## 341       0      3    381  4025    9670    388             7271       1371
## 342       0      3   2320  5763   11238    767             5162       2158
## 343       1      3    255  5758    5923    349             4595       1328
## 344       0      3   1689  6964   26316   1456            15469         37
## 345       1      3   3043  1172    1763   2234              217        379
## 346       1      3   1198  2602    8335    402             3843        303
## 347       0      3   2771  6939   15541   2693             6600       1115
## 348       0      3  27380  7184   12311   2809             4621       1022
## 349       1      3   3428  2380    2028   1341             1184        665
## 350       0      3   5981 14641   20521   2005            12218        445
## 351       1      3   3521  1099    1997   1796              173        995
## 352       0      3   1210 10044   22294   1741            12638       3137
## 353       1      3    608  1106    1533    830               90        195
## 354       0      3    117  6264   21203    228             8682       1111
## 355       1      3  14039  7393    2548   6386             1333       2341
## 356       1      3    190   727    2012    245              184        127
## 357       1      3  22686   134     218   3157                9        548
## 358       0      3     37  1275   22272    137             6747        110
## 359       1      3    759 18664    1660   6114              536       4100
## 360       1      3    796  5878    2109    340              232        776
## 361       1      3  19746  2872    2006   2601              468        503
## 362       1      3   4734   607     864   1206              159        405
## 363       1      3   2121  1601    2453    560              179        712
## 364       1      3   4627   997    4438    191             1335        314
## 365       1      3   2615   873    1524   1103              514        468
## 366       0      3   4692  6128    8025   1619             4515       3105
## 367       1      3   9561  2217    1664   1173              222        447
## 368       1      3   3477   894     534   1457              252        342
## 369       1      3  22335  1196    2406   2046              101        558
## 370       1      3   6211   337     683   1089               41        296
## 371       0      3  39679  3944    4955   1364              523       2235
## 372       1      3  20105  1887    1939   8164              716        790
## 373       1      3   3884  3801    1641    876              397       4829
## 374       0      3  15076  6257    7398   1504             1916       3113
## 375       1      3   6338  2256    1668   1492              311        686
## 376       1      3   5841  1450    1162    597              476         70
## 377       0      3   3136  8630   13586   5641             4666       1426
## 378       1      3  38793  3154    2648   1034               96       1242
## 379       1      3   3225  3294    1902    282               68       1114
## 380       0      3   4048  5164   10391    130              813        179
## 381       1      3  28257   944    2146   3881              600        270
## 382       1      3  17770  4591    1617   9927              246        532
## 383       1      3  34454  7435    8469   2540             1711       2893
## 384       1      3   1821  1364    3450   4006              397        361
## 385       1      3  10683 21858   15400   3635              282       5120
## 386       1      3  11635   922    1614   2583              192       1068
## 387       1      3   1206  3620    2857   1945              353        967
## 388       1      3  20918  1916    1573   1960              231        961
## 389       1      3   9785   848    1172   1677              200        406
## 390       1      3   9385  1530    1422   3019              227        684
## 391       1      3   3352  1181    1328   5502              311       1000
## 392       1      3   2647  2761    2313    907               95       1827
## 393       1      3    518  4180    3600    659              122        654
## 394       1      3  23632  6730    3842   8620              385        819
## 395       1      3  12377   865    3204   1398              149        452
## 396       1      3   9602  1316    1263   2921              841        290
## 397       0      3   4515 11991    9345   2644             3378       2213
## 398       1      3  11535  1666    1428   6838               64        743
## 399       1      3  11442  1032     582   5390               74        247
## 400       1      3   9612   577     935   1601              469        375
## 401       1      3   4446   906    1238   3576              153       1014
## 402       1      3  27167  2801    2128  13223               92       1902
## 403       1      3  26539  4753    5091    220               10        340
## 404       1      3  25606 11006    4604    127              632        288
## 405       1      3  18073  4613    3444   4324              914        715
## 406       1      3   6884  1046    1167   2069              593        378
## 407       1      3  25066  5010    5026   9806             1092        960
## 408       0      3   7362 12844   18683   2854             7883        553
## 409       0      3   8257  3880    6407   1646             2730        344
## 410       1      3   8708  3634    6100   2349             2123       5137
## 411       1      3   6633  2096    4563   1389             1860       1892
## 412       1      3   2126  3289    3281   1535              235       4365
## 413       1      3     97  3605   12400     98             2970         62
## 414       1      3   4983  4859    6633  17866              912       2435
## 415       1      3   5969  1990    3417   5679             1135        290
## 416       0      3   7842  6046    8552   1691             3540       1874
## 417       0      3   4389 10940   10908    848             6728        993
## 418       1      3   5065  5499   11055    364             3485       1063
## 419       0      3    660  8494   18622    133             6740        776
## 420       1      3   8861  3783    2223    633             1580       1521
## 421       1      3   4456  5266   13227     25             6818       1393
## 422       0      3  17063  4847    9053   1031             3415       1784
## 423       1      3  26400  1377    4172    830              948       1218
## 424       0      3  17565  3686    4657   1059             1803        668
## 425       0      3  16980  2884   12232    874             3213        249
## 426       1      3  11243  2408    2593  15348              108       1886
## 427       1      3  13134  9347   14316   3141             5079       1894
## 428       1      3  31012 16687    5429  15082              439       1163
## 429       1      3   3047  5970    4910   2198              850        317
## 430       1      3   8607  1750    3580     47               84       2501
## 431       1      3   3097  4230   16483    575              241       2080
## 432       1      3   8533  5506    5160  13486             1377       1498
## 433       1      3  21117  1162    4754    269             1328        395
## 434       1      3   1982  3218    1493   1541              356       1449
## 435       1      3  16731  3922    7994    688             2371        838
## 436       1      3  29703 12051   16027  13135              182       2204
## 437       1      3  39228  1431     764   4510               93       2346
## 438       0      3  14531 15488   30243    437            14841       1867
## 439       1      3  10290  1981    2232   1038              168       2125
## 440       1      3   2787  1698    2510     65              477         52
ind <- sample(2, nrow(wholesale), replace=TRUE, prob=c(0.7,0.3))
trainData <- wholesale[ind==1,]
testData <- wholesale[ind==2,]
trainData
##     Channel Region  Fresh  Milk Grocery Frozen Detergents_Paper Delicassen
## 2         0      3   7057  9810    9568   1762             3293       1776
## 3         0      3   6353  8808    7684   2405             3516       7844
## 4         1      3  13265  1196    4221   6404              507       1788
## 5         0      3  22615  5410    7198   3915             1777       5185
## 6         0      3   9413  8259    5126    666             1795       1451
## 7         0      3  12126  3199    6975    480             3140        545
## 8         0      3   7579  4956    9426   1669             3321       2566
## 9         1      3   5963  3648    6192    425             1716        750
## 10        0      3   6006 11093   18881   1159             7425       2098
## 11        0      3   3366  5403   12974   4400             5977       1744
## 12        0      3  13146  1124    4523   1420              549        497
## 13        0      3  31714 12319   11757    287             3881       2931
## 14        0      3  21217  6208   14982   3095             6707        602
## 15        0      3  24653  9465   12091    294             5058       2168
## 16        1      3  10253  1114    3821    397              964        412
## 17        0      3   1020  8816   12121    134             4508       1080
## 19        0      3  18601  6327   10099   2205             2767       3181
## 20        1      3   7780  2495    9464    669             2518        501
## 25        0      3  22647  9776   13792   2915             4482       5778
## 26        0      3  16165  4230    7595    201             4003         57
## 27        1      3   9898   961    2861   3151              242        833
## 28        1      3  14276   803    3045    485              100        518
## 29        0      3   4113 20484   25957   1158             8604       5206
## 30        1      3  43088  2100    2609   1200             1107        823
## 32        1      3   2612  4339    3133   2088              820        985
## 33        1      3  21632  1318    2886    266              918        405
## 34        1      3  29729  4786    7326   6130              361       1083
## 37        1      3  29955  4362    5428   1729              862       4626
## 38        0      3  15168 10556   12477   1920             6506        714
## 39        0      3   4591 15729   16709     33             6956        433
## 40        1      3  56159   555     902  10002              212       2916
## 42        1      3  19176  3065    5956   2033             2575       2802
## 43        0      3  10850  7555   14961    188             6899         46
## 45        0      3   9670  7027   10471    541             4618         65
## 46        0      3   5181 22044   21531   1740             7353       4985
## 48        0      3  44466 54259   55571   7782            24171       6465
## 51        1      3   6269  1095    1980   3860              609       2162
## 52        1      3   3347  4051    6996    239             1538        301
## 54        0      3    491 10473   11532    744             5611        224
## 57        0      3   4098 29892   26866   2616            17740       1340
## 60        1      3   6137  5360    8040    129             3084       1603
## 61        0      3   8590  3045    7854     96             4095        225
## 62        0      3  35942 38369   59598   3254            26701       2017
## 63        0      3   7823  6245    6544   4154             4074        964
## 64        0      3   9396 11601   15775   2896             7677       1295
## 65        1      3   4760  1227    3250   3724             1247       1145
## 67        1      3      9  1534    7417    175             3468         27
## 68        0      3  19913  6759   13462   1256             5141        834
## 69        1      3   2446  7260    3993   5870              788       3095
## 70        1      3   8352  2820    1293    779              656        144
## 74        0      3  19899  5332    8713   8132              764        648
## 75        0      3   8190  6343    9794   1285             1901       1780
## 76        1      3  20398  1137       3   4407                3        975
## 77        1      3    717  3587    6532   7530              529        894
## 78        0      3  12205 12697   28540    869            12034       1009
## 81        1      3   7005   829    3009    430              610        529
## 82        0      3    219  9540   14403    283             7818        156
## 83        0      3  10362  9232   11009    737             3537       2342
## 84        1      3  20874  1563    1783   2320              550        772
## 88        1      3  43265  5025    8117   6312             1579      14351
## 91        1      3  11405   596    1638   3347               69        360
## 92        1      3  12754  2762    2530   8693              627       1117
## 93        0      3   9198 27472   32034   3232            18906       5130
## 94        1      3  11314  3090    2062  35009               71       2698
## 97        0      3     23  2616    8118    145             3874        217
## 98        1      3    403   254     610    774               54         63
## 99        1      3    503   112     778    895               56        132
## 100       1      3   9658  2182    1909   5639              215        323
## 102       0      3   1420 10810   16267   1593             6766       1838
## 104       1      3  56082  3504    8906  18028             1480       2498
## 108       0      3   8797 10646   14886   2471             8969       1438
## 109       0      3   1531  8397    6981    247             2505       1236
## 110       0      3   1406 16729   28986    673              836          3
## 112       0      3  12579 11114   17569    805             6457       1519
## 113       1      3  19046  2770    2469   8853              483       2708
## 114       1      3  14438  2295    1733   3220              585       1561
## 115       1      3  18044  1080    2000   2555              118       1266
## 117       1      3  11173  2521    3355   1517              310        222
## 118       1      3   6990  3880    5380   1647              319       1160
## 119       1      3  20049  1891    2362   5343              411        933
## 120       1      3   8258  2344    2147   3896              266        635
## 121       1      3  17160  1200    3412   2417              174       1136
## 122       1      3   4020  3234    1498   2395              264        255
## 123       1      3  12212   201     245   1991               25        860
## 124       0      3  11170 10769    8814   2194             1976        143
## 126       1      3  76237  3473    7102  16538              778        918
## 128       0      3  21465  7243   10685    880             2386       2749
## 129       1      3    140  8847    3823    142             1062          3
## 130       1      3  42312   926    1510   1718              410       1819
## 131       1      3   7149  2428     699   6316              395        911
## 132       1      3   2101   589     314    346               70        310
## 133       1      3  14903  2032    2479    576              955        328
## 136       1      3   6300  1289    2591   1170              199        326
## 137       1      3   4625  8579    7030   4575             2447       1542
## 139       1      3  13537  4257    5034    155              249       3271
## 140       1      3   5387  4979    3343    825              637        929
## 141       1      3  17623  4280    7305   2279              960       2616
## 142       1      3  30379 13252    5189    321               51       1450
## 143       1      3  37036  7152    8253   2995               20          3
## 144       1      3  10405  1596    1096   8425              399        318
## 145       1      3  18827  3677    1988    118              516        201
## 148       1      3   9203  3373    2707   1286             1082        526
## 149       1      3   5924   584     542   4052              283        434
## 151       1      3  16225  1825    1765    853              170       1067
## 152       1      3   1289  3328    2022    531              255       1774
## 154       1      3   3463  9250    2368    779              302       1627
## 155       1      3    622    55     137     75                7          8
## 157       0      3   3830  5291   14855    317             6694       3182
## 160       0      3    355  7704   14682    398             8077        303
## 163       1      3  15177  2024    3810   2665              232        610
## 165       0      3   5224  7603    8584   2540             3674        238
## 168       1      3   2926  3195    3268    405             1680        693
## 169       1      3   5809   735     803   1393               79        429
## 170       1      3   5414   717    2155   2399               69        750
## 171       0      3    260  8675   13430   1116             7015        323
## 173       1      3    955  5479    6536    333             2840        707
## 174       0      3    514  7677   19805    937             9836        716
## 175       1      3    286  1208    5241   2515              153       1442
## 176       0      3   2343  7845   11874     52             4196       1697
## 177       1      3  45640  6958    6536   7368             1532        230
## 178       1      3  12759  7330    4533   1752               20       2631
## 179       1      3  11002  7075    4945   1152              120        395
## 181       1      3  12356  6036    8887    402             1382       2794
## 182       1      3 112151 29627   18148  16745             4948       8550
## 183       1      3    694  8533   10518    443             6907        156
## 184       1      3  36847 43950   20170  36534              239      47943
## 186       1      3   8170  6448    1139   2181               58        247
## 187       1      3   3009   521     854   3470              949        727
## 188       1      3   2438  8002    9819   6269             3459          3
## 189       0      3   8040  7639   11687   2758             6839        404
## 191       1      3  16936  6250    1981   7332              118         64
## 192       1      3  13624   295    1381    890               43         84
## 193       1      3   5509  1461    2251    547              187        409
## 194       0      3    180  3485   20292    959             5618        666
## 195       1      3   7107  1012    2974    806              355       1142
## 196       1      3  17023  5139    5230   7888              330       1755
## 197       1      1  30624  7209    4897  18711              763       2876
## 199       1      1  11686  2154    6824   3527              592        697
## 201       0      1   3067 13240   23127   3941             9959        731
## 202       0      1   4484 14399   24708   3549            14235       1681
## 203       1      1  25203 11487    9490   5065              284       6854
## 204       1      1    583   685    2216    469              954         18
## 205       1      1   1956   891    5226   1383                5       1328
## 206       0      1   1107 11711   23596    955             9265        710
## 207       1      1   6373   780     950    878              288        285
## 208       0      1   2541  4737    6089   2946             5316        120
## 209       1      1   1537  3748    5838   1859             3381        806
## 211       1      1  18567  1895    1393   1801              244       2100
## 213       1      1   7291  1012    2062   1291              240       1775
## 215       0      1   2362  6551   11364    913             5957        791
## 216       1      1   2806 10765   15538   1374             5828       2388
## 219       0      1     18  7504   15205   1285             4797       6372
## 220       1      1   4155   367    1390   2306               86        130
## 221       1      1  14755   899    1382   1765               56        749
## 224       0      1   2790  2527    5265   5612              788       1360
## 225       1      1   7274   659    1499    784               70        659
## 227       0      1  20782  5921    9212   1759             2568       1553
## 228       1      1   4042  2204    1563   2286              263        689
## 231       0      1  11072  5989    5615   8321              955       2137
## 233       1      1  25962  1780    3838    638              284        834
## 235       1      1  15603  2703    3833   4260              325       2563
## 237       1      1   8635   820    3047   2312              415        225
## 238       1      1  18692  3838     593   4634               28       1215
## 240       1      1  47493  2567    3779   5243              828       2253
## 242       1      1  24929  1801    2475   2216              412       1047
## 243       1      1  18226   659    2914   3752              586        578
## 246       0      1   3062  6154   13916    230             8933       2784
## 247       1      1   8885  2428    1777   1777              430        610
## 249       1      1  15671  5279    2406    559              562        572
## 250       1      1   8040  3795    2070   6340              918        291
## 252       0      1   6134 23133   33586   6746            18594       5121
## 254       1      1  29526  7961   16966    432              363       1391
## 256       1      1  31614   489    1495   3242              111        615
## 259       1      1  56083  4563    2124   6422              730       3321
## 261       1      1   9193  4885    2157    327              780        548
## 264       1      1   2153  1115    6684   4324             2894        411
## 265       0      1   1073  9679   15445     61             5980       1265
## 266       1      1   5909 23527   13699  10155              830       3636
## 268       1      1  20893  1222    2576   3975              737       3628
## 269       0      1  11908  8053   19847   1069             6374        698
## 270       1      1  15218   258    1138   2516              333        204
## 272       1      1   2083  5007    1563   1120              147       1550
## 273       1      1    514  8323    6869    529               93       1040
## 276       1      3    680  1610     223    862               96        379
## 277       1      3  27901  3749    6964   4479              603       2503
## 278       1      3   9061   829     683  16919              621        139
## 279       1      3  11693  2317    2543   5845              274       1409
## 282       0      3  12238  7108    6235   1093             2328       2079
## 283       1      3  49063  3965    4252   5970             1041       1404
## 284       1      3  25767  3613    2013  10303              314       1384
## 286       1      3  40254   640    3600   1042              436         18
## 287       1      3   7149  2247    1242   1619             1226        128
## 288       1      3  15354  2102    2828   8366              386       1027
## 289       1      3  16260   594    1296    848              445        258
## 291       1      3   2708  2160    2642    502              965       1522
## 293       1      3   2838  3086    4329   3838              825       1060
## 295       1      2  21273  2013    6550    909              811       1854
## 298       0      2   8090  3199    6986   1455             3712        531
## 299       0      2   6758  4560    9965    934             4538       1037
## 301       0      2  16448  6243    6360    824             2662       2005
## 302       0      2   5283 13316   20399   1809             8752        172
## 305       0      2    161  7460   24773    617            11783       2410
## 306       0      2    243 12939    8852    799             3909        211
## 310       0      2    918 20655   13567   1465             6846        806
## 311       1      2   7034  1492    2405  12569              299       1117
## 312       1      2  29635  2335    8280   3046              371        117
## 314       1      2   9784   925    2405   4447              183        297
## 316       0      2   1479 14982   11924    662             3891       3508
## 317       1      2   7127  1375    2201   2679               83       1059
## 319       1      2  11800  2713    3558   2121              706         51
## 320       0      2   9759 25071   17645   1128            12408       1625
## 321       1      2   1774  3696    2280    514              275        834
## 322       1      2   9155  1897    5167   2714              228       1113
## 325       1      2  25977  3587    2464   2369              140       1092
## 326       1      2  32717 16784   13626  60869             1272       5609
## 327       1      2   4414  1610    1431   3498              387        834
## 328       1      2    542   899    1664    414               88        522
## 329       1      2  16933  2209    3389   7849              210       1534
## 330       1      2   5113  1486    4583   5127              492        739
## 331       1      2   9790  1786    5109   3570              182       1043
## 333       1      2  22321  3216    1447   2208              178       2602
## 334       0      2   8565  4980   67298    131            38102       1215
## 336       0      2  27082  6817   10790   1365             4111       2139
## 338       1      2   9351  1347    2611   8170              442        868
## 339       1      2      3   333    7021  15601               15        550
## 340       1      2   2617  1188    5332   9584              573       1942
## 341       0      3    381  4025    9670    388             7271       1371
## 342       0      3   2320  5763   11238    767             5162       2158
## 343       1      3    255  5758    5923    349             4595       1328
## 345       1      3   3043  1172    1763   2234              217        379
## 347       0      3   2771  6939   15541   2693             6600       1115
## 348       0      3  27380  7184   12311   2809             4621       1022
## 349       1      3   3428  2380    2028   1341             1184        665
## 350       0      3   5981 14641   20521   2005            12218        445
## 351       1      3   3521  1099    1997   1796              173        995
## 352       0      3   1210 10044   22294   1741            12638       3137
## 353       1      3    608  1106    1533    830               90        195
## 354       0      3    117  6264   21203    228             8682       1111
## 355       1      3  14039  7393    2548   6386             1333       2341
## 356       1      3    190   727    2012    245              184        127
## 357       1      3  22686   134     218   3157                9        548
## 358       0      3     37  1275   22272    137             6747        110
## 360       1      3    796  5878    2109    340              232        776
## 361       1      3  19746  2872    2006   2601              468        503
## 362       1      3   4734   607     864   1206              159        405
## 364       1      3   4627   997    4438    191             1335        314
## 365       1      3   2615   873    1524   1103              514        468
## 366       0      3   4692  6128    8025   1619             4515       3105
## 367       1      3   9561  2217    1664   1173              222        447
## 368       1      3   3477   894     534   1457              252        342
## 371       0      3  39679  3944    4955   1364              523       2235
## 373       1      3   3884  3801    1641    876              397       4829
## 375       1      3   6338  2256    1668   1492              311        686
## 376       1      3   5841  1450    1162    597              476         70
## 377       0      3   3136  8630   13586   5641             4666       1426
## 378       1      3  38793  3154    2648   1034               96       1242
## 379       1      3   3225  3294    1902    282               68       1114
## 380       0      3   4048  5164   10391    130              813        179
## 381       1      3  28257   944    2146   3881              600        270
## 382       1      3  17770  4591    1617   9927              246        532
## 385       1      3  10683 21858   15400   3635              282       5120
## 387       1      3   1206  3620    2857   1945              353        967
## 388       1      3  20918  1916    1573   1960              231        961
## 389       1      3   9785   848    1172   1677              200        406
## 390       1      3   9385  1530    1422   3019              227        684
## 391       1      3   3352  1181    1328   5502              311       1000
## 392       1      3   2647  2761    2313    907               95       1827
## 393       1      3    518  4180    3600    659              122        654
## 394       1      3  23632  6730    3842   8620              385        819
## 395       1      3  12377   865    3204   1398              149        452
## 396       1      3   9602  1316    1263   2921              841        290
## 397       0      3   4515 11991    9345   2644             3378       2213
## 398       1      3  11535  1666    1428   6838               64        743
## 399       1      3  11442  1032     582   5390               74        247
## 400       1      3   9612   577     935   1601              469        375
## 401       1      3   4446   906    1238   3576              153       1014
## 402       1      3  27167  2801    2128  13223               92       1902
## 403       1      3  26539  4753    5091    220               10        340
## 404       1      3  25606 11006    4604    127              632        288
## 405       1      3  18073  4613    3444   4324              914        715
## 406       1      3   6884  1046    1167   2069              593        378
## 407       1      3  25066  5010    5026   9806             1092        960
## 409       0      3   8257  3880    6407   1646             2730        344
## 411       1      3   6633  2096    4563   1389             1860       1892
## 412       1      3   2126  3289    3281   1535              235       4365
## 413       1      3     97  3605   12400     98             2970         62
## 414       1      3   4983  4859    6633  17866              912       2435
## 415       1      3   5969  1990    3417   5679             1135        290
## 416       0      3   7842  6046    8552   1691             3540       1874
## 418       1      3   5065  5499   11055    364             3485       1063
## 419       0      3    660  8494   18622    133             6740        776
## 420       1      3   8861  3783    2223    633             1580       1521
## 421       1      3   4456  5266   13227     25             6818       1393
## 422       0      3  17063  4847    9053   1031             3415       1784
## 423       1      3  26400  1377    4172    830              948       1218
## 424       0      3  17565  3686    4657   1059             1803        668
## 425       0      3  16980  2884   12232    874             3213        249
## 426       1      3  11243  2408    2593  15348              108       1886
## 427       1      3  13134  9347   14316   3141             5079       1894
## 428       1      3  31012 16687    5429  15082              439       1163
## 429       1      3   3047  5970    4910   2198              850        317
## 431       1      3   3097  4230   16483    575              241       2080
## 433       1      3  21117  1162    4754    269             1328        395
## 434       1      3   1982  3218    1493   1541              356       1449
## 435       1      3  16731  3922    7994    688             2371        838
## 436       1      3  29703 12051   16027  13135              182       2204
## 437       1      3  39228  1431     764   4510               93       2346
## 438       0      3  14531 15488   30243    437            14841       1867
## 440       1      3   2787  1698    2510     65              477         52
glm.fit=glm(Channel~Region + Fresh + Milk + Grocery + Frozen + Detergents_Paper + Delicassen,
            data=trainData,family=binomial)
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
glm.probs=predict(glm.fit,newdata=wholesale[!trainData,],type="response") 
glm.pred=ifelse(glm.probs >0.5,"Hotel/Cafe/Restaurant","Retail")
Channel=wholesale$Channel[!trainData]
table(glm.pred,Channel)
##                        Channel
## glm.pred                 0  1
##   Hotel/Cafe/Restaurant  8 55
##   Retail                32  2
mean(glm.pred==Channel)
## [1] 0
summary(glm.fit)
## 
## Call:
## glm(formula = Channel ~ Region + Fresh + Milk + Grocery + Frozen + 
##     Detergents_Paper + Delicassen, family = binomial, data = trainData)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -2.5495  -0.0682   0.2451   0.3360   2.8501  
## 
## Coefficients:
##                    Estimate Std. Error z value Pr(>|z|)    
## (Intercept)       3.570e+00  9.606e-01   3.717 0.000202 ***
## Region           -2.934e-02  3.179e-01  -0.092 0.926466    
## Fresh             3.289e-06  1.831e-05   0.180 0.857491    
## Milk             -2.764e-05  7.097e-05  -0.389 0.696931    
## Grocery          -1.596e-04  7.401e-05  -2.157 0.031001 *  
## Frozen            1.811e-04  1.035e-04   1.749 0.080356 .  
## Detergents_Paper -7.682e-04  1.528e-04  -5.027 4.98e-07 ***
## Delicassen       -3.647e-05  1.156e-04  -0.316 0.752343    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 384.52  on 308  degrees of freedom
## Residual deviance: 149.99  on 301  degrees of freedom
## AIC: 165.99
## 
## Number of Fisher Scoring iterations: 7

We see a reduction in the amount of errors on the test set. From the initinal glm model 432 degreee of freedom and a huge change in the residual devianace. The training model yields 301 degrees of freedom and a reduction of about 50% in residual deviance from 384.52 to 149.99.

Fit a smaller Model, using the training data and get the same of errors. Each model with an AIC of 165.99

glm.fit=glm(Channel~Region + Fresh + Milk + Grocery + Frozen + Detergents_Paper + Delicassen,
            data=testData,family=binomial)
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
glm.probs=predict(glm.fit,newdata=wholesale[!testData,],type="response") 
glm.pred=ifelse(glm.probs >0.5,"Hotel/Cafe/Restaurant","Retail")
Channel=wholesale$Channel[!testData]
table(glm.pred,Channel)
##                        Channel
## glm.pred                 0  1
##   Hotel/Cafe/Restaurant  2 21
##   Retail                21  1
mean(glm.pred==Channel)
## [1] 0
summary(glm.fit)
## 
## Call:
## glm(formula = Channel ~ Region + Fresh + Milk + Grocery + Frozen + 
##     Detergents_Paper + Delicassen, family = binomial, data = testData)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -3.4656  -0.0032   0.1298   0.2150   1.7511  
## 
## Coefficients:
##                    Estimate Std. Error z value Pr(>|z|)    
## (Intercept)       8.985e+00  2.250e+00   3.993 6.52e-05 ***
## Region           -1.349e+00  5.792e-01  -2.329 0.019845 *  
## Fresh            -2.937e-05  3.362e-05  -0.873 0.382394    
## Milk             -1.856e-04  1.168e-04  -1.590 0.111836    
## Grocery          -2.852e-05  1.209e-04  -0.236 0.813449    
## Frozen            4.654e-06  1.616e-04   0.029 0.977021    
## Detergents_Paper -1.444e-03  4.008e-04  -3.604 0.000313 ***
## Delicassen        2.542e-04  2.121e-04   1.198 0.230826    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 168.554  on 130  degrees of freedom
## Residual deviance:  41.625  on 123  degrees of freedom
## AIC: 57.625
## 
## Number of Fisher Scoring iterations: 8

The test data set yeields 123 degrees of freedom, redisual devianace of 41.625 and a AIC of 57.625.

Linear Discriminant Analysis

LDA is more robust than logistic regression, becuase the discriminant scores are weighted sum of predictors, unlike logistics regression that models the logit transformations of classes probabilities as linear combinations of predictors.

testDF<-list(wholesale[1:8])
as.data.frame(testDF)
##     Channel Region  Fresh  Milk Grocery Frozen Detergents_Paper Delicassen
## 1         0      3  12669  9656    7561    214             2674       1338
## 2         0      3   7057  9810    9568   1762             3293       1776
## 3         0      3   6353  8808    7684   2405             3516       7844
## 4         1      3  13265  1196    4221   6404              507       1788
## 5         0      3  22615  5410    7198   3915             1777       5185
## 6         0      3   9413  8259    5126    666             1795       1451
## 7         0      3  12126  3199    6975    480             3140        545
## 8         0      3   7579  4956    9426   1669             3321       2566
## 9         1      3   5963  3648    6192    425             1716        750
## 10        0      3   6006 11093   18881   1159             7425       2098
## 11        0      3   3366  5403   12974   4400             5977       1744
## 12        0      3  13146  1124    4523   1420              549        497
## 13        0      3  31714 12319   11757    287             3881       2931
## 14        0      3  21217  6208   14982   3095             6707        602
## 15        0      3  24653  9465   12091    294             5058       2168
## 16        1      3  10253  1114    3821    397              964        412
## 17        0      3   1020  8816   12121    134             4508       1080
## 18        1      3   5876  6157    2933    839              370       4478
## 19        0      3  18601  6327   10099   2205             2767       3181
## 20        1      3   7780  2495    9464    669             2518        501
## 21        0      3  17546  4519    4602   1066             2259       2124
## 22        1      3   5567   871    2010   3383              375        569
## 23        1      3  31276  1917    4469   9408             2381       4334
## 24        0      3  26373 36423   22019   5154             4337      16523
## 25        0      3  22647  9776   13792   2915             4482       5778
## 26        0      3  16165  4230    7595    201             4003         57
## 27        1      3   9898   961    2861   3151              242        833
## 28        1      3  14276   803    3045    485              100        518
## 29        0      3   4113 20484   25957   1158             8604       5206
## 30        1      3  43088  2100    2609   1200             1107        823
## 31        1      3  18815  3610   11107   1148             2134       2963
## 32        1      3   2612  4339    3133   2088              820        985
## 33        1      3  21632  1318    2886    266              918        405
## 34        1      3  29729  4786    7326   6130              361       1083
## 35        1      3   1502  1979    2262    425              483        395
## 36        0      3    688  5491   11091    833             4239        436
## 37        1      3  29955  4362    5428   1729              862       4626
## 38        0      3  15168 10556   12477   1920             6506        714
## 39        0      3   4591 15729   16709     33             6956        433
## 40        1      3  56159   555     902  10002              212       2916
## 41        1      3  24025  4332    4757   9510             1145       5864
## 42        1      3  19176  3065    5956   2033             2575       2802
## 43        0      3  10850  7555   14961    188             6899         46
## 44        0      3    630 11095   23998    787             9529         72
## 45        0      3   9670  7027   10471    541             4618         65
## 46        0      3   5181 22044   21531   1740             7353       4985
## 47        0      3   3103 14069   21955   1668             6792       1452
## 48        0      3  44466 54259   55571   7782            24171       6465
## 49        0      3  11519  6152   10868    584             5121       1476
## 50        0      3   4967 21412   28921   1798            13583       1163
## 51        1      3   6269  1095    1980   3860              609       2162
## 52        1      3   3347  4051    6996    239             1538        301
## 53        0      3  40721  3916    5876    532             2587       1278
## 54        0      3    491 10473   11532    744             5611        224
## 55        1      3  27329  1449    1947   2436              204       1333
## 56        1      3   5264  3683    5005   1057             2024       1130
## 57        0      3   4098 29892   26866   2616            17740       1340
## 58        0      3   5417  9933   10487     38             7572       1282
## 59        1      3  13779  1970    1648    596              227        436
## 60        1      3   6137  5360    8040    129             3084       1603
## 61        0      3   8590  3045    7854     96             4095        225
## 62        0      3  35942 38369   59598   3254            26701       2017
## 63        0      3   7823  6245    6544   4154             4074        964
## 64        0      3   9396 11601   15775   2896             7677       1295
## 65        1      3   4760  1227    3250   3724             1247       1145
## 66        0      3     85 20959   45828     36            24231       1423
## 67        1      3      9  1534    7417    175             3468         27
## 68        0      3  19913  6759   13462   1256             5141        834
## 69        1      3   2446  7260    3993   5870              788       3095
## 70        1      3   8352  2820    1293    779              656        144
## 71        1      3  16705  2037    3202  10643              116       1365
## 72        1      3  18291  1266   21042   5373             4173      14472
## 73        1      3   4420  5139    2661   8872             1321        181
## 74        0      3  19899  5332    8713   8132              764        648
## 75        0      3   8190  6343    9794   1285             1901       1780
## 76        1      3  20398  1137       3   4407                3        975
## 77        1      3    717  3587    6532   7530              529        894
## 78        0      3  12205 12697   28540    869            12034       1009
## 79        1      3  10766  1175    2067   2096              301        167
## 80        1      3   1640  3259    3655    868             1202       1653
## 81        1      3   7005   829    3009    430              610        529
## 82        0      3    219  9540   14403    283             7818        156
## 83        0      3  10362  9232   11009    737             3537       2342
## 84        1      3  20874  1563    1783   2320              550        772
## 85        0      3  11867  3327    4814   1178             3837        120
## 86        0      3  16117 46197   92780   1026            40827       2944
## 87        0      3  22925 73498   32114    987            20070        903
## 88        1      3  43265  5025    8117   6312             1579      14351
## 89        1      3   7864   542    4042   9735              165         46
## 90        1      3  24904  3836    5330   3443              454       3178
## 91        1      3  11405   596    1638   3347               69        360
## 92        1      3  12754  2762    2530   8693              627       1117
## 93        0      3   9198 27472   32034   3232            18906       5130
## 94        1      3  11314  3090    2062  35009               71       2698
## 95        0      3   5626 12220   11323    206             5038        244
## 96        1      3      3  2920    6252    440              223        709
## 97        0      3     23  2616    8118    145             3874        217
## 98        1      3    403   254     610    774               54         63
## 99        1      3    503   112     778    895               56        132
## 100       1      3   9658  2182    1909   5639              215        323
## 101       0      3  11594  7779   12144   3252             8035       3029
## 102       0      3   1420 10810   16267   1593             6766       1838
## 103       0      3   2932  6459    7677   2561             4573       1386
## 104       1      3  56082  3504    8906  18028             1480       2498
## 105       1      3  14100  2132    3445   1336             1491        548
## 106       1      3  15587  1014    3970    910              139       1378
## 107       0      3   1454  6337   10704    133             6830       1831
## 108       0      3   8797 10646   14886   2471             8969       1438
## 109       0      3   1531  8397    6981    247             2505       1236
## 110       0      3   1406 16729   28986    673              836          3
## 111       1      3  11818  1648    1694   2276              169       1647
## 112       0      3  12579 11114   17569    805             6457       1519
## 113       1      3  19046  2770    2469   8853              483       2708
## 114       1      3  14438  2295    1733   3220              585       1561
## 115       1      3  18044  1080    2000   2555              118       1266
## 116       1      3  11134   793    2988   2715              276        610
## 117       1      3  11173  2521    3355   1517              310        222
## 118       1      3   6990  3880    5380   1647              319       1160
## 119       1      3  20049  1891    2362   5343              411        933
## 120       1      3   8258  2344    2147   3896              266        635
## 121       1      3  17160  1200    3412   2417              174       1136
## 122       1      3   4020  3234    1498   2395              264        255
## 123       1      3  12212   201     245   1991               25        860
## 124       0      3  11170 10769    8814   2194             1976        143
## 125       1      3  36050  1642    2961   4787              500       1621
## 126       1      3  76237  3473    7102  16538              778        918
## 127       1      3  19219  1840    1658   8195              349        483
## 128       0      3  21465  7243   10685    880             2386       2749
## 129       1      3    140  8847    3823    142             1062          3
## 130       1      3  42312   926    1510   1718              410       1819
## 131       1      3   7149  2428     699   6316              395        911
## 132       1      3   2101   589     314    346               70        310
## 133       1      3  14903  2032    2479    576              955        328
## 134       1      3   9434  1042    1235    436              256        396
## 135       1      3   7388  1882    2174    720               47        537
## 136       1      3   6300  1289    2591   1170              199        326
## 137       1      3   4625  8579    7030   4575             2447       1542
## 138       1      3   3087  8080    8282    661              721         36
## 139       1      3  13537  4257    5034    155              249       3271
## 140       1      3   5387  4979    3343    825              637        929
## 141       1      3  17623  4280    7305   2279              960       2616
## 142       1      3  30379 13252    5189    321               51       1450
## 143       1      3  37036  7152    8253   2995               20          3
## 144       1      3  10405  1596    1096   8425              399        318
## 145       1      3  18827  3677    1988    118              516        201
## 146       0      3  22039  8384   34792     42            12591       4430
## 147       1      3   7769  1936    2177    926               73        520
## 148       1      3   9203  3373    2707   1286             1082        526
## 149       1      3   5924   584     542   4052              283        434
## 150       1      3  31812  1433    1651    800              113       1440
## 151       1      3  16225  1825    1765    853              170       1067
## 152       1      3   1289  3328    2022    531              255       1774
## 153       1      3  18840  1371    3135   3001              352        184
## 154       1      3   3463  9250    2368    779              302       1627
## 155       1      3    622    55     137     75                7          8
## 156       0      3   1989 10690   19460    233            11577       2153
## 157       0      3   3830  5291   14855    317             6694       3182
## 158       1      3  17773  1366    2474   3378              811        418
## 159       0      3   2861  6570    9618    930             4004       1682
## 160       0      3    355  7704   14682    398             8077        303
## 161       0      3   1725  3651   12822    824             4424       2157
## 162       1      3  12434   540     283   1092                3       2233
## 163       1      3  15177  2024    3810   2665              232        610
## 164       0      3   5531 15726   26870   2367            13726        446
## 165       0      3   5224  7603    8584   2540             3674        238
## 166       0      3  15615 12653   19858   4425             7108       2379
## 167       0      3   4822  6721    9170    993             4973       3637
## 168       1      3   2926  3195    3268    405             1680        693
## 169       1      3   5809   735     803   1393               79        429
## 170       1      3   5414   717    2155   2399               69        750
## 171       0      3    260  8675   13430   1116             7015        323
## 172       0      3    200 25862   19816    651             8773       6250
## 173       1      3    955  5479    6536    333             2840        707
## 174       0      3    514  7677   19805    937             9836        716
## 175       1      3    286  1208    5241   2515              153       1442
## 176       0      3   2343  7845   11874     52             4196       1697
## 177       1      3  45640  6958    6536   7368             1532        230
## 178       1      3  12759  7330    4533   1752               20       2631
## 179       1      3  11002  7075    4945   1152              120        395
## 180       1      3   3157  4888    2500   4477              273       2165
## 181       1      3  12356  6036    8887    402             1382       2794
## 182       1      3 112151 29627   18148  16745             4948       8550
## 183       1      3    694  8533   10518    443             6907        156
## 184       1      3  36847 43950   20170  36534              239      47943
## 185       1      3    327   918    4710     74              334         11
## 186       1      3   8170  6448    1139   2181               58        247
## 187       1      3   3009   521     854   3470              949        727
## 188       1      3   2438  8002    9819   6269             3459          3
## 189       0      3   8040  7639   11687   2758             6839        404
## 190       0      3    834 11577   11522    275             4027       1856
## 191       1      3  16936  6250    1981   7332              118         64
## 192       1      3  13624   295    1381    890               43         84
## 193       1      3   5509  1461    2251    547              187        409
## 194       0      3    180  3485   20292    959             5618        666
## 195       1      3   7107  1012    2974    806              355       1142
## 196       1      3  17023  5139    5230   7888              330       1755
## 197       1      1  30624  7209    4897  18711              763       2876
## 198       0      1   2427  7097   10391   1127             4314       1468
## 199       1      1  11686  2154    6824   3527              592        697
## 200       1      1   9670  2280    2112    520              402        347
## 201       0      1   3067 13240   23127   3941             9959        731
## 202       0      1   4484 14399   24708   3549            14235       1681
## 203       1      1  25203 11487    9490   5065              284       6854
## 204       1      1    583   685    2216    469              954         18
## 205       1      1   1956   891    5226   1383                5       1328
## 206       0      1   1107 11711   23596    955             9265        710
## 207       1      1   6373   780     950    878              288        285
## 208       0      1   2541  4737    6089   2946             5316        120
## 209       1      1   1537  3748    5838   1859             3381        806
## 210       0      1   5550 12729   16767    864            12420        797
## 211       1      1  18567  1895    1393   1801              244       2100
## 212       0      1  12119 28326   39694   4736            19410       2870
## 213       1      1   7291  1012    2062   1291              240       1775
## 214       1      1   3317  6602    6861   1329             3961       1215
## 215       0      1   2362  6551   11364    913             5957        791
## 216       1      1   2806 10765   15538   1374             5828       2388
## 217       0      1   2532 16599   36486    179            13308        674
## 218       1      1  18044  1475    2046   2532              130       1158
## 219       0      1     18  7504   15205   1285             4797       6372
## 220       1      1   4155   367    1390   2306               86        130
## 221       1      1  14755   899    1382   1765               56        749
## 222       1      1   5396  7503   10646     91             4167        239
## 223       1      1   5041  1115    2856   7496              256        375
## 224       0      1   2790  2527    5265   5612              788       1360
## 225       1      1   7274   659    1499    784               70        659
## 226       1      1  12680  3243    4157    660              761        786
## 227       0      1  20782  5921    9212   1759             2568       1553
## 228       1      1   4042  2204    1563   2286              263        689
## 229       1      1   1869   577     572    950             4762        203
## 230       1      1   8656  2746    2501   6845              694        980
## 231       0      1  11072  5989    5615   8321              955       2137
## 232       1      1   2344 10678    3828   1439             1566        490
## 233       1      1  25962  1780    3838    638              284        834
## 234       1      1    964  4984    3316    937              409          7
## 235       1      1  15603  2703    3833   4260              325       2563
## 236       1      1   1838  6380    2824   1218             1216        295
## 237       1      1   8635   820    3047   2312              415        225
## 238       1      1  18692  3838     593   4634               28       1215
## 239       1      1   7363   475     585   1112               72        216
## 240       1      1  47493  2567    3779   5243              828       2253
## 241       1      1  22096  3575    7041  11422              343       2564
## 242       1      1  24929  1801    2475   2216              412       1047
## 243       1      1  18226   659    2914   3752              586        578
## 244       1      1  11210  3576    5119    561             1682       2398
## 245       1      1   6202  7775   10817   1183             3143       1970
## 246       0      1   3062  6154   13916    230             8933       2784
## 247       1      1   8885  2428    1777   1777              430        610
## 248       1      1  13569   346     489   2077               44        659
## 249       1      1  15671  5279    2406    559              562        572
## 250       1      1   8040  3795    2070   6340              918        291
## 251       1      1   3191  1993    1799   1730              234        710
## 252       0      1   6134 23133   33586   6746            18594       5121
## 253       1      1   6623  1860    4740   7683              205       1693
## 254       1      1  29526  7961   16966    432              363       1391
## 255       1      1  10379 17972    4748   4686             1547       3265
## 256       1      1  31614   489    1495   3242              111        615
## 257       1      1  11092  5008    5249    453              392        373
## 258       1      1   8475  1931    1883   5004             3593        987
## 259       1      1  56083  4563    2124   6422              730       3321
## 260       1      1  53205  4959    7336   3012              967        818
## 261       1      1   9193  4885    2157    327              780        548
## 262       1      1   7858  1110    1094   6818               49        287
## 263       1      1  23257  1372    1677    982              429        655
## 264       1      1   2153  1115    6684   4324             2894        411
## 265       0      1   1073  9679   15445     61             5980       1265
## 266       1      1   5909 23527   13699  10155              830       3636
## 267       0      1    572  9763   22182   2221             4882       2563
## 268       1      1  20893  1222    2576   3975              737       3628
## 269       0      1  11908  8053   19847   1069             6374        698
## 270       1      1  15218   258    1138   2516              333        204
## 271       1      1   4720  1032     975   5500              197         56
## 272       1      1   2083  5007    1563   1120              147       1550
## 273       1      1    514  8323    6869    529               93       1040
## 274       1      3  36817  3045    1493   4802              210       1824
## 275       1      3    894  1703    1841    744              759       1153
## 276       1      3    680  1610     223    862               96        379
## 277       1      3  27901  3749    6964   4479              603       2503
## 278       1      3   9061   829     683  16919              621        139
## 279       1      3  11693  2317    2543   5845              274       1409
## 280       0      3  17360  6200    9694   1293             3620       1721
## 281       1      3   3366  2884    2431    977              167       1104
## 282       0      3  12238  7108    6235   1093             2328       2079
## 283       1      3  49063  3965    4252   5970             1041       1404
## 284       1      3  25767  3613    2013  10303              314       1384
## 285       1      3  68951  4411   12609   8692              751       2406
## 286       1      3  40254   640    3600   1042              436         18
## 287       1      3   7149  2247    1242   1619             1226        128
## 288       1      3  15354  2102    2828   8366              386       1027
## 289       1      3  16260   594    1296    848              445        258
## 290       1      3  42786   286     471   1388               32         22
## 291       1      3   2708  2160    2642    502              965       1522
## 292       1      3   6022  3354    3261   2507              212        686
## 293       1      3   2838  3086    4329   3838              825       1060
## 294       0      2   3996 11103   12469    902             5952        741
## 295       1      2  21273  2013    6550    909              811       1854
## 296       0      2   7588  1897    5234    417             2208        254
## 297       1      2  19087  1304    3643   3045              710        898
## 298       0      2   8090  3199    6986   1455             3712        531
## 299       0      2   6758  4560    9965    934             4538       1037
## 300       1      2    444   879    2060    264              290        259
## 301       0      2  16448  6243    6360    824             2662       2005
## 302       0      2   5283 13316   20399   1809             8752        172
## 303       0      2   2886  5302    9785    364             6236        555
## 304       0      2   2599  3688   13829    492            10069         59
## 305       0      2    161  7460   24773    617            11783       2410
## 306       0      2    243 12939    8852    799             3909        211
## 307       0      2   6468 12867   21570   1840             7558       1543
## 308       1      2  17327  2374    2842   1149              351        925
## 309       1      2   6987  1020    3007    416              257        656
## 310       0      2    918 20655   13567   1465             6846        806
## 311       1      2   7034  1492    2405  12569              299       1117
## 312       1      2  29635  2335    8280   3046              371        117
## 313       0      2   2137  3737   19172   1274            17120        142
## 314       1      2   9784   925    2405   4447              183        297
## 315       1      2  10617  1795    7647   1483              857       1233
## 316       0      2   1479 14982   11924    662             3891       3508
## 317       1      2   7127  1375    2201   2679               83       1059
## 318       1      2   1182  3088    6114    978              821       1637
## 319       1      2  11800  2713    3558   2121              706         51
## 320       0      2   9759 25071   17645   1128            12408       1625
## 321       1      2   1774  3696    2280    514              275        834
## 322       1      2   9155  1897    5167   2714              228       1113
## 323       1      2  15881   713    3315   3703             1470        229
## 324       1      2  13360   944   11593    915             1679        573
## 325       1      2  25977  3587    2464   2369              140       1092
## 326       1      2  32717 16784   13626  60869             1272       5609
## 327       1      2   4414  1610    1431   3498              387        834
## 328       1      2    542   899    1664    414               88        522
## 329       1      2  16933  2209    3389   7849              210       1534
## 330       1      2   5113  1486    4583   5127              492        739
## 331       1      2   9790  1786    5109   3570              182       1043
## 332       0      2  11223 14881   26839   1234             9606       1102
## 333       1      2  22321  3216    1447   2208              178       2602
## 334       0      2   8565  4980   67298    131            38102       1215
## 335       0      2  16823   928    2743  11559              332       3486
## 336       0      2  27082  6817   10790   1365             4111       2139
## 337       1      2  13970  1511    1330    650              146        778
## 338       1      2   9351  1347    2611   8170              442        868
## 339       1      2      3   333    7021  15601               15        550
## 340       1      2   2617  1188    5332   9584              573       1942
## 341       0      3    381  4025    9670    388             7271       1371
## 342       0      3   2320  5763   11238    767             5162       2158
## 343       1      3    255  5758    5923    349             4595       1328
## 344       0      3   1689  6964   26316   1456            15469         37
## 345       1      3   3043  1172    1763   2234              217        379
## 346       1      3   1198  2602    8335    402             3843        303
## 347       0      3   2771  6939   15541   2693             6600       1115
## 348       0      3  27380  7184   12311   2809             4621       1022
## 349       1      3   3428  2380    2028   1341             1184        665
## 350       0      3   5981 14641   20521   2005            12218        445
## 351       1      3   3521  1099    1997   1796              173        995
## 352       0      3   1210 10044   22294   1741            12638       3137
## 353       1      3    608  1106    1533    830               90        195
## 354       0      3    117  6264   21203    228             8682       1111
## 355       1      3  14039  7393    2548   6386             1333       2341
## 356       1      3    190   727    2012    245              184        127
## 357       1      3  22686   134     218   3157                9        548
## 358       0      3     37  1275   22272    137             6747        110
## 359       1      3    759 18664    1660   6114              536       4100
## 360       1      3    796  5878    2109    340              232        776
## 361       1      3  19746  2872    2006   2601              468        503
## 362       1      3   4734   607     864   1206              159        405
## 363       1      3   2121  1601    2453    560              179        712
## 364       1      3   4627   997    4438    191             1335        314
## 365       1      3   2615   873    1524   1103              514        468
## 366       0      3   4692  6128    8025   1619             4515       3105
## 367       1      3   9561  2217    1664   1173              222        447
## 368       1      3   3477   894     534   1457              252        342
## 369       1      3  22335  1196    2406   2046              101        558
## 370       1      3   6211   337     683   1089               41        296
## 371       0      3  39679  3944    4955   1364              523       2235
## 372       1      3  20105  1887    1939   8164              716        790
## 373       1      3   3884  3801    1641    876              397       4829
## 374       0      3  15076  6257    7398   1504             1916       3113
## 375       1      3   6338  2256    1668   1492              311        686
## 376       1      3   5841  1450    1162    597              476         70
## 377       0      3   3136  8630   13586   5641             4666       1426
## 378       1      3  38793  3154    2648   1034               96       1242
## 379       1      3   3225  3294    1902    282               68       1114
## 380       0      3   4048  5164   10391    130              813        179
## 381       1      3  28257   944    2146   3881              600        270
## 382       1      3  17770  4591    1617   9927              246        532
## 383       1      3  34454  7435    8469   2540             1711       2893
## 384       1      3   1821  1364    3450   4006              397        361
## 385       1      3  10683 21858   15400   3635              282       5120
## 386       1      3  11635   922    1614   2583              192       1068
## 387       1      3   1206  3620    2857   1945              353        967
## 388       1      3  20918  1916    1573   1960              231        961
## 389       1      3   9785   848    1172   1677              200        406
## 390       1      3   9385  1530    1422   3019              227        684
## 391       1      3   3352  1181    1328   5502              311       1000
## 392       1      3   2647  2761    2313    907               95       1827
## 393       1      3    518  4180    3600    659              122        654
## 394       1      3  23632  6730    3842   8620              385        819
## 395       1      3  12377   865    3204   1398              149        452
## 396       1      3   9602  1316    1263   2921              841        290
## 397       0      3   4515 11991    9345   2644             3378       2213
## 398       1      3  11535  1666    1428   6838               64        743
## 399       1      3  11442  1032     582   5390               74        247
## 400       1      3   9612   577     935   1601              469        375
## 401       1      3   4446   906    1238   3576              153       1014
## 402       1      3  27167  2801    2128  13223               92       1902
## 403       1      3  26539  4753    5091    220               10        340
## 404       1      3  25606 11006    4604    127              632        288
## 405       1      3  18073  4613    3444   4324              914        715
## 406       1      3   6884  1046    1167   2069              593        378
## 407       1      3  25066  5010    5026   9806             1092        960
## 408       0      3   7362 12844   18683   2854             7883        553
## 409       0      3   8257  3880    6407   1646             2730        344
## 410       1      3   8708  3634    6100   2349             2123       5137
## 411       1      3   6633  2096    4563   1389             1860       1892
## 412       1      3   2126  3289    3281   1535              235       4365
## 413       1      3     97  3605   12400     98             2970         62
## 414       1      3   4983  4859    6633  17866              912       2435
## 415       1      3   5969  1990    3417   5679             1135        290
## 416       0      3   7842  6046    8552   1691             3540       1874
## 417       0      3   4389 10940   10908    848             6728        993
## 418       1      3   5065  5499   11055    364             3485       1063
## 419       0      3    660  8494   18622    133             6740        776
## 420       1      3   8861  3783    2223    633             1580       1521
## 421       1      3   4456  5266   13227     25             6818       1393
## 422       0      3  17063  4847    9053   1031             3415       1784
## 423       1      3  26400  1377    4172    830              948       1218
## 424       0      3  17565  3686    4657   1059             1803        668
## 425       0      3  16980  2884   12232    874             3213        249
## 426       1      3  11243  2408    2593  15348              108       1886
## 427       1      3  13134  9347   14316   3141             5079       1894
## 428       1      3  31012 16687    5429  15082              439       1163
## 429       1      3   3047  5970    4910   2198              850        317
## 430       1      3   8607  1750    3580     47               84       2501
## 431       1      3   3097  4230   16483    575              241       2080
## 432       1      3   8533  5506    5160  13486             1377       1498
## 433       1      3  21117  1162    4754    269             1328        395
## 434       1      3   1982  3218    1493   1541              356       1449
## 435       1      3  16731  3922    7994    688             2371        838
## 436       1      3  29703 12051   16027  13135              182       2204
## 437       1      3  39228  1431     764   4510               93       2346
## 438       0      3  14531 15488   30243    437            14841       1867
## 439       1      3  10290  1981    2232   1038              168       2125
## 440       1      3   2787  1698    2510     65              477         52
ind <- sample(2, nrow(wholesale), replace=TRUE, prob=c(0.7,0.3))
trainData <- wholesale[ind==1,]
testData <- wholesale[ind==2,]
ldaModel<- lda(Channel ~ ., data = trainData)
predictions <- predict(ldaModel, testData)
testPred <- predictions$class
cf <- table(testPred, testData$Channel, dnn=list('predicted','actual'))
confusionMatrix(cf)
## Confusion Matrix and Statistics
## 
##          actual
## predicted  0  1
##         0 29  3
##         1 23 89
##                                           
##                Accuracy : 0.8194          
##                  95% CI : (0.7467, 0.8785)
##     No Information Rate : 0.6389          
##     P-Value [Acc > NIR] : 1.629e-06       
##                                           
##                   Kappa : 0.573           
##  Mcnemar's Test P-Value : 0.0001944       
##                                           
##             Sensitivity : 0.5577          
##             Specificity : 0.9674          
##          Pos Pred Value : 0.9062          
##          Neg Pred Value : 0.7946          
##              Prevalence : 0.3611          
##          Detection Rate : 0.2014          
##    Detection Prevalence : 0.2222          
##       Balanced Accuracy : 0.7625          
##                                           
##        'Positive' Class : 0               
## 

The LDA model produces a 81% accuracy model.

Principal Components Analysis

dimnames(wholesale)
## [[1]]
##   [1] "1"   "2"   "3"   "4"   "5"   "6"   "7"   "8"   "9"   "10"  "11" 
##  [12] "12"  "13"  "14"  "15"  "16"  "17"  "18"  "19"  "20"  "21"  "22" 
##  [23] "23"  "24"  "25"  "26"  "27"  "28"  "29"  "30"  "31"  "32"  "33" 
##  [34] "34"  "35"  "36"  "37"  "38"  "39"  "40"  "41"  "42"  "43"  "44" 
##  [45] "45"  "46"  "47"  "48"  "49"  "50"  "51"  "52"  "53"  "54"  "55" 
##  [56] "56"  "57"  "58"  "59"  "60"  "61"  "62"  "63"  "64"  "65"  "66" 
##  [67] "67"  "68"  "69"  "70"  "71"  "72"  "73"  "74"  "75"  "76"  "77" 
##  [78] "78"  "79"  "80"  "81"  "82"  "83"  "84"  "85"  "86"  "87"  "88" 
##  [89] "89"  "90"  "91"  "92"  "93"  "94"  "95"  "96"  "97"  "98"  "99" 
## [100] "100" "101" "102" "103" "104" "105" "106" "107" "108" "109" "110"
## [111] "111" "112" "113" "114" "115" "116" "117" "118" "119" "120" "121"
## [122] "122" "123" "124" "125" "126" "127" "128" "129" "130" "131" "132"
## [133] "133" "134" "135" "136" "137" "138" "139" "140" "141" "142" "143"
## [144] "144" "145" "146" "147" "148" "149" "150" "151" "152" "153" "154"
## [155] "155" "156" "157" "158" "159" "160" "161" "162" "163" "164" "165"
## [166] "166" "167" "168" "169" "170" "171" "172" "173" "174" "175" "176"
## [177] "177" "178" "179" "180" "181" "182" "183" "184" "185" "186" "187"
## [188] "188" "189" "190" "191" "192" "193" "194" "195" "196" "197" "198"
## [199] "199" "200" "201" "202" "203" "204" "205" "206" "207" "208" "209"
## [210] "210" "211" "212" "213" "214" "215" "216" "217" "218" "219" "220"
## [221] "221" "222" "223" "224" "225" "226" "227" "228" "229" "230" "231"
## [232] "232" "233" "234" "235" "236" "237" "238" "239" "240" "241" "242"
## [243] "243" "244" "245" "246" "247" "248" "249" "250" "251" "252" "253"
## [254] "254" "255" "256" "257" "258" "259" "260" "261" "262" "263" "264"
## [265] "265" "266" "267" "268" "269" "270" "271" "272" "273" "274" "275"
## [276] "276" "277" "278" "279" "280" "281" "282" "283" "284" "285" "286"
## [287] "287" "288" "289" "290" "291" "292" "293" "294" "295" "296" "297"
## [298] "298" "299" "300" "301" "302" "303" "304" "305" "306" "307" "308"
## [309] "309" "310" "311" "312" "313" "314" "315" "316" "317" "318" "319"
## [320] "320" "321" "322" "323" "324" "325" "326" "327" "328" "329" "330"
## [331] "331" "332" "333" "334" "335" "336" "337" "338" "339" "340" "341"
## [342] "342" "343" "344" "345" "346" "347" "348" "349" "350" "351" "352"
## [353] "353" "354" "355" "356" "357" "358" "359" "360" "361" "362" "363"
## [364] "364" "365" "366" "367" "368" "369" "370" "371" "372" "373" "374"
## [375] "375" "376" "377" "378" "379" "380" "381" "382" "383" "384" "385"
## [386] "386" "387" "388" "389" "390" "391" "392" "393" "394" "395" "396"
## [397] "397" "398" "399" "400" "401" "402" "403" "404" "405" "406" "407"
## [408] "408" "409" "410" "411" "412" "413" "414" "415" "416" "417" "418"
## [419] "419" "420" "421" "422" "423" "424" "425" "426" "427" "428" "429"
## [430] "430" "431" "432" "433" "434" "435" "436" "437" "438" "439" "440"
## 
## [[2]]
## [1] "Channel"          "Region"           "Fresh"           
## [4] "Milk"             "Grocery"          "Frozen"          
## [7] "Detergents_Paper" "Delicassen"
apply(wholesale,2,mean)
##          Channel           Region            Fresh             Milk 
##     6.772727e-01     2.543182e+00     1.200030e+04     5.796266e+03 
##          Grocery           Frozen Detergents_Paper       Delicassen 
##     7.951277e+03     3.071932e+03     2.881493e+03     1.524870e+03
apply(wholesale,2, var)
##          Channel           Region            Fresh             Milk 
##     2.190723e-01     5.994978e-01     1.599549e+08     5.446997e+07 
##          Grocery           Frozen Detergents_Paper       Delicassen 
##     9.031010e+07     2.356785e+07     2.273244e+07     7.952997e+06

We see that Detergents_Paper has a much larger variance than the other variables. It would dominate the principal components, so we standardize the variables when we perform PCA.

pca.out=prcomp(wholesale, scale=TRUE)
pca.out
## Standard deviations:
## [1] 1.7606845 1.3378965 1.0058697 0.8592976 0.7460780 0.6777229 0.5302132
## [8] 0.2505796
## 
## Rotation:
##                          PC1         PC2           PC3         PC4
## Channel           0.42829156 -0.20469886 -0.0829798863  0.02964416
## Region           -0.02472603 -0.04312964  0.9825008891 -0.07784462
## Fresh             0.02531946 -0.51344468  0.0889509074  0.79847592
## Milk             -0.47440995 -0.20554061 -0.0257510842 -0.05402202
## Grocery          -0.53632914  0.00871762 -0.0453143572  0.12158624
## Frozen            0.02997456 -0.59274525 -0.1221565222 -0.16131688
## Detergents_Paper -0.52390630  0.12108309 -0.0474814388  0.15101211
## Delicassen       -0.16499653 -0.53318082  0.0009301994 -0.53755767
##                          PC5         PC6          PC7          PC8
## Channel          -0.03620585  0.86350670 -0.139899044 -0.019335373
## Region           -0.13250892  0.08976479 -0.023279938 -0.001545045
## Fresh             0.25811686 -0.14747474 -0.027173693 -0.033851114
## Milk              0.07208576  0.31593256  0.789020414 -0.039291347
## Grocery          -0.11172990  0.21369889 -0.353064294  0.715984124
## Frozen           -0.75421244 -0.19435993 -0.005336793 -0.012983225
## Detergents_Paper -0.17650264  0.19575356 -0.371374310 -0.691672189
## Delicassen        0.54482721 -0.05453289 -0.306582655 -0.075642587
names(pca.out)
## [1] "sdev"     "rotation" "center"   "scale"    "x"
biplot(pca.out, scale=0)

Hierarchical Clustering

hc.complete=hclust(dist(wholesale),method="complete")
plot(hc.complete)

hc.single=hclust(dist(wholesale),method="single")
plot(hc.single)

hc.average=hclust(dist(wholesale),method="average")
plot(hc.average)

Utilizing Hierarchical Clustering does not yield much valuable informaiton.

Lastly we will use Classificaiton Trees

range(wholesale)
## [1]      0 112151
rf =randomForest(Channel ~ ., data=wholesale, mtry=4, ntree=10 )
## Warning in randomForest.default(m, y, ...): The response has five or fewer
## unique values.  Are you sure you want to do regression?
class(rm)
## [1] "function"
str(rf)
## List of 18
##  $ call           : language randomForest(formula = Channel ~ ., data = wholesale, mtry = 4, ntree = 10)
##  $ type           : chr "regression"
##  $ predicted      : Named num [1:440] 0.00 2.00e-01 -3.33e-16 1.00 5.00e-01 ...
##   ..- attr(*, "names")= chr [1:440] "1" "2" "3" "4" ...
##  $ mse            : num [1:10] 0.138 0.133 0.123 0.134 0.117 ...
##  $ rsq            : num [1:10] 0.367 0.391 0.439 0.387 0.466 ...
##  $ oob.times      : int [1:440] 2 5 6 6 2 3 3 5 3 4 ...
##  $ importance     : num [1:7, 1] 0.507 3.935 16.236 16.094 4.806 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : chr [1:7] "Region" "Fresh" "Milk" "Grocery" ...
##   .. ..$ : chr "IncNodePurity"
##  $ importanceSD   : NULL
##  $ localImportance: NULL
##  $ proximity      : NULL
##  $ ntree          : num 10
##  $ mtry           : num 4
##  $ forest         :List of 11
##   ..$ ndbigtree    : int [1:10] 85 77 73 65 71 61 73 69 55 67
##   ..$ nodestatus   : int [1:85, 1:10] -3 -3 -3 -3 -3 -3 -3 -3 -3 -1 ...
##   ..$ leftDaughter : int [1:85, 1:10] 2 4 6 8 10 12 14 16 18 0 ...
##   ..$ rightDaughter: int [1:85, 1:10] 3 5 7 9 11 13 15 17 19 0 ...
##   ..$ nodepred     : num [1:85, 1:10] 0.711 0.932 0.329 0.959 0.2 ...
##   ..$ bestvar      : int [1:85, 1:10] 3 6 4 6 3 6 7 4 6 0 ...
##   ..$ xbestsplit   : num [1:85, 1:10] 5152 3715 8591 2171 2156 ...
##   ..$ ncat         : Named int [1:7] 1 1 1 1 1 1 1
##   .. ..- attr(*, "names")= chr [1:7] "Region" "Fresh" "Milk" "Grocery" ...
##   ..$ nrnodes      : int 85
##   ..$ ntree        : num 10
##   ..$ xlevels      :List of 7
##   .. ..$ Region          : num 0
##   .. ..$ Fresh           : num 0
##   .. ..$ Milk            : num 0
##   .. ..$ Grocery         : num 0
##   .. ..$ Frozen          : num 0
##   .. ..$ Detergents_Paper: num 0
##   .. ..$ Delicassen      : num 0
##  $ coefs          : NULL
##  $ y              : Named num [1:440] 0 0 0 1 0 0 0 0 1 0 ...
##   ..- attr(*, "names")= chr [1:440] "1" "2" "3" "4" ...
##  $ test           : NULL
##  $ inbag          : NULL
##  $ terms          :Classes 'terms', 'formula' length 3 Channel ~ Region + Fresh + Milk + Grocery + Frozen + Detergents_Paper +      Delicassen
##   .. ..- attr(*, "variables")= language list(Channel, Region, Fresh, Milk, Grocery, Frozen, Detergents_Paper,      Delicassen)
##   .. ..- attr(*, "factors")= int [1:8, 1:7] 0 1 0 0 0 0 0 0 0 0 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:8] "Channel" "Region" "Fresh" "Milk" ...
##   .. .. .. ..$ : chr [1:7] "Region" "Fresh" "Milk" "Grocery" ...
##   .. ..- attr(*, "term.labels")= chr [1:7] "Region" "Fresh" "Milk" "Grocery" ...
##   .. ..- attr(*, "order")= int [1:7] 1 1 1 1 1 1 1
##   .. ..- attr(*, "intercept")= num 0
##   .. ..- attr(*, "response")= int 1
##   .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> 
##   .. ..- attr(*, "predvars")= language list(Channel, Region, Fresh, Milk, Grocery, Frozen, Detergents_Paper,      Delicassen)
##   .. ..- attr(*, "dataClasses")= Named chr [1:8] "numeric" "numeric" "numeric" "numeric" ...
##   .. .. ..- attr(*, "names")= chr [1:8] "Channel" "Region" "Fresh" "Milk" ...
##  - attr(*, "class")= chr [1:2] "randomForest.formula" "randomForest"
rf$confusion
## NULL
rf$importance
##                  IncNodePurity
## Region                0.507344
## Fresh                 3.935115
## Milk                 16.235844
## Grocery              16.093554
## Frozen                4.806335
## Detergents_Paper     46.135670
## Delicassen            3.599017

Plot classification tree algorithm using both rpart and C5.0

Classification Tree using rpart:

Legend: node), split, n, loss, yval, (yprob) * denotes terminal node

set.seed(1234)
R<-runif(nrow(wholesale))
str(wholesale)
## 'data.frame':    440 obs. of  8 variables:
##  $ Channel         : int  0 0 0 1 0 0 0 0 1 0 ...
##  $ Region          : int  3 3 3 3 3 3 3 3 3 3 ...
##  $ Fresh           : int  12669 7057 6353 13265 22615 9413 12126 7579 5963 6006 ...
##  $ Milk            : int  9656 9810 8808 1196 5410 8259 3199 4956 3648 11093 ...
##  $ Grocery         : int  7561 9568 7684 4221 7198 5126 6975 9426 6192 18881 ...
##  $ Frozen          : int  214 1762 2405 6404 3915 666 480 1669 425 1159 ...
##  $ Detergents_Paper: int  2674 3293 3516 507 1777 1795 3140 3321 1716 7425 ...
##  $ Delicassen      : int  1338 1776 7844 1788 5185 1451 545 2566 750 2098 ...
wholesaleRandom<- wholesale[order(R),]
M1 <- rpart(Channel~ ., data=wholesaleRandom[1:100,], method="class")
M1
## n= 100 
## 
## node), split, n, loss, yval, (yprob)
##       * denotes terminal node
## 
## 1) root 100 34 1 (0.34000000 0.66000000)  
##   2) Detergents_Paper>=1757 39  6 0 (0.84615385 0.15384615) *
##   3) Detergents_Paper< 1757 61  1 1 (0.01639344 0.98360656) *
rpart.plot(M1)

rpart.plot(M1, type=3, extra=101, fallen.leaves=T)

P1<-predict(M1, wholesale[101:440,], type="class")
summary(M1)
## Call:
## rpart(formula = Channel ~ ., data = wholesaleRandom[1:100, ], 
##     method = "class")
##   n= 100 
## 
##          CP nsplit rel error    xerror       xstd
## 1 0.7941176      0 1.0000000 1.0000000 0.13932611
## 2 0.0100000      1 0.2058824 0.2647059 0.08417111
## 
## Variable importance
## Detergents_Paper          Grocery             Milk           Frozen 
##               42               28               22                6 
##       Delicassen 
##                2 
## 
## Node number 1: 100 observations,    complexity param=0.7941176
##   predicted class=1  expected loss=0.34  P(node) =1
##     class counts:    34    66
##    probabilities: 0.340 0.660 
##   left son=2 (39 obs) right son=3 (61 obs)
##   Primary splits:
##       Detergents_Paper < 1757    to the right, improve=32.758940, (0 missing)
##       Grocery          < 6804    to the right, improve=25.779840, (0 missing)
##       Milk             < 3197    to the right, improve=20.502640, (0 missing)
##       Frozen           < 3300.5  to the left,  improve= 6.389356, (0 missing)
##       Fresh            < 12901.5 to the left,  improve= 2.294279, (0 missing)
##   Surrogate splits:
##       Grocery    < 4255.5  to the right, agree=0.87, adj=0.667, (0 split)
##       Milk       < 4907.5  to the right, agree=0.81, adj=0.513, (0 split)
##       Frozen     < 309.5   to the left,  agree=0.67, adj=0.154, (0 split)
##       Delicassen < 5125    to the right, agree=0.63, adj=0.051, (0 split)
## 
## Node number 2: 39 observations
##   predicted class=0  expected loss=0.1538462  P(node) =0.39
##     class counts:    33     6
##    probabilities: 0.846 0.154 
## 
## Node number 3: 61 observations
##   predicted class=1  expected loss=0.01639344  P(node) =0.61
##     class counts:     1    60
##    probabilities: 0.016 0.984
table(wholesaled[101:440,1], predicted=P1)
##                        predicted
##                           0   1
##   Hotel/Restaurant/Cafe  22 228
##   Retail                 84   6
summary(M1)
## Call:
## rpart(formula = Channel ~ ., data = wholesaleRandom[1:100, ], 
##     method = "class")
##   n= 100 
## 
##          CP nsplit rel error    xerror       xstd
## 1 0.7941176      0 1.0000000 1.0000000 0.13932611
## 2 0.0100000      1 0.2058824 0.2647059 0.08417111
## 
## Variable importance
## Detergents_Paper          Grocery             Milk           Frozen 
##               42               28               22                6 
##       Delicassen 
##                2 
## 
## Node number 1: 100 observations,    complexity param=0.7941176
##   predicted class=1  expected loss=0.34  P(node) =1
##     class counts:    34    66
##    probabilities: 0.340 0.660 
##   left son=2 (39 obs) right son=3 (61 obs)
##   Primary splits:
##       Detergents_Paper < 1757    to the right, improve=32.758940, (0 missing)
##       Grocery          < 6804    to the right, improve=25.779840, (0 missing)
##       Milk             < 3197    to the right, improve=20.502640, (0 missing)
##       Frozen           < 3300.5  to the left,  improve= 6.389356, (0 missing)
##       Fresh            < 12901.5 to the left,  improve= 2.294279, (0 missing)
##   Surrogate splits:
##       Grocery    < 4255.5  to the right, agree=0.87, adj=0.667, (0 split)
##       Milk       < 4907.5  to the right, agree=0.81, adj=0.513, (0 split)
##       Frozen     < 309.5   to the left,  agree=0.67, adj=0.154, (0 split)
##       Delicassen < 5125    to the right, agree=0.63, adj=0.051, (0 split)
## 
## Node number 2: 39 observations
##   predicted class=0  expected loss=0.1538462  P(node) =0.39
##     class counts:    33     6
##    probabilities: 0.846 0.154 
## 
## Node number 3: 61 observations
##   predicted class=1  expected loss=0.01639344  P(node) =0.61
##     class counts:     1    60
##    probabilities: 0.016 0.984

Classification Tree using C5.0: CHange data set to Wholesaled for factor variables to model Channel.

set.seed(1234)
wholesaled
##                   Channel Region  Fresh  Milk Grocery Frozen
## 1                  Retail  Other  12669  9656    7561    214
## 2                  Retail  Other   7057  9810    9568   1762
## 3                  Retail  Other   6353  8808    7684   2405
## 4   Hotel/Restaurant/Cafe  Other  13265  1196    4221   6404
## 5                  Retail  Other  22615  5410    7198   3915
## 6                  Retail  Other   9413  8259    5126    666
## 7                  Retail  Other  12126  3199    6975    480
## 8                  Retail  Other   7579  4956    9426   1669
## 9   Hotel/Restaurant/Cafe  Other   5963  3648    6192    425
## 10                 Retail  Other   6006 11093   18881   1159
## 11                 Retail  Other   3366  5403   12974   4400
## 12                 Retail  Other  13146  1124    4523   1420
## 13                 Retail  Other  31714 12319   11757    287
## 14                 Retail  Other  21217  6208   14982   3095
## 15                 Retail  Other  24653  9465   12091    294
## 16  Hotel/Restaurant/Cafe  Other  10253  1114    3821    397
## 17                 Retail  Other   1020  8816   12121    134
## 18  Hotel/Restaurant/Cafe  Other   5876  6157    2933    839
## 19                 Retail  Other  18601  6327   10099   2205
## 20  Hotel/Restaurant/Cafe  Other   7780  2495    9464    669
## 21                 Retail  Other  17546  4519    4602   1066
## 22  Hotel/Restaurant/Cafe  Other   5567   871    2010   3383
## 23  Hotel/Restaurant/Cafe  Other  31276  1917    4469   9408
## 24                 Retail  Other  26373 36423   22019   5154
## 25                 Retail  Other  22647  9776   13792   2915
## 26                 Retail  Other  16165  4230    7595    201
## 27  Hotel/Restaurant/Cafe  Other   9898   961    2861   3151
## 28  Hotel/Restaurant/Cafe  Other  14276   803    3045    485
## 29                 Retail  Other   4113 20484   25957   1158
## 30  Hotel/Restaurant/Cafe  Other  43088  2100    2609   1200
## 31  Hotel/Restaurant/Cafe  Other  18815  3610   11107   1148
## 32  Hotel/Restaurant/Cafe  Other   2612  4339    3133   2088
## 33  Hotel/Restaurant/Cafe  Other  21632  1318    2886    266
## 34  Hotel/Restaurant/Cafe  Other  29729  4786    7326   6130
## 35  Hotel/Restaurant/Cafe  Other   1502  1979    2262    425
## 36                 Retail  Other    688  5491   11091    833
## 37  Hotel/Restaurant/Cafe  Other  29955  4362    5428   1729
## 38                 Retail  Other  15168 10556   12477   1920
## 39                 Retail  Other   4591 15729   16709     33
## 40  Hotel/Restaurant/Cafe  Other  56159   555     902  10002
## 41  Hotel/Restaurant/Cafe  Other  24025  4332    4757   9510
## 42  Hotel/Restaurant/Cafe  Other  19176  3065    5956   2033
## 43                 Retail  Other  10850  7555   14961    188
## 44                 Retail  Other    630 11095   23998    787
## 45                 Retail  Other   9670  7027   10471    541
## 46                 Retail  Other   5181 22044   21531   1740
## 47                 Retail  Other   3103 14069   21955   1668
## 48                 Retail  Other  44466 54259   55571   7782
## 49                 Retail  Other  11519  6152   10868    584
## 50                 Retail  Other   4967 21412   28921   1798
## 51  Hotel/Restaurant/Cafe  Other   6269  1095    1980   3860
## 52  Hotel/Restaurant/Cafe  Other   3347  4051    6996    239
## 53                 Retail  Other  40721  3916    5876    532
## 54                 Retail  Other    491 10473   11532    744
## 55  Hotel/Restaurant/Cafe  Other  27329  1449    1947   2436
## 56  Hotel/Restaurant/Cafe  Other   5264  3683    5005   1057
## 57                 Retail  Other   4098 29892   26866   2616
## 58                 Retail  Other   5417  9933   10487     38
## 59  Hotel/Restaurant/Cafe  Other  13779  1970    1648    596
## 60  Hotel/Restaurant/Cafe  Other   6137  5360    8040    129
## 61                 Retail  Other   8590  3045    7854     96
## 62                 Retail  Other  35942 38369   59598   3254
## 63                 Retail  Other   7823  6245    6544   4154
## 64                 Retail  Other   9396 11601   15775   2896
## 65  Hotel/Restaurant/Cafe  Other   4760  1227    3250   3724
## 66                 Retail  Other     85 20959   45828     36
## 67  Hotel/Restaurant/Cafe  Other      9  1534    7417    175
## 68                 Retail  Other  19913  6759   13462   1256
## 69  Hotel/Restaurant/Cafe  Other   2446  7260    3993   5870
## 70  Hotel/Restaurant/Cafe  Other   8352  2820    1293    779
## 71  Hotel/Restaurant/Cafe  Other  16705  2037    3202  10643
## 72  Hotel/Restaurant/Cafe  Other  18291  1266   21042   5373
## 73  Hotel/Restaurant/Cafe  Other   4420  5139    2661   8872
## 74                 Retail  Other  19899  5332    8713   8132
## 75                 Retail  Other   8190  6343    9794   1285
## 76  Hotel/Restaurant/Cafe  Other  20398  1137       3   4407
## 77  Hotel/Restaurant/Cafe  Other    717  3587    6532   7530
## 78                 Retail  Other  12205 12697   28540    869
## 79  Hotel/Restaurant/Cafe  Other  10766  1175    2067   2096
## 80  Hotel/Restaurant/Cafe  Other   1640  3259    3655    868
## 81  Hotel/Restaurant/Cafe  Other   7005   829    3009    430
## 82                 Retail  Other    219  9540   14403    283
## 83                 Retail  Other  10362  9232   11009    737
## 84  Hotel/Restaurant/Cafe  Other  20874  1563    1783   2320
## 85                 Retail  Other  11867  3327    4814   1178
## 86                 Retail  Other  16117 46197   92780   1026
## 87                 Retail  Other  22925 73498   32114    987
## 88  Hotel/Restaurant/Cafe  Other  43265  5025    8117   6312
## 89  Hotel/Restaurant/Cafe  Other   7864   542    4042   9735
## 90  Hotel/Restaurant/Cafe  Other  24904  3836    5330   3443
## 91  Hotel/Restaurant/Cafe  Other  11405   596    1638   3347
## 92  Hotel/Restaurant/Cafe  Other  12754  2762    2530   8693
## 93                 Retail  Other   9198 27472   32034   3232
## 94  Hotel/Restaurant/Cafe  Other  11314  3090    2062  35009
## 95                 Retail  Other   5626 12220   11323    206
## 96  Hotel/Restaurant/Cafe  Other      3  2920    6252    440
## 97                 Retail  Other     23  2616    8118    145
## 98  Hotel/Restaurant/Cafe  Other    403   254     610    774
## 99  Hotel/Restaurant/Cafe  Other    503   112     778    895
## 100 Hotel/Restaurant/Cafe  Other   9658  2182    1909   5639
## 101                Retail  Other  11594  7779   12144   3252
## 102                Retail  Other   1420 10810   16267   1593
## 103                Retail  Other   2932  6459    7677   2561
## 104 Hotel/Restaurant/Cafe  Other  56082  3504    8906  18028
## 105 Hotel/Restaurant/Cafe  Other  14100  2132    3445   1336
## 106 Hotel/Restaurant/Cafe  Other  15587  1014    3970    910
## 107                Retail  Other   1454  6337   10704    133
## 108                Retail  Other   8797 10646   14886   2471
## 109                Retail  Other   1531  8397    6981    247
## 110                Retail  Other   1406 16729   28986    673
## 111 Hotel/Restaurant/Cafe  Other  11818  1648    1694   2276
## 112                Retail  Other  12579 11114   17569    805
## 113 Hotel/Restaurant/Cafe  Other  19046  2770    2469   8853
## 114 Hotel/Restaurant/Cafe  Other  14438  2295    1733   3220
## 115 Hotel/Restaurant/Cafe  Other  18044  1080    2000   2555
## 116 Hotel/Restaurant/Cafe  Other  11134   793    2988   2715
## 117 Hotel/Restaurant/Cafe  Other  11173  2521    3355   1517
## 118 Hotel/Restaurant/Cafe  Other   6990  3880    5380   1647
## 119 Hotel/Restaurant/Cafe  Other  20049  1891    2362   5343
## 120 Hotel/Restaurant/Cafe  Other   8258  2344    2147   3896
## 121 Hotel/Restaurant/Cafe  Other  17160  1200    3412   2417
## 122 Hotel/Restaurant/Cafe  Other   4020  3234    1498   2395
## 123 Hotel/Restaurant/Cafe  Other  12212   201     245   1991
## 124                Retail  Other  11170 10769    8814   2194
## 125 Hotel/Restaurant/Cafe  Other  36050  1642    2961   4787
## 126 Hotel/Restaurant/Cafe  Other  76237  3473    7102  16538
## 127 Hotel/Restaurant/Cafe  Other  19219  1840    1658   8195
## 128                Retail  Other  21465  7243   10685    880
## 129 Hotel/Restaurant/Cafe  Other    140  8847    3823    142
## 130 Hotel/Restaurant/Cafe  Other  42312   926    1510   1718
## 131 Hotel/Restaurant/Cafe  Other   7149  2428     699   6316
## 132 Hotel/Restaurant/Cafe  Other   2101   589     314    346
## 133 Hotel/Restaurant/Cafe  Other  14903  2032    2479    576
## 134 Hotel/Restaurant/Cafe  Other   9434  1042    1235    436
## 135 Hotel/Restaurant/Cafe  Other   7388  1882    2174    720
## 136 Hotel/Restaurant/Cafe  Other   6300  1289    2591   1170
## 137 Hotel/Restaurant/Cafe  Other   4625  8579    7030   4575
## 138 Hotel/Restaurant/Cafe  Other   3087  8080    8282    661
## 139 Hotel/Restaurant/Cafe  Other  13537  4257    5034    155
## 140 Hotel/Restaurant/Cafe  Other   5387  4979    3343    825
## 141 Hotel/Restaurant/Cafe  Other  17623  4280    7305   2279
## 142 Hotel/Restaurant/Cafe  Other  30379 13252    5189    321
## 143 Hotel/Restaurant/Cafe  Other  37036  7152    8253   2995
## 144 Hotel/Restaurant/Cafe  Other  10405  1596    1096   8425
## 145 Hotel/Restaurant/Cafe  Other  18827  3677    1988    118
## 146                Retail  Other  22039  8384   34792     42
## 147 Hotel/Restaurant/Cafe  Other   7769  1936    2177    926
## 148 Hotel/Restaurant/Cafe  Other   9203  3373    2707   1286
## 149 Hotel/Restaurant/Cafe  Other   5924   584     542   4052
## 150 Hotel/Restaurant/Cafe  Other  31812  1433    1651    800
## 151 Hotel/Restaurant/Cafe  Other  16225  1825    1765    853
## 152 Hotel/Restaurant/Cafe  Other   1289  3328    2022    531
## 153 Hotel/Restaurant/Cafe  Other  18840  1371    3135   3001
## 154 Hotel/Restaurant/Cafe  Other   3463  9250    2368    779
## 155 Hotel/Restaurant/Cafe  Other    622    55     137     75
## 156                Retail  Other   1989 10690   19460    233
## 157                Retail  Other   3830  5291   14855    317
## 158 Hotel/Restaurant/Cafe  Other  17773  1366    2474   3378
## 159                Retail  Other   2861  6570    9618    930
## 160                Retail  Other    355  7704   14682    398
## 161                Retail  Other   1725  3651   12822    824
## 162 Hotel/Restaurant/Cafe  Other  12434   540     283   1092
## 163 Hotel/Restaurant/Cafe  Other  15177  2024    3810   2665
## 164                Retail  Other   5531 15726   26870   2367
## 165                Retail  Other   5224  7603    8584   2540
## 166                Retail  Other  15615 12653   19858   4425
## 167                Retail  Other   4822  6721    9170    993
## 168 Hotel/Restaurant/Cafe  Other   2926  3195    3268    405
## 169 Hotel/Restaurant/Cafe  Other   5809   735     803   1393
## 170 Hotel/Restaurant/Cafe  Other   5414   717    2155   2399
## 171                Retail  Other    260  8675   13430   1116
## 172                Retail  Other    200 25862   19816    651
## 173 Hotel/Restaurant/Cafe  Other    955  5479    6536    333
## 174                Retail  Other    514  7677   19805    937
## 175 Hotel/Restaurant/Cafe  Other    286  1208    5241   2515
## 176                Retail  Other   2343  7845   11874     52
## 177 Hotel/Restaurant/Cafe  Other  45640  6958    6536   7368
## 178 Hotel/Restaurant/Cafe  Other  12759  7330    4533   1752
## 179 Hotel/Restaurant/Cafe  Other  11002  7075    4945   1152
## 180 Hotel/Restaurant/Cafe  Other   3157  4888    2500   4477
## 181 Hotel/Restaurant/Cafe  Other  12356  6036    8887    402
## 182 Hotel/Restaurant/Cafe  Other 112151 29627   18148  16745
## 183 Hotel/Restaurant/Cafe  Other    694  8533   10518    443
## 184 Hotel/Restaurant/Cafe  Other  36847 43950   20170  36534
## 185 Hotel/Restaurant/Cafe  Other    327   918    4710     74
## 186 Hotel/Restaurant/Cafe  Other   8170  6448    1139   2181
## 187 Hotel/Restaurant/Cafe  Other   3009   521     854   3470
## 188 Hotel/Restaurant/Cafe  Other   2438  8002    9819   6269
## 189                Retail  Other   8040  7639   11687   2758
## 190                Retail  Other    834 11577   11522    275
## 191 Hotel/Restaurant/Cafe  Other  16936  6250    1981   7332
## 192 Hotel/Restaurant/Cafe  Other  13624   295    1381    890
## 193 Hotel/Restaurant/Cafe  Other   5509  1461    2251    547
## 194                Retail  Other    180  3485   20292    959
## 195 Hotel/Restaurant/Cafe  Other   7107  1012    2974    806
## 196 Hotel/Restaurant/Cafe  Other  17023  5139    5230   7888
## 197 Hotel/Restaurant/Cafe Oponto  30624  7209    4897  18711
## 198                Retail Oponto   2427  7097   10391   1127
## 199 Hotel/Restaurant/Cafe Oponto  11686  2154    6824   3527
## 200 Hotel/Restaurant/Cafe Oponto   9670  2280    2112    520
## 201                Retail Oponto   3067 13240   23127   3941
## 202                Retail Oponto   4484 14399   24708   3549
## 203 Hotel/Restaurant/Cafe Oponto  25203 11487    9490   5065
## 204 Hotel/Restaurant/Cafe Oponto    583   685    2216    469
## 205 Hotel/Restaurant/Cafe Oponto   1956   891    5226   1383
## 206                Retail Oponto   1107 11711   23596    955
## 207 Hotel/Restaurant/Cafe Oponto   6373   780     950    878
## 208                Retail Oponto   2541  4737    6089   2946
## 209 Hotel/Restaurant/Cafe Oponto   1537  3748    5838   1859
## 210                Retail Oponto   5550 12729   16767    864
## 211 Hotel/Restaurant/Cafe Oponto  18567  1895    1393   1801
## 212                Retail Oponto  12119 28326   39694   4736
## 213 Hotel/Restaurant/Cafe Oponto   7291  1012    2062   1291
## 214 Hotel/Restaurant/Cafe Oponto   3317  6602    6861   1329
## 215                Retail Oponto   2362  6551   11364    913
## 216 Hotel/Restaurant/Cafe Oponto   2806 10765   15538   1374
## 217                Retail Oponto   2532 16599   36486    179
## 218 Hotel/Restaurant/Cafe Oponto  18044  1475    2046   2532
## 219                Retail Oponto     18  7504   15205   1285
## 220 Hotel/Restaurant/Cafe Oponto   4155   367    1390   2306
## 221 Hotel/Restaurant/Cafe Oponto  14755   899    1382   1765
## 222 Hotel/Restaurant/Cafe Oponto   5396  7503   10646     91
## 223 Hotel/Restaurant/Cafe Oponto   5041  1115    2856   7496
## 224                Retail Oponto   2790  2527    5265   5612
## 225 Hotel/Restaurant/Cafe Oponto   7274   659    1499    784
## 226 Hotel/Restaurant/Cafe Oponto  12680  3243    4157    660
## 227                Retail Oponto  20782  5921    9212   1759
## 228 Hotel/Restaurant/Cafe Oponto   4042  2204    1563   2286
## 229 Hotel/Restaurant/Cafe Oponto   1869   577     572    950
## 230 Hotel/Restaurant/Cafe Oponto   8656  2746    2501   6845
## 231                Retail Oponto  11072  5989    5615   8321
## 232 Hotel/Restaurant/Cafe Oponto   2344 10678    3828   1439
## 233 Hotel/Restaurant/Cafe Oponto  25962  1780    3838    638
## 234 Hotel/Restaurant/Cafe Oponto    964  4984    3316    937
## 235 Hotel/Restaurant/Cafe Oponto  15603  2703    3833   4260
## 236 Hotel/Restaurant/Cafe Oponto   1838  6380    2824   1218
## 237 Hotel/Restaurant/Cafe Oponto   8635   820    3047   2312
## 238 Hotel/Restaurant/Cafe Oponto  18692  3838     593   4634
## 239 Hotel/Restaurant/Cafe Oponto   7363   475     585   1112
## 240 Hotel/Restaurant/Cafe Oponto  47493  2567    3779   5243
## 241 Hotel/Restaurant/Cafe Oponto  22096  3575    7041  11422
## 242 Hotel/Restaurant/Cafe Oponto  24929  1801    2475   2216
## 243 Hotel/Restaurant/Cafe Oponto  18226   659    2914   3752
## 244 Hotel/Restaurant/Cafe Oponto  11210  3576    5119    561
## 245 Hotel/Restaurant/Cafe Oponto   6202  7775   10817   1183
## 246                Retail Oponto   3062  6154   13916    230
## 247 Hotel/Restaurant/Cafe Oponto   8885  2428    1777   1777
## 248 Hotel/Restaurant/Cafe Oponto  13569   346     489   2077
## 249 Hotel/Restaurant/Cafe Oponto  15671  5279    2406    559
## 250 Hotel/Restaurant/Cafe Oponto   8040  3795    2070   6340
## 251 Hotel/Restaurant/Cafe Oponto   3191  1993    1799   1730
## 252                Retail Oponto   6134 23133   33586   6746
## 253 Hotel/Restaurant/Cafe Oponto   6623  1860    4740   7683
## 254 Hotel/Restaurant/Cafe Oponto  29526  7961   16966    432
## 255 Hotel/Restaurant/Cafe Oponto  10379 17972    4748   4686
## 256 Hotel/Restaurant/Cafe Oponto  31614   489    1495   3242
## 257 Hotel/Restaurant/Cafe Oponto  11092  5008    5249    453
## 258 Hotel/Restaurant/Cafe Oponto   8475  1931    1883   5004
## 259 Hotel/Restaurant/Cafe Oponto  56083  4563    2124   6422
## 260 Hotel/Restaurant/Cafe Oponto  53205  4959    7336   3012
## 261 Hotel/Restaurant/Cafe Oponto   9193  4885    2157    327
## 262 Hotel/Restaurant/Cafe Oponto   7858  1110    1094   6818
## 263 Hotel/Restaurant/Cafe Oponto  23257  1372    1677    982
## 264 Hotel/Restaurant/Cafe Oponto   2153  1115    6684   4324
## 265                Retail Oponto   1073  9679   15445     61
## 266 Hotel/Restaurant/Cafe Oponto   5909 23527   13699  10155
## 267                Retail Oponto    572  9763   22182   2221
## 268 Hotel/Restaurant/Cafe Oponto  20893  1222    2576   3975
## 269                Retail Oponto  11908  8053   19847   1069
## 270 Hotel/Restaurant/Cafe Oponto  15218   258    1138   2516
## 271 Hotel/Restaurant/Cafe Oponto   4720  1032     975   5500
## 272 Hotel/Restaurant/Cafe Oponto   2083  5007    1563   1120
## 273 Hotel/Restaurant/Cafe Oponto    514  8323    6869    529
## 274 Hotel/Restaurant/Cafe  Other  36817  3045    1493   4802
## 275 Hotel/Restaurant/Cafe  Other    894  1703    1841    744
## 276 Hotel/Restaurant/Cafe  Other    680  1610     223    862
## 277 Hotel/Restaurant/Cafe  Other  27901  3749    6964   4479
## 278 Hotel/Restaurant/Cafe  Other   9061   829     683  16919
## 279 Hotel/Restaurant/Cafe  Other  11693  2317    2543   5845
## 280                Retail  Other  17360  6200    9694   1293
## 281 Hotel/Restaurant/Cafe  Other   3366  2884    2431    977
## 282                Retail  Other  12238  7108    6235   1093
## 283 Hotel/Restaurant/Cafe  Other  49063  3965    4252   5970
## 284 Hotel/Restaurant/Cafe  Other  25767  3613    2013  10303
## 285 Hotel/Restaurant/Cafe  Other  68951  4411   12609   8692
## 286 Hotel/Restaurant/Cafe  Other  40254   640    3600   1042
## 287 Hotel/Restaurant/Cafe  Other   7149  2247    1242   1619
## 288 Hotel/Restaurant/Cafe  Other  15354  2102    2828   8366
## 289 Hotel/Restaurant/Cafe  Other  16260   594    1296    848
## 290 Hotel/Restaurant/Cafe  Other  42786   286     471   1388
## 291 Hotel/Restaurant/Cafe  Other   2708  2160    2642    502
## 292 Hotel/Restaurant/Cafe  Other   6022  3354    3261   2507
## 293 Hotel/Restaurant/Cafe  Other   2838  3086    4329   3838
## 294                Retail Lisbon   3996 11103   12469    902
## 295 Hotel/Restaurant/Cafe Lisbon  21273  2013    6550    909
## 296                Retail Lisbon   7588  1897    5234    417
## 297 Hotel/Restaurant/Cafe Lisbon  19087  1304    3643   3045
## 298                Retail Lisbon   8090  3199    6986   1455
## 299                Retail Lisbon   6758  4560    9965    934
## 300 Hotel/Restaurant/Cafe Lisbon    444   879    2060    264
## 301                Retail Lisbon  16448  6243    6360    824
## 302                Retail Lisbon   5283 13316   20399   1809
## 303                Retail Lisbon   2886  5302    9785    364
## 304                Retail Lisbon   2599  3688   13829    492
## 305                Retail Lisbon    161  7460   24773    617
## 306                Retail Lisbon    243 12939    8852    799
## 307                Retail Lisbon   6468 12867   21570   1840
## 308 Hotel/Restaurant/Cafe Lisbon  17327  2374    2842   1149
## 309 Hotel/Restaurant/Cafe Lisbon   6987  1020    3007    416
## 310                Retail Lisbon    918 20655   13567   1465
## 311 Hotel/Restaurant/Cafe Lisbon   7034  1492    2405  12569
## 312 Hotel/Restaurant/Cafe Lisbon  29635  2335    8280   3046
## 313                Retail Lisbon   2137  3737   19172   1274
## 314 Hotel/Restaurant/Cafe Lisbon   9784   925    2405   4447
## 315 Hotel/Restaurant/Cafe Lisbon  10617  1795    7647   1483
## 316                Retail Lisbon   1479 14982   11924    662
## 317 Hotel/Restaurant/Cafe Lisbon   7127  1375    2201   2679
## 318 Hotel/Restaurant/Cafe Lisbon   1182  3088    6114    978
## 319 Hotel/Restaurant/Cafe Lisbon  11800  2713    3558   2121
## 320                Retail Lisbon   9759 25071   17645   1128
## 321 Hotel/Restaurant/Cafe Lisbon   1774  3696    2280    514
## 322 Hotel/Restaurant/Cafe Lisbon   9155  1897    5167   2714
## 323 Hotel/Restaurant/Cafe Lisbon  15881   713    3315   3703
## 324 Hotel/Restaurant/Cafe Lisbon  13360   944   11593    915
## 325 Hotel/Restaurant/Cafe Lisbon  25977  3587    2464   2369
## 326 Hotel/Restaurant/Cafe Lisbon  32717 16784   13626  60869
## 327 Hotel/Restaurant/Cafe Lisbon   4414  1610    1431   3498
## 328 Hotel/Restaurant/Cafe Lisbon    542   899    1664    414
## 329 Hotel/Restaurant/Cafe Lisbon  16933  2209    3389   7849
## 330 Hotel/Restaurant/Cafe Lisbon   5113  1486    4583   5127
## 331 Hotel/Restaurant/Cafe Lisbon   9790  1786    5109   3570
## 332                Retail Lisbon  11223 14881   26839   1234
## 333 Hotel/Restaurant/Cafe Lisbon  22321  3216    1447   2208
## 334                Retail Lisbon   8565  4980   67298    131
## 335                Retail Lisbon  16823   928    2743  11559
## 336                Retail Lisbon  27082  6817   10790   1365
## 337 Hotel/Restaurant/Cafe Lisbon  13970  1511    1330    650
## 338 Hotel/Restaurant/Cafe Lisbon   9351  1347    2611   8170
## 339 Hotel/Restaurant/Cafe Lisbon      3   333    7021  15601
## 340 Hotel/Restaurant/Cafe Lisbon   2617  1188    5332   9584
## 341                Retail  Other    381  4025    9670    388
## 342                Retail  Other   2320  5763   11238    767
## 343 Hotel/Restaurant/Cafe  Other    255  5758    5923    349
## 344                Retail  Other   1689  6964   26316   1456
## 345 Hotel/Restaurant/Cafe  Other   3043  1172    1763   2234
## 346 Hotel/Restaurant/Cafe  Other   1198  2602    8335    402
## 347                Retail  Other   2771  6939   15541   2693
## 348                Retail  Other  27380  7184   12311   2809
## 349 Hotel/Restaurant/Cafe  Other   3428  2380    2028   1341
## 350                Retail  Other   5981 14641   20521   2005
## 351 Hotel/Restaurant/Cafe  Other   3521  1099    1997   1796
## 352                Retail  Other   1210 10044   22294   1741
## 353 Hotel/Restaurant/Cafe  Other    608  1106    1533    830
## 354                Retail  Other    117  6264   21203    228
## 355 Hotel/Restaurant/Cafe  Other  14039  7393    2548   6386
## 356 Hotel/Restaurant/Cafe  Other    190   727    2012    245
## 357 Hotel/Restaurant/Cafe  Other  22686   134     218   3157
## 358                Retail  Other     37  1275   22272    137
## 359 Hotel/Restaurant/Cafe  Other    759 18664    1660   6114
## 360 Hotel/Restaurant/Cafe  Other    796  5878    2109    340
## 361 Hotel/Restaurant/Cafe  Other  19746  2872    2006   2601
## 362 Hotel/Restaurant/Cafe  Other   4734   607     864   1206
## 363 Hotel/Restaurant/Cafe  Other   2121  1601    2453    560
## 364 Hotel/Restaurant/Cafe  Other   4627   997    4438    191
## 365 Hotel/Restaurant/Cafe  Other   2615   873    1524   1103
## 366                Retail  Other   4692  6128    8025   1619
## 367 Hotel/Restaurant/Cafe  Other   9561  2217    1664   1173
## 368 Hotel/Restaurant/Cafe  Other   3477   894     534   1457
## 369 Hotel/Restaurant/Cafe  Other  22335  1196    2406   2046
## 370 Hotel/Restaurant/Cafe  Other   6211   337     683   1089
## 371                Retail  Other  39679  3944    4955   1364
## 372 Hotel/Restaurant/Cafe  Other  20105  1887    1939   8164
## 373 Hotel/Restaurant/Cafe  Other   3884  3801    1641    876
## 374                Retail  Other  15076  6257    7398   1504
## 375 Hotel/Restaurant/Cafe  Other   6338  2256    1668   1492
## 376 Hotel/Restaurant/Cafe  Other   5841  1450    1162    597
## 377                Retail  Other   3136  8630   13586   5641
## 378 Hotel/Restaurant/Cafe  Other  38793  3154    2648   1034
## 379 Hotel/Restaurant/Cafe  Other   3225  3294    1902    282
## 380                Retail  Other   4048  5164   10391    130
## 381 Hotel/Restaurant/Cafe  Other  28257   944    2146   3881
## 382 Hotel/Restaurant/Cafe  Other  17770  4591    1617   9927
## 383 Hotel/Restaurant/Cafe  Other  34454  7435    8469   2540
## 384 Hotel/Restaurant/Cafe  Other   1821  1364    3450   4006
## 385 Hotel/Restaurant/Cafe  Other  10683 21858   15400   3635
## 386 Hotel/Restaurant/Cafe  Other  11635   922    1614   2583
## 387 Hotel/Restaurant/Cafe  Other   1206  3620    2857   1945
## 388 Hotel/Restaurant/Cafe  Other  20918  1916    1573   1960
## 389 Hotel/Restaurant/Cafe  Other   9785   848    1172   1677
## 390 Hotel/Restaurant/Cafe  Other   9385  1530    1422   3019
## 391 Hotel/Restaurant/Cafe  Other   3352  1181    1328   5502
## 392 Hotel/Restaurant/Cafe  Other   2647  2761    2313    907
## 393 Hotel/Restaurant/Cafe  Other    518  4180    3600    659
## 394 Hotel/Restaurant/Cafe  Other  23632  6730    3842   8620
## 395 Hotel/Restaurant/Cafe  Other  12377   865    3204   1398
## 396 Hotel/Restaurant/Cafe  Other   9602  1316    1263   2921
## 397                Retail  Other   4515 11991    9345   2644
## 398 Hotel/Restaurant/Cafe  Other  11535  1666    1428   6838
## 399 Hotel/Restaurant/Cafe  Other  11442  1032     582   5390
## 400 Hotel/Restaurant/Cafe  Other   9612   577     935   1601
## 401 Hotel/Restaurant/Cafe  Other   4446   906    1238   3576
## 402 Hotel/Restaurant/Cafe  Other  27167  2801    2128  13223
## 403 Hotel/Restaurant/Cafe  Other  26539  4753    5091    220
## 404 Hotel/Restaurant/Cafe  Other  25606 11006    4604    127
## 405 Hotel/Restaurant/Cafe  Other  18073  4613    3444   4324
## 406 Hotel/Restaurant/Cafe  Other   6884  1046    1167   2069
## 407 Hotel/Restaurant/Cafe  Other  25066  5010    5026   9806
## 408                Retail  Other   7362 12844   18683   2854
## 409                Retail  Other   8257  3880    6407   1646
## 410 Hotel/Restaurant/Cafe  Other   8708  3634    6100   2349
## 411 Hotel/Restaurant/Cafe  Other   6633  2096    4563   1389
## 412 Hotel/Restaurant/Cafe  Other   2126  3289    3281   1535
## 413 Hotel/Restaurant/Cafe  Other     97  3605   12400     98
## 414 Hotel/Restaurant/Cafe  Other   4983  4859    6633  17866
## 415 Hotel/Restaurant/Cafe  Other   5969  1990    3417   5679
## 416                Retail  Other   7842  6046    8552   1691
## 417                Retail  Other   4389 10940   10908    848
## 418 Hotel/Restaurant/Cafe  Other   5065  5499   11055    364
## 419                Retail  Other    660  8494   18622    133
## 420 Hotel/Restaurant/Cafe  Other   8861  3783    2223    633
## 421 Hotel/Restaurant/Cafe  Other   4456  5266   13227     25
## 422                Retail  Other  17063  4847    9053   1031
## 423 Hotel/Restaurant/Cafe  Other  26400  1377    4172    830
## 424                Retail  Other  17565  3686    4657   1059
## 425                Retail  Other  16980  2884   12232    874
## 426 Hotel/Restaurant/Cafe  Other  11243  2408    2593  15348
## 427 Hotel/Restaurant/Cafe  Other  13134  9347   14316   3141
## 428 Hotel/Restaurant/Cafe  Other  31012 16687    5429  15082
## 429 Hotel/Restaurant/Cafe  Other   3047  5970    4910   2198
## 430 Hotel/Restaurant/Cafe  Other   8607  1750    3580     47
## 431 Hotel/Restaurant/Cafe  Other   3097  4230   16483    575
## 432 Hotel/Restaurant/Cafe  Other   8533  5506    5160  13486
## 433 Hotel/Restaurant/Cafe  Other  21117  1162    4754    269
## 434 Hotel/Restaurant/Cafe  Other   1982  3218    1493   1541
## 435 Hotel/Restaurant/Cafe  Other  16731  3922    7994    688
## 436 Hotel/Restaurant/Cafe  Other  29703 12051   16027  13135
## 437 Hotel/Restaurant/Cafe  Other  39228  1431     764   4510
## 438                Retail  Other  14531 15488   30243    437
## 439 Hotel/Restaurant/Cafe  Other  10290  1981    2232   1038
## 440 Hotel/Restaurant/Cafe  Other   2787  1698    2510     65
##     Detergents_Paper Delicassen
## 1               2674       1338
## 2               3293       1776
## 3               3516       7844
## 4                507       1788
## 5               1777       5185
## 6               1795       1451
## 7               3140        545
## 8               3321       2566
## 9               1716        750
## 10              7425       2098
## 11              5977       1744
## 12               549        497
## 13              3881       2931
## 14              6707        602
## 15              5058       2168
## 16               964        412
## 17              4508       1080
## 18               370       4478
## 19              2767       3181
## 20              2518        501
## 21              2259       2124
## 22               375        569
## 23              2381       4334
## 24              4337      16523
## 25              4482       5778
## 26              4003         57
## 27               242        833
## 28               100        518
## 29              8604       5206
## 30              1107        823
## 31              2134       2963
## 32               820        985
## 33               918        405
## 34               361       1083
## 35               483        395
## 36              4239        436
## 37               862       4626
## 38              6506        714
## 39              6956        433
## 40               212       2916
## 41              1145       5864
## 42              2575       2802
## 43              6899         46
## 44              9529         72
## 45              4618         65
## 46              7353       4985
## 47              6792       1452
## 48             24171       6465
## 49              5121       1476
## 50             13583       1163
## 51               609       2162
## 52              1538        301
## 53              2587       1278
## 54              5611        224
## 55               204       1333
## 56              2024       1130
## 57             17740       1340
## 58              7572       1282
## 59               227        436
## 60              3084       1603
## 61              4095        225
## 62             26701       2017
## 63              4074        964
## 64              7677       1295
## 65              1247       1145
## 66             24231       1423
## 67              3468         27
## 68              5141        834
## 69               788       3095
## 70               656        144
## 71               116       1365
## 72              4173      14472
## 73              1321        181
## 74               764        648
## 75              1901       1780
## 76                 3        975
## 77               529        894
## 78             12034       1009
## 79               301        167
## 80              1202       1653
## 81               610        529
## 82              7818        156
## 83              3537       2342
## 84               550        772
## 85              3837        120
## 86             40827       2944
## 87             20070        903
## 88              1579      14351
## 89               165         46
## 90               454       3178
## 91                69        360
## 92               627       1117
## 93             18906       5130
## 94                71       2698
## 95              5038        244
## 96               223        709
## 97              3874        217
## 98                54         63
## 99                56        132
## 100              215        323
## 101             8035       3029
## 102             6766       1838
## 103             4573       1386
## 104             1480       2498
## 105             1491        548
## 106              139       1378
## 107             6830       1831
## 108             8969       1438
## 109             2505       1236
## 110              836          3
## 111              169       1647
## 112             6457       1519
## 113              483       2708
## 114              585       1561
## 115              118       1266
## 116              276        610
## 117              310        222
## 118              319       1160
## 119              411        933
## 120              266        635
## 121              174       1136
## 122              264        255
## 123               25        860
## 124             1976        143
## 125              500       1621
## 126              778        918
## 127              349        483
## 128             2386       2749
## 129             1062          3
## 130              410       1819
## 131              395        911
## 132               70        310
## 133              955        328
## 134              256        396
## 135               47        537
## 136              199        326
## 137             2447       1542
## 138              721         36
## 139              249       3271
## 140              637        929
## 141              960       2616
## 142               51       1450
## 143               20          3
## 144              399        318
## 145              516        201
## 146            12591       4430
## 147               73        520
## 148             1082        526
## 149              283        434
## 150              113       1440
## 151              170       1067
## 152              255       1774
## 153              352        184
## 154              302       1627
## 155                7          8
## 156            11577       2153
## 157             6694       3182
## 158              811        418
## 159             4004       1682
## 160             8077        303
## 161             4424       2157
## 162                3       2233
## 163              232        610
## 164            13726        446
## 165             3674        238
## 166             7108       2379
## 167             4973       3637
## 168             1680        693
## 169               79        429
## 170               69        750
## 171             7015        323
## 172             8773       6250
## 173             2840        707
## 174             9836        716
## 175              153       1442
## 176             4196       1697
## 177             1532        230
## 178               20       2631
## 179              120        395
## 180              273       2165
## 181             1382       2794
## 182             4948       8550
## 183             6907        156
## 184              239      47943
## 185              334         11
## 186               58        247
## 187              949        727
## 188             3459          3
## 189             6839        404
## 190             4027       1856
## 191              118         64
## 192               43         84
## 193              187        409
## 194             5618        666
## 195              355       1142
## 196              330       1755
## 197              763       2876
## 198             4314       1468
## 199              592        697
## 200              402        347
## 201             9959        731
## 202            14235       1681
## 203              284       6854
## 204              954         18
## 205                5       1328
## 206             9265        710
## 207              288        285
## 208             5316        120
## 209             3381        806
## 210            12420        797
## 211              244       2100
## 212            19410       2870
## 213              240       1775
## 214             3961       1215
## 215             5957        791
## 216             5828       2388
## 217            13308        674
## 218              130       1158
## 219             4797       6372
## 220               86        130
## 221               56        749
## 222             4167        239
## 223              256        375
## 224              788       1360
## 225               70        659
## 226              761        786
## 227             2568       1553
## 228              263        689
## 229             4762        203
## 230              694        980
## 231              955       2137
## 232             1566        490
## 233              284        834
## 234              409          7
## 235              325       2563
## 236             1216        295
## 237              415        225
## 238               28       1215
## 239               72        216
## 240              828       2253
## 241              343       2564
## 242              412       1047
## 243              586        578
## 244             1682       2398
## 245             3143       1970
## 246             8933       2784
## 247              430        610
## 248               44        659
## 249              562        572
## 250              918        291
## 251              234        710
## 252            18594       5121
## 253              205       1693
## 254              363       1391
## 255             1547       3265
## 256              111        615
## 257              392        373
## 258             3593        987
## 259              730       3321
## 260              967        818
## 261              780        548
## 262               49        287
## 263              429        655
## 264             2894        411
## 265             5980       1265
## 266              830       3636
## 267             4882       2563
## 268              737       3628
## 269             6374        698
## 270              333        204
## 271              197         56
## 272              147       1550
## 273               93       1040
## 274              210       1824
## 275              759       1153
## 276               96        379
## 277              603       2503
## 278              621        139
## 279              274       1409
## 280             3620       1721
## 281              167       1104
## 282             2328       2079
## 283             1041       1404
## 284              314       1384
## 285              751       2406
## 286              436         18
## 287             1226        128
## 288              386       1027
## 289              445        258
## 290               32         22
## 291              965       1522
## 292              212        686
## 293              825       1060
## 294             5952        741
## 295              811       1854
## 296             2208        254
## 297              710        898
## 298             3712        531
## 299             4538       1037
## 300              290        259
## 301             2662       2005
## 302             8752        172
## 303             6236        555
## 304            10069         59
## 305            11783       2410
## 306             3909        211
## 307             7558       1543
## 308              351        925
## 309              257        656
## 310             6846        806
## 311              299       1117
## 312              371        117
## 313            17120        142
## 314              183        297
## 315              857       1233
## 316             3891       3508
## 317               83       1059
## 318              821       1637
## 319              706         51
## 320            12408       1625
## 321              275        834
## 322              228       1113
## 323             1470        229
## 324             1679        573
## 325              140       1092
## 326             1272       5609
## 327              387        834
## 328               88        522
## 329              210       1534
## 330              492        739
## 331              182       1043
## 332             9606       1102
## 333              178       2602
## 334            38102       1215
## 335              332       3486
## 336             4111       2139
## 337              146        778
## 338              442        868
## 339               15        550
## 340              573       1942
## 341             7271       1371
## 342             5162       2158
## 343             4595       1328
## 344            15469         37
## 345              217        379
## 346             3843        303
## 347             6600       1115
## 348             4621       1022
## 349             1184        665
## 350            12218        445
## 351              173        995
## 352            12638       3137
## 353               90        195
## 354             8682       1111
## 355             1333       2341
## 356              184        127
## 357                9        548
## 358             6747        110
## 359              536       4100
## 360              232        776
## 361              468        503
## 362              159        405
## 363              179        712
## 364             1335        314
## 365              514        468
## 366             4515       3105
## 367              222        447
## 368              252        342
## 369              101        558
## 370               41        296
## 371              523       2235
## 372              716        790
## 373              397       4829
## 374             1916       3113
## 375              311        686
## 376              476         70
## 377             4666       1426
## 378               96       1242
## 379               68       1114
## 380              813        179
## 381              600        270
## 382              246        532
## 383             1711       2893
## 384              397        361
## 385              282       5120
## 386              192       1068
## 387              353        967
## 388              231        961
## 389              200        406
## 390              227        684
## 391              311       1000
## 392               95       1827
## 393              122        654
## 394              385        819
## 395              149        452
## 396              841        290
## 397             3378       2213
## 398               64        743
## 399               74        247
## 400              469        375
## 401              153       1014
## 402               92       1902
## 403               10        340
## 404              632        288
## 405              914        715
## 406              593        378
## 407             1092        960
## 408             7883        553
## 409             2730        344
## 410             2123       5137
## 411             1860       1892
## 412              235       4365
## 413             2970         62
## 414              912       2435
## 415             1135        290
## 416             3540       1874
## 417             6728        993
## 418             3485       1063
## 419             6740        776
## 420             1580       1521
## 421             6818       1393
## 422             3415       1784
## 423              948       1218
## 424             1803        668
## 425             3213        249
## 426              108       1886
## 427             5079       1894
## 428              439       1163
## 429              850        317
## 430               84       2501
## 431              241       2080
## 432             1377       1498
## 433             1328        395
## 434              356       1449
## 435             2371        838
## 436              182       2204
## 437               93       2346
## 438            14841       1867
## 439              168       2125
## 440              477         52
str(wholesaled)
## 'data.frame':    440 obs. of  8 variables:
##  $ Channel         : Factor w/ 2 levels "Hotel/Restaurant/Cafe",..: 2 2 2 1 2 2 2 2 1 2 ...
##  $ Region          : Factor w/ 3 levels "Lisbon","Oponto",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ Fresh           : int  12669 7057 6353 13265 22615 9413 12126 7579 5963 6006 ...
##  $ Milk            : int  9656 9810 8808 1196 5410 8259 3199 4956 3648 11093 ...
##  $ Grocery         : int  7561 9568 7684 4221 7198 5126 6975 9426 6192 18881 ...
##  $ Frozen          : int  214 1762 2405 6404 3915 666 480 1669 425 1159 ...
##  $ Detergents_Paper: int  2674 3293 3516 507 1777 1795 3140 3321 1716 7425 ...
##  $ Delicassen      : int  1338 1776 7844 1788 5185 1451 545 2566 750 2098 ...
random<- runif(nrow(wholesaled))
wholesaleF<-wholesaled[order(random),]
wholesaleF
##                   Channel Region  Fresh  Milk Grocery Frozen
## 383 Hotel/Restaurant/Cafe  Other  34454  7435    8469   2540
## 361 Hotel/Restaurant/Cafe  Other  19746  2872    2006   2601
## 258 Hotel/Restaurant/Cafe Oponto   8475  1931    1883   5004
## 7                  Retail  Other  12126  3199    6975    480
## 64                 Retail  Other   9396 11601   15775   2896
## 73  Hotel/Restaurant/Cafe  Other   4420  5139    2661   8872
## 268 Hotel/Restaurant/Cafe Oponto  20893  1222    2576   3975
## 399 Hotel/Restaurant/Cafe  Other  11442  1032     582   5390
## 186 Hotel/Restaurant/Cafe  Other   8170  6448    1139   2181
## 275 Hotel/Restaurant/Cafe  Other    894  1703    1841    744
## 98  Hotel/Restaurant/Cafe  Other    403   254     610    774
## 338 Hotel/Restaurant/Cafe Lisbon   9351  1347    2611   8170
## 262 Hotel/Restaurant/Cafe Oponto   7858  1110    1094   6818
## 222 Hotel/Restaurant/Cafe Oponto   5396  7503   10646     91
## 347                Retail  Other   2771  6939   15541   2693
## 101                Retail  Other  11594  7779   12144   3252
## 110                Retail  Other   1406 16729   28986    673
## 24                 Retail  Other  26373 36423   22019   5154
## 62                 Retail  Other  35942 38369   59598   3254
## 350                Retail  Other   5981 14641   20521   2005
## 30  Hotel/Restaurant/Cafe  Other  43088  2100    2609   1200
## 269                Retail Oponto  11908  8053   19847   1069
## 69  Hotel/Restaurant/Cafe  Other   2446  7260    3993   5870
## 427 Hotel/Restaurant/Cafe  Other  13134  9347   14316   3141
## 255 Hotel/Restaurant/Cafe Oponto  10379 17972    4748   4686
## 78                 Retail  Other  12205 12697   28540    869
## 168 Hotel/Restaurant/Cafe  Other   2926  3195    3268    405
## 51  Hotel/Restaurant/Cafe  Other   6269  1095    1980   3860
## 184 Hotel/Restaurant/Cafe  Other  36847 43950   20170  36534
## 153 Hotel/Restaurant/Cafe  Other  18840  1371    3135   3001
## 165                Retail  Other   5224  7603    8584   2540
## 75                 Retail  Other   8190  6343    9794   1285
## 408                Retail  Other   7362 12844   18683   2854
## 266 Hotel/Restaurant/Cafe Oponto   5909 23527   13699  10155
## 112                Retail  Other  12579 11114   17569    805
## 378 Hotel/Restaurant/Cafe  Other  38793  3154    2648   1034
## 424                Retail  Other  17565  3686    4657   1059
## 95                 Retail  Other   5626 12220   11323    206
## 233 Hotel/Restaurant/Cafe Oponto  25962  1780    3838    638
## 384 Hotel/Restaurant/Cafe  Other   1821  1364    3450   4006
## 1                  Retail  Other  12669  9656    7561    214
## 386 Hotel/Restaurant/Cafe  Other  11635   922    1614   2583
## 298                Retail Lisbon   8090  3199    6986   1455
## 179 Hotel/Restaurant/Cafe  Other  11002  7075    4945   1152
## 265                Retail Oponto   1073  9679   15445     61
## 71  Hotel/Restaurant/Cafe  Other  16705  2037    3202  10643
## 114 Hotel/Restaurant/Cafe  Other  14438  2295    1733   3220
## 119 Hotel/Restaurant/Cafe  Other  20049  1891    2362   5343
## 133 Hotel/Restaurant/Cafe  Other  14903  2032    2479    576
## 193 Hotel/Restaurant/Cafe  Other   5509  1461    2251    547
## 108                Retail  Other   8797 10646   14886   2471
## 353 Hotel/Restaurant/Cafe  Other    608  1106    1533    830
## 94  Hotel/Restaurant/Cafe  Other  11314  3090    2062  35009
## 419                Retail  Other    660  8494   18622    133
## 225 Hotel/Restaurant/Cafe Oponto   7274   659    1499    784
## 105 Hotel/Restaurant/Cafe  Other  14100  2132    3445   1336
## 93                 Retail  Other   9198 27472   32034   3232
## 83                 Retail  Other  10362  9232   11009    737
## 315 Hotel/Restaurant/Cafe Lisbon  10617  1795    7647   1483
## 55  Hotel/Restaurant/Cafe  Other  27329  1449    1947   2436
## 324 Hotel/Restaurant/Cafe Lisbon  13360   944   11593    915
## 107                Retail  Other   1454  6337   10704    133
## 23  Hotel/Restaurant/Cafe  Other  31276  1917    4469   9408
## 89  Hotel/Restaurant/Cafe  Other   7864   542    4042   9735
## 91  Hotel/Restaurant/Cafe  Other  11405   596    1638   3347
## 395 Hotel/Restaurant/Cafe  Other  12377   865    3204   1398
## 59  Hotel/Restaurant/Cafe  Other  13779  1970    1648    596
## 35  Hotel/Restaurant/Cafe  Other   1502  1979    2262    425
## 213 Hotel/Restaurant/Cafe Oponto   7291  1012    2062   1291
## 328 Hotel/Restaurant/Cafe Lisbon    542   899    1664    414
## 19                 Retail  Other  18601  6327   10099   2205
## 406 Hotel/Restaurant/Cafe  Other   6884  1046    1167   2069
## 307                Retail Lisbon   6468 12867   21570   1840
## 317 Hotel/Restaurant/Cafe Lisbon   7127  1375    2201   2679
## 388 Hotel/Restaurant/Cafe  Other  20918  1916    1573   1960
## 334                Retail Lisbon   8565  4980   67298    131
## 85                 Retail  Other  11867  3327    4814   1178
## 316                Retail Lisbon   1479 14982   11924    662
## 321 Hotel/Restaurant/Cafe Lisbon   1774  3696    2280    514
## 426 Hotel/Restaurant/Cafe  Other  11243  2408    2593  15348
## 351 Hotel/Restaurant/Cafe  Other   3521  1099    1997   1796
## 37  Hotel/Restaurant/Cafe  Other  29955  4362    5428   1729
## 104 Hotel/Restaurant/Cafe  Other  56082  3504    8906  18028
## 209 Hotel/Restaurant/Cafe Oponto   1537  3748    5838   1859
## 382 Hotel/Restaurant/Cafe  Other  17770  4591    1617   9927
## 236 Hotel/Restaurant/Cafe Oponto   1838  6380    2824   1218
## 385 Hotel/Restaurant/Cafe  Other  10683 21858   15400   3635
## 414 Hotel/Restaurant/Cafe  Other   4983  4859    6633  17866
## 243 Hotel/Restaurant/Cafe Oponto  18226   659    2914   3752
## 25                 Retail  Other  22647  9776   13792   2915
## 115 Hotel/Restaurant/Cafe  Other  18044  1080    2000   2555
## 164                Retail  Other   5531 15726   26870   2367
## 152 Hotel/Restaurant/Cafe  Other   1289  3328    2022    531
## 20  Hotel/Restaurant/Cafe  Other   7780  2495    9464    669
## 8                  Retail  Other   7579  4956    9426   1669
## 368 Hotel/Restaurant/Cafe  Other   3477   894     534   1457
## 155 Hotel/Restaurant/Cafe  Other    622    55     137     75
## 65  Hotel/Restaurant/Cafe  Other   4760  1227    3250   3724
## 294                Retail Lisbon   3996 11103   12469    902
## 49                 Retail  Other  11519  6152   10868    584
## 242 Hotel/Restaurant/Cafe Oponto  24929  1801    2475   2216
## 127 Hotel/Restaurant/Cafe  Other  19219  1840    1658   8195
## 223 Hotel/Restaurant/Cafe Oponto   5041  1115    2856   7496
## 38                 Retail  Other  15168 10556   12477   1920
## 257 Hotel/Restaurant/Cafe Oponto  11092  5008    5249    453
## 253 Hotel/Restaurant/Cafe Oponto   6623  1860    4740   7683
## 372 Hotel/Restaurant/Cafe  Other  20105  1887    1939   8164
## 32  Hotel/Restaurant/Cafe  Other   2612  4339    3133   2088
## 279 Hotel/Restaurant/Cafe  Other  11693  2317    2543   5845
## 18  Hotel/Restaurant/Cafe  Other   5876  6157    2933    839
## 264 Hotel/Restaurant/Cafe Oponto   2153  1115    6684   4324
## 342                Retail  Other   2320  5763   11238    767
## 435 Hotel/Restaurant/Cafe  Other  16731  3922    7994    688
## 430 Hotel/Restaurant/Cafe  Other   8607  1750    3580     47
## 118 Hotel/Restaurant/Cafe  Other   6990  3880    5380   1647
## 254 Hotel/Restaurant/Cafe Oponto  29526  7961   16966    432
## 103                Retail  Other   2932  6459    7677   2561
## 212                Retail Oponto  12119 28326   39694   4736
## 286 Hotel/Restaurant/Cafe  Other  40254   640    3600   1042
## 13                 Retail  Other  31714 12319   11757    287
## 126 Hotel/Restaurant/Cafe  Other  76237  3473    7102  16538
## 17                 Retail  Other   1020  8816   12121    134
## 288 Hotel/Restaurant/Cafe  Other  15354  2102    2828   8366
## 15                 Retail  Other  24653  9465   12091    294
## 381 Hotel/Restaurant/Cafe  Other  28257   944    2146   3881
## 97                 Retail  Other     23  2616    8118    145
## 22  Hotel/Restaurant/Cafe  Other   5567   871    2010   3383
## 180 Hotel/Restaurant/Cafe  Other   3157  4888    2500   4477
## 33  Hotel/Restaurant/Cafe  Other  21632  1318    2886    266
## 375 Hotel/Restaurant/Cafe  Other   6338  2256    1668   1492
## 238 Hotel/Restaurant/Cafe Oponto  18692  3838     593   4634
## 207 Hotel/Restaurant/Cafe Oponto   6373   780     950    878
## 67  Hotel/Restaurant/Cafe  Other      9  1534    7417    175
## 300 Hotel/Restaurant/Cafe Lisbon    444   879    2060    264
## 99  Hotel/Restaurant/Cafe  Other    503   112     778    895
## 52  Hotel/Restaurant/Cafe  Other   3347  4051    6996    239
## 189                Retail  Other   8040  7639   11687   2758
## 346 Hotel/Restaurant/Cafe  Other   1198  2602    8335    402
## 88  Hotel/Restaurant/Cafe  Other  43265  5025    8117   6312
## 43                 Retail  Other  10850  7555   14961    188
## 21                 Retail  Other  17546  4519    4602   1066
## 63                 Retail  Other   7823  6245    6544   4154
## 203 Hotel/Restaurant/Cafe Oponto  25203 11487    9490   5065
## 130 Hotel/Restaurant/Cafe  Other  42312   926    1510   1718
## 79  Hotel/Restaurant/Cafe  Other  10766  1175    2067   2096
## 143 Hotel/Restaurant/Cafe  Other  37036  7152    8253   2995
## 170 Hotel/Restaurant/Cafe  Other   5414   717    2155   2399
## 106 Hotel/Restaurant/Cafe  Other  15587  1014    3970    910
## 364 Hotel/Restaurant/Cafe  Other   4627   997    4438    191
## 45                 Retail  Other   9670  7027   10471    541
## 224                Retail Oponto   2790  2527    5265   5612
## 228 Hotel/Restaurant/Cafe Oponto   4042  2204    1563   2286
## 429 Hotel/Restaurant/Cafe  Other   3047  5970    4910   2198
## 325 Hotel/Restaurant/Cafe Lisbon  25977  3587    2464   2369
## 175 Hotel/Restaurant/Cafe  Other    286  1208    5241   2515
## 423 Hotel/Restaurant/Cafe  Other  26400  1377    4172    830
## 280                Retail  Other  17360  6200    9694   1293
## 182 Hotel/Restaurant/Cafe  Other 112151 29627   18148  16745
## 319 Hotel/Restaurant/Cafe Lisbon  11800  2713    3558   2121
## 301                Retail Lisbon  16448  6243    6360    824
## 145 Hotel/Restaurant/Cafe  Other  18827  3677    1988    118
## 271 Hotel/Restaurant/Cafe Oponto   4720  1032     975   5500
## 400 Hotel/Restaurant/Cafe  Other   9612   577     935   1601
## 326 Hotel/Restaurant/Cafe Lisbon  32717 16784   13626  60869
## 281 Hotel/Restaurant/Cafe  Other   3366  2884    2431    977
## 345 Hotel/Restaurant/Cafe  Other   3043  1172    1763   2234
## 337 Hotel/Restaurant/Cafe Lisbon  13970  1511    1330    650
## 159                Retail  Other   2861  6570    9618    930
## 273 Hotel/Restaurant/Cafe Oponto    514  8323    6869    529
## 437 Hotel/Restaurant/Cafe  Other  39228  1431     764   4510
## 77  Hotel/Restaurant/Cafe  Other    717  3587    6532   7530
## 336                Retail Lisbon  27082  6817   10790   1365
## 87                 Retail  Other  22925 73498   32114    987
## 376 Hotel/Restaurant/Cafe  Other   5841  1450    1162    597
## 323 Hotel/Restaurant/Cafe Lisbon  15881   713    3315   3703
## 208                Retail Oponto   2541  4737    6089   2946
## 313                Retail Lisbon   2137  3737   19172   1274
## 314 Hotel/Restaurant/Cafe Lisbon   9784   925    2405   4447
## 318 Hotel/Restaurant/Cafe Lisbon   1182  3088    6114    978
## 340 Hotel/Restaurant/Cafe Lisbon   2617  1188    5332   9584
## 420 Hotel/Restaurant/Cafe  Other   8861  3783    2223    633
## 292 Hotel/Restaurant/Cafe  Other   6022  3354    3261   2507
## 410 Hotel/Restaurant/Cafe  Other   8708  3634    6100   2349
## 402 Hotel/Restaurant/Cafe  Other  27167  2801    2128  13223
## 416                Retail  Other   7842  6046    8552   1691
## 379 Hotel/Restaurant/Cafe  Other   3225  3294    1902    282
## 221 Hotel/Restaurant/Cafe Oponto  14755   899    1382   1765
## 134 Hotel/Restaurant/Cafe  Other   9434  1042    1235    436
## 177 Hotel/Restaurant/Cafe  Other  45640  6958    6536   7368
## 241 Hotel/Restaurant/Cafe Oponto  22096  3575    7041  11422
## 428 Hotel/Restaurant/Cafe  Other  31012 16687    5429  15082
## 174                Retail  Other    514  7677   19805    937
## 327 Hotel/Restaurant/Cafe Lisbon   4414  1610    1431   3498
## 282                Retail  Other  12238  7108    6235   1093
## 161                Retail  Other   1725  3651   12822    824
## 167                Retail  Other   4822  6721    9170    993
## 163 Hotel/Restaurant/Cafe  Other  15177  2024    3810   2665
## 109                Retail  Other   1531  8397    6981    247
## 151 Hotel/Restaurant/Cafe  Other  16225  1825    1765    853
## 433 Hotel/Restaurant/Cafe  Other  21117  1162    4754    269
## 304                Retail Lisbon   2599  3688   13829    492
## 306                Retail Lisbon    243 12939    8852    799
## 31  Hotel/Restaurant/Cafe  Other  18815  3610   11107   1148
## 287 Hotel/Restaurant/Cafe  Other   7149  2247    1242   1619
## 363 Hotel/Restaurant/Cafe  Other   2121  1601    2453    560
## 136 Hotel/Restaurant/Cafe  Other   6300  1289    2591   1170
## 82                 Retail  Other    219  9540   14403    283
## 335                Retail Lisbon  16823   928    2743  11559
## 246                Retail Oponto   3062  6154   13916    230
## 181 Hotel/Restaurant/Cafe  Other  12356  6036    8887    402
## 219                Retail Oponto     18  7504   15205   1285
## 144 Hotel/Restaurant/Cafe  Other  10405  1596    1096   8425
## 48                 Retail  Other  44466 54259   55571   7782
## 125 Hotel/Restaurant/Cafe  Other  36050  1642    2961   4787
## 359 Hotel/Restaurant/Cafe  Other    759 18664    1660   6114
## 374                Retail  Other  15076  6257    7398   1504
## 239 Hotel/Restaurant/Cafe Oponto   7363   475     585   1112
## 57                 Retail  Other   4098 29892   26866   2616
## 230 Hotel/Restaurant/Cafe Oponto   8656  2746    2501   6845
## 129 Hotel/Restaurant/Cafe  Other    140  8847    3823    142
## 226 Hotel/Restaurant/Cafe Oponto  12680  3243    4157    660
## 46                 Retail  Other   5181 22044   21531   1740
## 141 Hotel/Restaurant/Cafe  Other  17623  4280    7305   2279
## 128                Retail  Other  21465  7243   10685    880
## 56  Hotel/Restaurant/Cafe  Other   5264  3683    5005   1057
## 54                 Retail  Other    491 10473   11532    744
## 276 Hotel/Restaurant/Cafe  Other    680  1610     223    862
## 34  Hotel/Restaurant/Cafe  Other  29729  4786    7326   6130
## 68                 Retail  Other  19913  6759   13462   1256
## 229 Hotel/Restaurant/Cafe Oponto   1869   577     572    950
## 96  Hotel/Restaurant/Cafe  Other      3  2920    6252    440
## 417                Retail  Other   4389 10940   10908    848
## 10                 Retail  Other   6006 11093   18881   1159
## 343 Hotel/Restaurant/Cafe  Other    255  5758    5923    349
## 76  Hotel/Restaurant/Cafe  Other  20398  1137       3   4407
## 260 Hotel/Restaurant/Cafe Oponto  53205  4959    7336   3012
## 27  Hotel/Restaurant/Cafe  Other   9898   961    2861   3151
## 205 Hotel/Restaurant/Cafe Oponto   1956   891    5226   1383
## 202                Retail Oponto   4484 14399   24708   3549
## 251 Hotel/Restaurant/Cafe Oponto   3191  1993    1799   1730
## 398 Hotel/Restaurant/Cafe  Other  11535  1666    1428   6838
## 303                Retail Lisbon   2886  5302    9785    364
## 84  Hotel/Restaurant/Cafe  Other  20874  1563    1783   2320
## 278 Hotel/Restaurant/Cafe  Other   9061   829     683  16919
## 12                 Retail  Other  13146  1124    4523   1420
## 309 Hotel/Restaurant/Cafe Lisbon   6987  1020    3007    416
## 41  Hotel/Restaurant/Cafe  Other  24025  4332    4757   9510
## 160                Retail  Other    355  7704   14682    398
## 362 Hotel/Restaurant/Cafe  Other   4734   607     864   1206
## 178 Hotel/Restaurant/Cafe  Other  12759  7330    4533   1752
## 256 Hotel/Restaurant/Cafe Oponto  31614   489    1495   3242
## 70  Hotel/Restaurant/Cafe  Other   8352  2820    1293    779
## 397                Retail  Other   4515 11991    9345   2644
## 102                Retail  Other   1420 10810   16267   1593
## 148 Hotel/Restaurant/Cafe  Other   9203  3373    2707   1286
## 211 Hotel/Restaurant/Cafe Oponto  18567  1895    1393   1801
## 215                Retail Oponto   2362  6551   11364    913
## 232 Hotel/Restaurant/Cafe Oponto   2344 10678    3828   1439
## 235 Hotel/Restaurant/Cafe Oponto  15603  2703    3833   4260
## 405 Hotel/Restaurant/Cafe  Other  18073  4613    3444   4324
## 248 Hotel/Restaurant/Cafe Oponto  13569   346     489   2077
## 162 Hotel/Restaurant/Cafe  Other  12434   540     283   1092
## 150 Hotel/Restaurant/Cafe  Other  31812  1433    1651    800
## 172                Retail  Other    200 25862   19816    651
## 259 Hotel/Restaurant/Cafe Oponto  56083  4563    2124   6422
## 440 Hotel/Restaurant/Cafe  Other   2787  1698    2510     65
## 357 Hotel/Restaurant/Cafe  Other  22686   134     218   3157
## 252                Retail Oponto   6134 23133   33586   6746
## 138 Hotel/Restaurant/Cafe  Other   3087  8080    8282    661
## 263 Hotel/Restaurant/Cafe Oponto  23257  1372    1677    982
## 183 Hotel/Restaurant/Cafe  Other    694  8533   10518    443
## 157                Retail  Other   3830  5291   14855    317
## 295 Hotel/Restaurant/Cafe Lisbon  21273  2013    6550    909
## 3                  Retail  Other   6353  8808    7684   2405
## 44                 Retail  Other    630 11095   23998    787
## 2                  Retail  Other   7057  9810    9568   1762
## 409                Retail  Other   8257  3880    6407   1646
## 4   Hotel/Restaurant/Cafe  Other  13265  1196    4221   6404
## 146                Retail  Other  22039  8384   34792     42
## 139 Hotel/Restaurant/Cafe  Other  13537  4257    5034    155
## 188 Hotel/Restaurant/Cafe  Other   2438  8002    9819   6269
## 132 Hotel/Restaurant/Cafe  Other   2101   589     314    346
## 299                Retail Lisbon   6758  4560    9965    934
## 166                Retail  Other  15615 12653   19858   4425
## 217                Retail Oponto   2532 16599   36486    179
## 191 Hotel/Restaurant/Cafe  Other  16936  6250    1981   7332
## 200 Hotel/Restaurant/Cafe Oponto   9670  2280    2112    520
## 6                  Retail  Other   9413  8259    5126    666
## 42  Hotel/Restaurant/Cafe  Other  19176  3065    5956   2033
## 394 Hotel/Restaurant/Cafe  Other  23632  6730    3842   8620
## 291 Hotel/Restaurant/Cafe  Other   2708  2160    2642    502
## 380                Retail  Other   4048  5164   10391    130
## 329 Hotel/Restaurant/Cafe Lisbon  16933  2209    3389   7849
## 436 Hotel/Restaurant/Cafe  Other  29703 12051   16027  13135
## 367 Hotel/Restaurant/Cafe  Other   9561  2217    1664   1173
## 201                Retail Oponto   3067 13240   23127   3941
## 421 Hotel/Restaurant/Cafe  Other   4456  5266   13227     25
## 431 Hotel/Restaurant/Cafe  Other   3097  4230   16483    575
## 9   Hotel/Restaurant/Cafe  Other   5963  3648    6192    425
## 348                Retail  Other  27380  7184   12311   2809
## 80  Hotel/Restaurant/Cafe  Other   1640  3259    3655    868
## 47                 Retail  Other   3103 14069   21955   1668
## 312 Hotel/Restaurant/Cafe Lisbon  29635  2335    8280   3046
## 401 Hotel/Restaurant/Cafe  Other   4446   906    1238   3576
## 387 Hotel/Restaurant/Cafe  Other   1206  3620    2857   1945
## 244 Hotel/Restaurant/Cafe Oponto  11210  3576    5119    561
## 391 Hotel/Restaurant/Cafe  Other   3352  1181    1328   5502
## 11                 Retail  Other   3366  5403   12974   4400
## 297 Hotel/Restaurant/Cafe Lisbon  19087  1304    3643   3045
## 289 Hotel/Restaurant/Cafe  Other  16260   594    1296    848
## 218 Hotel/Restaurant/Cafe Oponto  18044  1475    2046   2532
## 66                 Retail  Other     85 20959   45828     36
## 173 Hotel/Restaurant/Cafe  Other    955  5479    6536    333
## 354                Retail  Other    117  6264   21203    228
## 111 Hotel/Restaurant/Cafe  Other  11818  1648    1694   2276
## 53                 Retail  Other  40721  3916    5876    532
## 370 Hotel/Restaurant/Cafe  Other   6211   337     683   1089
## 358                Retail  Other     37  1275   22272    137
## 206                Retail Oponto   1107 11711   23596    955
## 393 Hotel/Restaurant/Cafe  Other    518  4180    3600    659
## 198                Retail Oponto   2427  7097   10391   1127
## 331 Hotel/Restaurant/Cafe Lisbon   9790  1786    5109   3570
## 439 Hotel/Restaurant/Cafe  Other  10290  1981    2232   1038
## 285 Hotel/Restaurant/Cafe  Other  68951  4411   12609   8692
## 392 Hotel/Restaurant/Cafe  Other   2647  2761    2313    907
## 147 Hotel/Restaurant/Cafe  Other   7769  1936    2177    926
## 100 Hotel/Restaurant/Cafe  Other   9658  2182    1909   5639
## 190                Retail  Other    834 11577   11522    275
## 352                Retail  Other   1210 10044   22294   1741
## 121 Hotel/Restaurant/Cafe  Other  17160  1200    3412   2417
## 270 Hotel/Restaurant/Cafe Oponto  15218   258    1138   2516
## 267                Retail Oponto    572  9763   22182   2221
## 237 Hotel/Restaurant/Cafe Oponto   8635   820    3047   2312
## 58                 Retail  Other   5417  9933   10487     38
## 403 Hotel/Restaurant/Cafe  Other  26539  4753    5091    220
## 171                Retail  Other    260  8675   13430   1116
## 296                Retail Lisbon   7588  1897    5234    417
## 214 Hotel/Restaurant/Cafe Oponto   3317  6602    6861   1329
## 407 Hotel/Restaurant/Cafe  Other  25066  5010    5026   9806
## 272 Hotel/Restaurant/Cafe Oponto   2083  5007    1563   1120
## 176                Retail  Other   2343  7845   11874     52
## 377                Retail  Other   3136  8630   13586   5641
## 36                 Retail  Other    688  5491   11091    833
## 50                 Retail  Other   4967 21412   28921   1798
## 204 Hotel/Restaurant/Cafe Oponto    583   685    2216    469
## 360 Hotel/Restaurant/Cafe  Other    796  5878    2109    340
## 310                Retail Lisbon    918 20655   13567   1465
## 247 Hotel/Restaurant/Cafe Oponto   8885  2428    1777   1777
## 418 Hotel/Restaurant/Cafe  Other   5065  5499   11055    364
## 404 Hotel/Restaurant/Cafe  Other  25606 11006    4604    127
## 411 Hotel/Restaurant/Cafe  Other   6633  2096    4563   1389
## 74                 Retail  Other  19899  5332    8713   8132
## 432 Hotel/Restaurant/Cafe  Other   8533  5506    5160  13486
## 284 Hotel/Restaurant/Cafe  Other  25767  3613    2013  10303
## 250 Hotel/Restaurant/Cafe Oponto   8040  3795    2070   6340
## 231                Retail Oponto  11072  5989    5615   8321
## 120 Hotel/Restaurant/Cafe  Other   8258  2344    2147   3896
## 274 Hotel/Restaurant/Cafe  Other  36817  3045    1493   4802
## 227                Retail Oponto  20782  5921    9212   1759
## 169 Hotel/Restaurant/Cafe  Other   5809   735     803   1393
## 40  Hotel/Restaurant/Cafe  Other  56159   555     902  10002
## 234 Hotel/Restaurant/Cafe Oponto    964  4984    3316    937
## 412 Hotel/Restaurant/Cafe  Other   2126  3289    3281   1535
## 195 Hotel/Restaurant/Cafe  Other   7107  1012    2974    806
## 26                 Retail  Other  16165  4230    7595    201
## 369 Hotel/Restaurant/Cafe  Other  22335  1196    2406   2046
## 290 Hotel/Restaurant/Cafe  Other  42786   286     471   1388
## 277 Hotel/Restaurant/Cafe  Other  27901  3749    6964   4479
## 196 Hotel/Restaurant/Cafe  Other  17023  5139    5230   7888
## 29                 Retail  Other   4113 20484   25957   1158
## 320                Retail Lisbon   9759 25071   17645   1128
## 197 Hotel/Restaurant/Cafe Oponto  30624  7209    4897  18711
## 365 Hotel/Restaurant/Cafe  Other   2615   873    1524   1103
## 16  Hotel/Restaurant/Cafe  Other  10253  1114    3821    397
## 187 Hotel/Restaurant/Cafe  Other   3009   521     854   3470
## 261 Hotel/Restaurant/Cafe Oponto   9193  4885    2157    327
## 60  Hotel/Restaurant/Cafe  Other   6137  5360    8040    129
## 154 Hotel/Restaurant/Cafe  Other   3463  9250    2368    779
## 220 Hotel/Restaurant/Cafe Oponto   4155   367    1390   2306
## 5                  Retail  Other  22615  5410    7198   3915
## 322 Hotel/Restaurant/Cafe Lisbon   9155  1897    5167   2714
## 61                 Retail  Other   8590  3045    7854     96
## 415 Hotel/Restaurant/Cafe  Other   5969  1990    3417   5679
## 140 Hotel/Restaurant/Cafe  Other   5387  4979    3343    825
## 373 Hotel/Restaurant/Cafe  Other   3884  3801    1641    876
## 332                Retail Lisbon  11223 14881   26839   1234
## 194                Retail  Other    180  3485   20292    959
## 72  Hotel/Restaurant/Cafe  Other  18291  1266   21042   5373
## 90  Hotel/Restaurant/Cafe  Other  24904  3836    5330   3443
## 86                 Retail  Other  16117 46197   92780   1026
## 92  Hotel/Restaurant/Cafe  Other  12754  2762    2530   8693
## 422                Retail  Other  17063  4847    9053   1031
## 137 Hotel/Restaurant/Cafe  Other   4625  8579    7030   4575
## 116 Hotel/Restaurant/Cafe  Other  11134   793    2988   2715
## 311 Hotel/Restaurant/Cafe Lisbon   7034  1492    2405  12569
## 135 Hotel/Restaurant/Cafe  Other   7388  1882    2174    720
## 28  Hotel/Restaurant/Cafe  Other  14276   803    3045    485
## 122 Hotel/Restaurant/Cafe  Other   4020  3234    1498   2395
## 283 Hotel/Restaurant/Cafe  Other  49063  3965    4252   5970
## 330 Hotel/Restaurant/Cafe Lisbon   5113  1486    4583   5127
## 349 Hotel/Restaurant/Cafe  Other   3428  2380    2028   1341
## 396 Hotel/Restaurant/Cafe  Other   9602  1316    1263   2921
## 14                 Retail  Other  21217  6208   14982   3095
## 81  Hotel/Restaurant/Cafe  Other   7005   829    3009    430
## 339 Hotel/Restaurant/Cafe Lisbon      3   333    7021  15601
## 434 Hotel/Restaurant/Cafe  Other   1982  3218    1493   1541
## 216 Hotel/Restaurant/Cafe Oponto   2806 10765   15538   1374
## 425                Retail  Other  16980  2884   12232    874
## 438                Retail  Other  14531 15488   30243    437
## 124                Retail  Other  11170 10769    8814   2194
## 356 Hotel/Restaurant/Cafe  Other    190   727    2012    245
## 117 Hotel/Restaurant/Cafe  Other  11173  2521    3355   1517
## 390 Hotel/Restaurant/Cafe  Other   9385  1530    1422   3019
## 305                Retail Lisbon    161  7460   24773    617
## 113 Hotel/Restaurant/Cafe  Other  19046  2770    2469   8853
## 293 Hotel/Restaurant/Cafe  Other   2838  3086    4329   3838
## 333 Hotel/Restaurant/Cafe Lisbon  22321  3216    1447   2208
## 341                Retail  Other    381  4025    9670    388
## 185 Hotel/Restaurant/Cafe  Other    327   918    4710     74
## 131 Hotel/Restaurant/Cafe  Other   7149  2428     699   6316
## 249 Hotel/Restaurant/Cafe Oponto  15671  5279    2406    559
## 413 Hotel/Restaurant/Cafe  Other     97  3605   12400     98
## 371                Retail  Other  39679  3944    4955   1364
## 366                Retail  Other   4692  6128    8025   1619
## 344                Retail  Other   1689  6964   26316   1456
## 245 Hotel/Restaurant/Cafe Oponto   6202  7775   10817   1183
## 149 Hotel/Restaurant/Cafe  Other   5924   584     542   4052
## 302                Retail Lisbon   5283 13316   20399   1809
## 199 Hotel/Restaurant/Cafe Oponto  11686  2154    6824   3527
## 142 Hotel/Restaurant/Cafe  Other  30379 13252    5189    321
## 389 Hotel/Restaurant/Cafe  Other   9785   848    1172   1677
## 210                Retail Oponto   5550 12729   16767    864
## 156                Retail  Other   1989 10690   19460    233
## 240 Hotel/Restaurant/Cafe Oponto  47493  2567    3779   5243
## 308 Hotel/Restaurant/Cafe Lisbon  17327  2374    2842   1149
## 39                 Retail  Other   4591 15729   16709     33
## 192 Hotel/Restaurant/Cafe  Other  13624   295    1381    890
## 123 Hotel/Restaurant/Cafe  Other  12212   201     245   1991
## 158 Hotel/Restaurant/Cafe  Other  17773  1366    2474   3378
## 355 Hotel/Restaurant/Cafe  Other  14039  7393    2548   6386
##     Detergents_Paper Delicassen
## 383             1711       2893
## 361              468        503
## 258             3593        987
## 7               3140        545
## 64              7677       1295
## 73              1321        181
## 268              737       3628
## 399               74        247
## 186               58        247
## 275              759       1153
## 98                54         63
## 338              442        868
## 262               49        287
## 222             4167        239
## 347             6600       1115
## 101             8035       3029
## 110              836          3
## 24              4337      16523
## 62             26701       2017
## 350            12218        445
## 30              1107        823
## 269             6374        698
## 69               788       3095
## 427             5079       1894
## 255             1547       3265
## 78             12034       1009
## 168             1680        693
## 51               609       2162
## 184              239      47943
## 153              352        184
## 165             3674        238
## 75              1901       1780
## 408             7883        553
## 266              830       3636
## 112             6457       1519
## 378               96       1242
## 424             1803        668
## 95              5038        244
## 233              284        834
## 384              397        361
## 1               2674       1338
## 386              192       1068
## 298             3712        531
## 179              120        395
## 265             5980       1265
## 71               116       1365
## 114              585       1561
## 119              411        933
## 133              955        328
## 193              187        409
## 108             8969       1438
## 353               90        195
## 94                71       2698
## 419             6740        776
## 225               70        659
## 105             1491        548
## 93             18906       5130
## 83              3537       2342
## 315              857       1233
## 55               204       1333
## 324             1679        573
## 107             6830       1831
## 23              2381       4334
## 89               165         46
## 91                69        360
## 395              149        452
## 59               227        436
## 35               483        395
## 213              240       1775
## 328               88        522
## 19              2767       3181
## 406              593        378
## 307             7558       1543
## 317               83       1059
## 388              231        961
## 334            38102       1215
## 85              3837        120
## 316             3891       3508
## 321              275        834
## 426              108       1886
## 351              173        995
## 37               862       4626
## 104             1480       2498
## 209             3381        806
## 382              246        532
## 236             1216        295
## 385              282       5120
## 414              912       2435
## 243              586        578
## 25              4482       5778
## 115              118       1266
## 164            13726        446
## 152              255       1774
## 20              2518        501
## 8               3321       2566
## 368              252        342
## 155                7          8
## 65              1247       1145
## 294             5952        741
## 49              5121       1476
## 242              412       1047
## 127              349        483
## 223              256        375
## 38              6506        714
## 257              392        373
## 253              205       1693
## 372              716        790
## 32               820        985
## 279              274       1409
## 18               370       4478
## 264             2894        411
## 342             5162       2158
## 435             2371        838
## 430               84       2501
## 118              319       1160
## 254              363       1391
## 103             4573       1386
## 212            19410       2870
## 286              436         18
## 13              3881       2931
## 126              778        918
## 17              4508       1080
## 288              386       1027
## 15              5058       2168
## 381              600        270
## 97              3874        217
## 22               375        569
## 180              273       2165
## 33               918        405
## 375              311        686
## 238               28       1215
## 207              288        285
## 67              3468         27
## 300              290        259
## 99                56        132
## 52              1538        301
## 189             6839        404
## 346             3843        303
## 88              1579      14351
## 43              6899         46
## 21              2259       2124
## 63              4074        964
## 203              284       6854
## 130              410       1819
## 79               301        167
## 143               20          3
## 170               69        750
## 106              139       1378
## 364             1335        314
## 45              4618         65
## 224              788       1360
## 228              263        689
## 429              850        317
## 325              140       1092
## 175              153       1442
## 423              948       1218
## 280             3620       1721
## 182             4948       8550
## 319              706         51
## 301             2662       2005
## 145              516        201
## 271              197         56
## 400              469        375
## 326             1272       5609
## 281              167       1104
## 345              217        379
## 337              146        778
## 159             4004       1682
## 273               93       1040
## 437               93       2346
## 77               529        894
## 336             4111       2139
## 87             20070        903
## 376              476         70
## 323             1470        229
## 208             5316        120
## 313            17120        142
## 314              183        297
## 318              821       1637
## 340              573       1942
## 420             1580       1521
## 292              212        686
## 410             2123       5137
## 402               92       1902
## 416             3540       1874
## 379               68       1114
## 221               56        749
## 134              256        396
## 177             1532        230
## 241              343       2564
## 428              439       1163
## 174             9836        716
## 327              387        834
## 282             2328       2079
## 161             4424       2157
## 167             4973       3637
## 163              232        610
## 109             2505       1236
## 151              170       1067
## 433             1328        395
## 304            10069         59
## 306             3909        211
## 31              2134       2963
## 287             1226        128
## 363              179        712
## 136              199        326
## 82              7818        156
## 335              332       3486
## 246             8933       2784
## 181             1382       2794
## 219             4797       6372
## 144              399        318
## 48             24171       6465
## 125              500       1621
## 359              536       4100
## 374             1916       3113
## 239               72        216
## 57             17740       1340
## 230              694        980
## 129             1062          3
## 226              761        786
## 46              7353       4985
## 141              960       2616
## 128             2386       2749
## 56              2024       1130
## 54              5611        224
## 276               96        379
## 34               361       1083
## 68              5141        834
## 229             4762        203
## 96               223        709
## 417             6728        993
## 10              7425       2098
## 343             4595       1328
## 76                 3        975
## 260              967        818
## 27               242        833
## 205                5       1328
## 202            14235       1681
## 251              234        710
## 398               64        743
## 303             6236        555
## 84               550        772
## 278              621        139
## 12               549        497
## 309              257        656
## 41              1145       5864
## 160             8077        303
## 362              159        405
## 178               20       2631
## 256              111        615
## 70               656        144
## 397             3378       2213
## 102             6766       1838
## 148             1082        526
## 211              244       2100
## 215             5957        791
## 232             1566        490
## 235              325       2563
## 405              914        715
## 248               44        659
## 162                3       2233
## 150              113       1440
## 172             8773       6250
## 259              730       3321
## 440              477         52
## 357                9        548
## 252            18594       5121
## 138              721         36
## 263              429        655
## 183             6907        156
## 157             6694       3182
## 295              811       1854
## 3               3516       7844
## 44              9529         72
## 2               3293       1776
## 409             2730        344
## 4                507       1788
## 146            12591       4430
## 139              249       3271
## 188             3459          3
## 132               70        310
## 299             4538       1037
## 166             7108       2379
## 217            13308        674
## 191              118         64
## 200              402        347
## 6               1795       1451
## 42              2575       2802
## 394              385        819
## 291              965       1522
## 380              813        179
## 329              210       1534
## 436              182       2204
## 367              222        447
## 201             9959        731
## 421             6818       1393
## 431              241       2080
## 9               1716        750
## 348             4621       1022
## 80              1202       1653
## 47              6792       1452
## 312              371        117
## 401              153       1014
## 387              353        967
## 244             1682       2398
## 391              311       1000
## 11              5977       1744
## 297              710        898
## 289              445        258
## 218              130       1158
## 66             24231       1423
## 173             2840        707
## 354             8682       1111
## 111              169       1647
## 53              2587       1278
## 370               41        296
## 358             6747        110
## 206             9265        710
## 393              122        654
## 198             4314       1468
## 331              182       1043
## 439              168       2125
## 285              751       2406
## 392               95       1827
## 147               73        520
## 100              215        323
## 190             4027       1856
## 352            12638       3137
## 121              174       1136
## 270              333        204
## 267             4882       2563
## 237              415        225
## 58              7572       1282
## 403               10        340
## 171             7015        323
## 296             2208        254
## 214             3961       1215
## 407             1092        960
## 272              147       1550
## 176             4196       1697
## 377             4666       1426
## 36              4239        436
## 50             13583       1163
## 204              954         18
## 360              232        776
## 310             6846        806
## 247              430        610
## 418             3485       1063
## 404              632        288
## 411             1860       1892
## 74               764        648
## 432             1377       1498
## 284              314       1384
## 250              918        291
## 231              955       2137
## 120              266        635
## 274              210       1824
## 227             2568       1553
## 169               79        429
## 40               212       2916
## 234              409          7
## 412              235       4365
## 195              355       1142
## 26              4003         57
## 369              101        558
## 290               32         22
## 277              603       2503
## 196              330       1755
## 29              8604       5206
## 320            12408       1625
## 197              763       2876
## 365              514        468
## 16               964        412
## 187              949        727
## 261              780        548
## 60              3084       1603
## 154              302       1627
## 220               86        130
## 5               1777       5185
## 322              228       1113
## 61              4095        225
## 415             1135        290
## 140              637        929
## 373              397       4829
## 332             9606       1102
## 194             5618        666
## 72              4173      14472
## 90               454       3178
## 86             40827       2944
## 92               627       1117
## 422             3415       1784
## 137             2447       1542
## 116              276        610
## 311              299       1117
## 135               47        537
## 28               100        518
## 122              264        255
## 283             1041       1404
## 330              492        739
## 349             1184        665
## 396              841        290
## 14              6707        602
## 81               610        529
## 339               15        550
## 434              356       1449
## 216             5828       2388
## 425             3213        249
## 438            14841       1867
## 124             1976        143
## 356              184        127
## 117              310        222
## 390              227        684
## 305            11783       2410
## 113              483       2708
## 293              825       1060
## 333              178       2602
## 341             7271       1371
## 185              334         11
## 131              395        911
## 249              562        572
## 413             2970         62
## 371              523       2235
## 366             4515       3105
## 344            15469         37
## 245             3143       1970
## 149              283        434
## 302             8752        172
## 199              592        697
## 142               51       1450
## 389              200        406
## 210            12420        797
## 156            11577       2153
## 240              828       2253
## 308              351        925
## 39              6956        433
## 192               43         84
## 123               25        860
## 158              811        418
## 355             1333       2341
#Utilizing Channel as our target feature, and all other variables as our target predictors.  Create a training data set and begin to build my algorithm. 

M2 <- C5.0(wholesaleF[1:100,-1], wholesaleF[1:100, 1])
summary(M2)
## 
## Call:
## C5.0.default(x = wholesaleF[1:100, -1], y = wholesaleF[1:100, 1])
## 
## 
## C5.0 [Release 2.07 GPL Edition]      Wed Jun 10 15:53:03 2015
## -------------------------------
## 
## Class specified by attribute `outcome'
## 
## Read 100 cases (8 attributes) from undefined.data
## 
## Decision tree:
## 
## Detergents_Paper <= 1711: Hotel/Restaurant/Cafe (61/1)
## Detergents_Paper > 1711:
## :...Milk <= 2495: Hotel/Restaurant/Cafe (3)
##     Milk > 2495:
##     :...Region in {Lisbon,Other}: Retail (32/1)
##         Region = Oponto:
##         :...Milk <= 7603: Hotel/Restaurant/Cafe (2)
##             Milk > 7603: Retail (2)
## 
## 
## Evaluation on training data (100 cases):
## 
##      Decision Tree   
##    ----------------  
##    Size      Errors  
## 
##       5    2( 2.0%)   <<
## 
## 
##     (a)   (b)    <-classified as
##    ----  ----
##      65     1    (a): class Hotel/Restaurant/Cafe
##       1    33    (b): class Retail
## 
## 
##  Attribute usage:
## 
##  100.00% Detergents_Paper
##   39.00% Milk
##   36.00% Region
## 
## 
## Time: 0.0 secs
#Model M2 only yields 4 total errors. 
#Now let test our remaining data set. 
P2 <-predict(M2, wholesaleF[101:440,])
P2
##   [1] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
##   [4] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
##   [7] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
##  [10] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Retail               
##  [13] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
##  [16] Hotel/Restaurant/Cafe Retail                Retail               
##  [19] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
##  [22] Retail                Hotel/Restaurant/Cafe Retail               
##  [25] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
##  [28] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
##  [31] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
##  [34] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
##  [37] Retail                Retail                Hotel/Restaurant/Cafe
##  [40] Retail                Retail                Retail               
##  [43] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
##  [46] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
##  [49] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
##  [52] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
##  [55] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Retail               
##  [58] Retail                Hotel/Restaurant/Cafe Retail               
##  [61] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
##  [64] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
##  [67] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
##  [70] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Retail               
##  [73] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
##  [76] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
##  [79] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
##  [82] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
##  [85] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
##  [88] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
##  [91] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
##  [94] Retail                Retail                Retail               
##  [97] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
## [100] Hotel/Restaurant/Cafe Retail                Retail               
## [103] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [106] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
## [109] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [112] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
## [115] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
## [118] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [121] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
## [124] Retail                Retail                Retail               
## [127] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Retail               
## [130] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Retail               
## [133] Retail                Retail                Hotel/Restaurant/Cafe
## [136] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [139] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [142] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [145] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [148] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [151] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Retail               
## [154] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [157] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [160] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [163] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
## [166] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Retail               
## [169] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Retail               
## [172] Retail                Hotel/Restaurant/Cafe Retail               
## [175] Retail                Retail                Retail               
## [178] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
## [181] Retail                Hotel/Restaurant/Cafe Retail               
## [184] Retail                Retail                Hotel/Restaurant/Cafe
## [187] Hotel/Restaurant/Cafe Retail                Retail               
## [190] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [193] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [196] Retail                Retail                Hotel/Restaurant/Cafe
## [199] Retail                Retail                Hotel/Restaurant/Cafe
## [202] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [205] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [208] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [211] Hotel/Restaurant/Cafe Retail                Retail               
## [214] Retail                Hotel/Restaurant/Cafe Retail               
## [217] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Retail               
## [220] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [223] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [226] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Retail               
## [229] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [232] Retail                Hotel/Restaurant/Cafe Retail               
## [235] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
## [238] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [241] Retail                Retail                Retail               
## [244] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [247] Retail                Hotel/Restaurant/Cafe Retail               
## [250] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [253] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [256] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [259] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [262] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [265] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [268] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Retail               
## [271] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [274] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [277] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [280] Retail                Hotel/Restaurant/Cafe Retail               
## [283] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [286] Retail                Retail                Hotel/Restaurant/Cafe
## [289] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
## [292] Retail                Retail                Hotel/Restaurant/Cafe
## [295] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [298] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [301] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Retail               
## [304] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [307] Retail                Retail                Retail               
## [310] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [313] Hotel/Restaurant/Cafe Retail                Hotel/Restaurant/Cafe
## [316] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Retail               
## [319] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [322] Retail                Hotel/Restaurant/Cafe Retail               
## [325] Retail                Retail                Hotel/Restaurant/Cafe
## [328] Retail                Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [331] Hotel/Restaurant/Cafe Retail                Retail               
## [334] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Retail               
## [337] Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe Hotel/Restaurant/Cafe
## [340] Hotel/Restaurant/Cafe
## Levels: Hotel/Restaurant/Cafe Retail
table(wholesaleF[101:440,1], predicted=P2)
##                        predicted
##                         Hotel/Restaurant/Cafe Retail
##   Hotel/Restaurant/Cafe                   213     19
##   Retail                                   15     93

Compare tree models

table(wholesaled[101:440,1], predicted=P1)
##                        predicted
##                           0   1
##   Hotel/Restaurant/Cafe  22 228
##   Retail                 84   6
table(wholesaleF[101:440,1], predicted=P2)
##                        predicted
##                         Hotel/Restaurant/Cafe Retail
##   Hotel/Restaurant/Cafe                   213     19
##   Retail                                   15     93

After evaluation of each of the tree model algorithms rpart vs. C5.0 we see that model P2 produces the least amount of errors for a total amount of 34 errors. Evaluation of each of the several models LDA produces the least amount of errors and is the most robust model at 89% accuracy.