This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(rattle)
## Loading required package: tibble
## Loading required package: bitops
## Rattle: A free graphical interface for data science with R.
## Version 5.5.1 Copyright (c) 2006-2021 Togaware Pty Ltd.
## Type 'rattle()' to shake, rattle, and roll your data.
library(RColorBrewer)
credit <- read.csv("~/Downloads/credit.csv", stringsAsFactors=TRUE)
View(credit)
set.seed(12345)
credit_rand <-credit[order(runif(1000)), ]
runif(1000)
## [1] 0.0777567036 0.8437136484 0.0068136845 0.3511842042 0.6860610321
## [6] 0.2540864940 0.1741293166 0.7071131645 0.9995669075 0.9496759747
## [11] 0.4352806835 0.8916067847 0.5872418997 0.3438367692 0.8095422778
## [16] 0.5416912837 0.0158186657 0.7376737485 0.4075890041 0.7575714595
## [21] 0.0228316295 0.1547229099 0.1084561225 0.2806243401 0.8013083299
## [26] 0.8523376379 0.4814579317 0.7703864295 0.6567622824 0.5173526625
## [31] 0.7785943775 0.6926085495 0.8070568061 0.2142587404 0.1048154260
## [36] 0.2186046925 0.4373079913 0.0437870950 0.3042146589 0.7267219294
## [41] 0.6602043419 0.2354373285 0.7137101276 0.8436817555 0.7661008295
## [46] 0.7935107991 0.3390335382 0.3142745141 0.5165973087 0.5048659837
## [51] 0.5887349686 0.9722319373 0.7841860852 0.6407156852 0.3360152766
## [56] 0.0886050970 0.3566103817 0.5048438089 0.0386124158 0.4579752202
## [61] 0.4271879985 0.9793282044 0.7981051120 0.3720586351 0.2785345241
## [66] 0.0561862723 0.3598228290 0.6475324086 0.9827478663 0.9795333201
## [71] 0.7406695855 0.0314395325 0.3773986904 0.4294274861 0.8820798704
## [76] 0.6579108767 0.7101417843 0.4416559828 0.4785656102 0.0680428902
## [81] 0.9833091802 0.7640029874 0.4255533803 0.1820202691 0.5393347333
## [86] 0.1139705596 0.9719577306 0.0880683684 0.9475400327 0.0123275036
## [91] 0.9818284549 0.8346416645 0.2443945890 0.5760519905 0.0110921310
## [96] 0.6378872006 0.0489012559 0.3953613597 0.7154947596 0.0005157613
## [101] 0.3187408934 0.8059563036 0.4867536933 0.4312844181 0.6470495826
## [106] 0.7340863363 0.8765104278 0.7769336631 0.9190410159 0.3154266642
## [111] 0.9829337932 0.5795484053 0.1384168146 0.0694019734 0.8880138926
## [116] 0.8193018446 0.7508684923 0.0973195622 0.2338038718 0.4765379161
## [121] 0.5449228641 0.1779741647 0.5259980250 0.6450509054 0.2641421508
## [126] 0.4074000223 0.6980692339 0.1938885071 0.2110034036 0.8810128772
## [131] 0.2477386207 0.7363855059 0.4851776310 0.2903681598 0.3869511473
## [136] 0.3712436198 0.1524393873 0.4892353129 0.9189973811 0.8316703266
## [141] 0.7986166533 0.0791017532 0.3707391704 0.5249428253 0.7036067015
## [146] 0.4917231726 0.1136673295 0.2520255612 0.7352492979 0.4880532084
## [151] 0.7177480794 0.5373601401 0.8918123213 0.5994046289 0.6827988101
## [156] 0.4450904198 0.0609138389 0.5443498802 0.5221175055 0.4484722465
## [161] 0.7517674197 0.9936176911 0.0884756697 0.0619401587 0.5968114452
## [166] 0.1775272016 0.3792890508 0.2709059671 0.7677217436 0.8677942061
## [171] 0.5797999771 0.9794304082 0.0575748300 0.2677852714 0.5093897504
## [176] 0.4335404916 0.7886197066 0.0957744191 0.0052998273 0.8662888575
## [181] 0.2991278083 0.7891022933 0.0946152499 0.9906538252 0.7883940383
## [186] 0.8430416877 0.7621082976 0.3318448993 0.8489439958 0.6929465232
## [191] 0.9536970104 0.8593127392 0.4104800038 0.8870295139 0.4215502921
## [196] 0.7885297544 0.8516884169 0.1954303612 0.3293396446 0.2508964648
## [201] 0.0508539947 0.8032334009 0.5837758495 0.5854832230 0.3210259757
## [206] 0.9584395026 0.2538711648 0.2215727409 0.4471150385 0.7374086354
## [211] 0.0931337508 0.2709370609 0.5305660244 0.6118952190 0.3501220858
## [216] 0.9667522209 0.8282586737 0.6966053150 0.5086508940 0.1633692919
## [221] 0.3233706176 0.1536298189 0.5905119644 0.7114739148 0.0812958886
## [226] 0.5980426143 0.8223334197 0.2504766711 0.5263970867 0.0504449278
## [231] 0.7889810870 0.6894923782 0.4758686426 0.8384034017 0.5355896275
## [236] 0.5947897960 0.6559045569 0.2414543480 0.1871196402 0.3861902640
## [241] 0.9263548679 0.0548229557 0.5814133412 0.7018023168 0.4776231155
## [246] 0.8126417527 0.2611319877 0.0719611384 0.7635538341 0.8663788619
## [251] 0.4742859367 0.9755663653 0.5526777462 0.4731400141 0.5138465350
## [256] 0.3044357693 0.6108950628 0.2314155486 0.8210249711 0.8632446849
## [261] 0.1485382647 0.5509163870 0.4154206566 0.5723100612 0.9622937285
## [266] 0.6171846224 0.9279841650 0.1431856079 0.3577233632 0.2927738633
## [271] 0.2698851374 0.7667622501 0.6900199116 0.4541873268 0.5970189935
## [276] 0.6375497121 0.4491121508 0.7001244305 0.1055695352 0.3203951260
## [281] 0.9489074103 0.7309176833 0.8353279254 0.1991672162 0.8608348782
## [286] 0.5071824987 0.3596526959 0.9593778017 0.1549290936 0.0307096986
## [291] 0.9091471350 0.7385891106 0.4381890337 0.1890506682 0.8229350788
## [296] 0.6620346240 0.8130644781 0.3285284250 0.5576907480 0.1927869774
## [301] 0.2064940296 0.3326827041 0.1080764281 0.4055493334 0.9897542780
## [306] 0.5250190527 0.5202273978 0.2411924344 0.6144114409 0.1442913327
## [311] 0.0350480059 0.8083797011 0.1260739930 0.8106233103 0.8998808300
## [316] 0.4536956826 0.0869988448 0.7149512444 0.9702831036 0.9546365219
## [321] 0.0855619262 0.5799163692 0.7067587615 0.0885722821 0.1078524368
## [326] 0.1089445429 0.9697500223 0.5738067687 0.0741152398 0.1460326868
## [331] 0.4390542789 0.5012178998 0.1721537141 0.3866833837 0.6226336218
## [336] 0.1614258026 0.6082359944 0.8136703714 0.3762129229 0.4816998374
## [341] 0.3503530079 0.4983976563 0.0765113463 0.9748104147 0.8323310192
## [346] 0.9408279755 0.7303201829 0.0294377604 0.3562299383 0.1905312119
## [351] 0.0353776552 0.8913339803 0.9123610412 0.6843555856 0.6720858573
## [356] 0.2430700560 0.5654472420 0.9440552588 0.5119576079 0.8801631518
## [361] 0.2494844771 0.9614770701 0.8720321110 0.2164454951 0.9849712609
## [366] 0.8110020303 0.1380726886 0.7073657222 0.1350730604 0.8939344361
## [371] 0.9036504987 0.8876989218 0.0027319901 0.8323496236 0.6335654750
## [376] 0.8775700259 0.4115538206 0.6465182982 0.4212207103 0.4385075776
## [381] 0.9487973230 0.0606403218 0.0307681947 0.6070591439 0.4012593189
## [386] 0.3311363435 0.0852249968 0.3139067194 0.9266465220 0.4466821318
## [391] 0.0162620342 0.1724349132 0.2818815561 0.7532050123 0.5934580355
## [396] 0.3198176965 0.8643026883 0.1689800976 0.7126975916 0.0175051326
## [401] 0.9893782043 0.7701033992 0.9783547290 0.8540933765 0.4769226916
## [406] 0.8226374025 0.6707891799 0.8511373366 0.0962308650 0.3453158364
## [411] 0.4859519827 0.5414021171 0.8223230357 0.9805192025 0.3591138937
## [416] 0.4737425947 0.6798118292 0.4504585292 0.4202566852 0.4650207167
## [421] 0.4978667302 0.1975288719 0.2970156558 0.0542281296 0.3031314788
## [426] 0.1381969717 0.4661661133 0.0721095554 0.6685574572 0.3303719272
## [431] 0.8408492259 0.7934054516 0.1223763609 0.1877616218 0.9536082337
## [436] 0.2250510089 0.8882208145 0.9482737223 0.4890548643 0.8844608653
## [441] 0.3853170366 0.0445676188 0.8346308430 0.7240984244 0.4052788019
## [446] 0.9364653660 0.1836034353 0.2952076690 0.2639632733 0.8850478269
## [451] 0.0519774705 0.9773229507 0.0157975492 0.7515435049 0.9826836833
## [456] 0.7594938267 0.6060661038 0.8108430125 0.3017157679 0.1584865986
## [461] 0.4937231196 0.9622761128 0.4398880976 0.8265698885 0.5351535990
## [466] 0.4743092493 0.7819814268 0.5947666871 0.6505182923 0.8276161600
## [471] 0.6360624337 0.8740559290 0.0287446966 0.7297454963 0.4770007983
## [476] 0.6557591627 0.3187114764 0.4157041425 0.7371981661 0.3013113760
## [481] 0.1683405314 0.2275979982 0.2104604514 0.2749277635 0.3099659900
## [486] 0.4370625254 0.3377992054 0.8844660476 0.2562388845 0.6788090842
## [491] 0.9185654067 0.9530549832 0.9990116030 0.5258525084 0.9713375776
## [496] 0.0583157204 0.3463037431 0.4774280726 0.2787018081 0.3305488063
## [501] 0.6778752119 0.8512316681 0.5387199295 0.2284057762 0.7504877932
## [506] 0.4430092890 0.2269977615 0.4867921183 0.8474487253 0.9913031289
## [511] 0.2430280214 0.9904011474 0.1007772188 0.2590785371 0.4631806915
## [516] 0.3717048247 0.9676600124 0.2092092596 0.1762814855 0.4729586702
## [521] 0.1513172702 0.5096273369 0.0934986048 0.6245909156 0.4664464421
## [526] 0.7417968519 0.7805056896 0.1095504211 0.4364612624 0.3658015456
## [531] 0.8060158005 0.5122637672 0.8338199144 0.0767527779 0.7304349756
## [536] 0.1521932939 0.9937361125 0.2961431956 0.8760090137 0.5430484337
## [541] 0.9695948055 0.9644850143 0.4061121722 0.4805803744 0.3253537535
## [546] 0.0589104916 0.2367637162 0.2514303587 0.6875558863 0.4781660144
## [551] 0.7979163071 0.0104476984 0.8227418752 0.9821375927 0.8271992265
## [556] 0.6460105369 0.2877143263 0.2516318541 0.7541789182 0.4226943476
## [561] 0.5869964403 0.4357300075 0.1573912781 0.6995304092 0.6454634287
## [566] 0.2299823829 0.6806051095 0.9637110799 0.5257641394 0.2550193437
## [571] 0.8425071361 0.6835579339 0.3542656137 0.9468998224 0.8253913396
## [576] 0.0320681024 0.8009413995 0.2835036211 0.8627280369 0.6196113171
## [581] 0.7354055322 0.7042326105 0.8501867270 0.8251521052 0.8080183615
## [586] 0.9128911106 0.2651957849 0.9200240569 0.6684833134 0.6572273036
## [591] 0.5946049758 0.9258234508 0.1045361655 0.4323124902 0.5884539983
## [596] 0.9125463746 0.6930765409 0.0612914448 0.9828706940 0.7431088653
## [601] 0.2068236275 0.2970700946 0.4015775677 0.3035781509 0.6783173380
## [606] 0.1442428357 0.7477181561 0.8643508835 0.6872852440 0.8450815298
## [611] 0.8591453389 0.7155871654 0.8747829839 0.4168886626 0.0523884762
## [616] 0.4311508541 0.8699771105 0.0094300914 0.7225479661 0.9645635099
## [621] 0.2294725587 0.9414274313 0.5996548864 0.3199552880 0.3680593069
## [626] 0.3241101336 0.8284453533 0.0802825245 0.2545145033 0.3891225385
## [631] 0.7527135671 0.6313121992 0.5312417105 0.3020804634 0.7031106020
## [636] 0.1561811434 0.8093725988 0.8169445253 0.5550815708 0.6421428972
## [641] 0.8264394202 0.7874418723 0.2534485015 0.8788151420 0.1997786281
## [646] 0.0296691919 0.9909694218 0.6043973279 0.4868918869 0.1264328358
## [651] 0.7422927062 0.5023460607 0.2424695229 0.1874108510 0.3308741655
## [656] 0.8400970043 0.2360435331 0.2881459370 0.3916622754 0.5514054198
## [661] 0.8151185976 0.7839823074 0.2611696941 0.3586736394 0.4696571145
## [666] 0.6908080878 0.8019700521 0.7636204730 0.7314020491 0.3453742538
## [671] 0.0233790406 0.9249749251 0.7361743117 0.5284539119 0.0259389651
## [676] 0.5572566183 0.6834524535 0.2981955982 0.9623579730 0.8815391285
## [681] 0.8127007231 0.0242697515 0.1349779656 0.4668280343 0.3810845104
## [686] 0.4349127191 0.7978018615 0.7168333840 0.0079865300 0.9847835235
## [691] 0.6015852154 0.8251972958 0.0148623886 0.5078060790 0.5104382017
## [696] 0.8090569349 0.2830211713 0.9509545742 0.6091378587 0.4926501720
## [701] 0.6040345316 0.5852358192 0.8131215062 0.6516282519 0.2974697973
## [706] 0.4049514665 0.3863378498 0.5548989535 0.9899436219 0.7517814594
## [711] 0.7896102639 0.2856648238 0.2047591922 0.4128368595 0.7303948575
## [716] 0.9868601053 0.5024669189 0.3313909958 0.6937342742 0.0654005902
## [721] 0.1500367809 0.1052966106 0.0197862850 0.3908512597 0.1182656002
## [726] 0.9906605261 0.3008788191 0.0408763660 0.1238454394 0.3832684488
## [731] 0.9561085703 0.0914707901 0.3440459471 0.7534254773 0.4688948393
## [736] 0.0332159714 0.2453385124 0.2887331210 0.2409024420 0.9680771143
## [741] 0.5814754986 0.6403869330 0.6628212153 0.4433091595 0.8562710672
## [746] 0.5340177126 0.2334043055 0.9600019376 0.8088611602 0.8239885387
## [751] 0.0825039505 0.7232702340 0.6217315875 0.9333907971 0.5753666770
## [756] 0.0426129715 0.4349424457 0.6928186382 0.6961959009 0.2527274983
## [761] 0.8159654948 0.8821414984 0.5477073181 0.5792689417 0.8267826780
## [766] 0.1111345706 0.6968944275 0.0288303748 0.2895289275 0.4706488270
## [771] 0.7800543848 0.2559883392 0.7714396275 0.5879654277 0.2777118254
## [776] 0.6860747372 0.7344409674 0.5613213682 0.0303025341 0.7530470700
## [781] 0.5556092085 0.4223272833 0.5949527719 0.0897908374 0.5477512905
## [786] 0.0076269226 0.0221252283 0.1513033207 0.3543285611 0.5998576151
## [791] 0.1593409118 0.9945898911 0.1290060158 0.3922706575 0.5060674178
## [796] 0.9344360873 0.6567853086 0.9386965593 0.2941812493 0.4197072629
## [801] 0.2162675429 0.0708067021 0.0052328235 0.0079573195 0.5290176750
## [806] 0.5807481420 0.7734459862 0.6150977763 0.4489760073 0.8595178479
## [811] 0.3128221184 0.5491125437 0.8182689231 0.8613903646 0.0319796018
## [816] 0.3323303196 0.3782242408 0.4036910308 0.3768118129 0.8128832537
## [821] 0.5093947062 0.7623506228 0.8816864900 0.2358025336 0.2901887984
## [826] 0.3935586710 0.7247597624 0.1327357262 0.7520545672 0.4668486256
## [831] 0.5047716547 0.5686121581 0.4180800724 0.7315619413 0.7700006666
## [836] 0.1340475976 0.4897396811 0.5086563989 0.0361894297 0.1255378707
## [841] 0.0347150459 0.9434105607 0.3983017150 0.2512090395 0.4757882191
## [846] 0.7881840330 0.8393704337 0.9834263006 0.1664120906 0.8474212564
## [851] 0.6482946975 0.8905366843 0.5845353033 0.4189990326 0.1663957299
## [856] 0.7222598826 0.9325262175 0.2658053171 0.3683525410 0.5659386758
## [861] 0.0445064441 0.1124258367 0.0710959048 0.3221618715 0.4143579917
## [866] 0.6153891860 0.8752952777 0.8406333674 0.7367900296 0.8990218795
## [871] 0.3907711669 0.5317097956 0.0406364410 0.5118846477 0.1542076529
## [876] 0.6207736935 0.3784777301 0.4704964519 0.3036240635 0.2794935894
## [881] 0.2292054119 0.5094459536 0.5758220188 0.8039463593 0.1216084894
## [886] 0.4170303459 0.0519598180 0.3259610937 0.1643100085 0.8971349664
## [891] 0.2455308398 0.8814140609 0.6582900689 0.4181259810 0.1310577302
## [896] 0.7782266999 0.0590340386 0.5321815803 0.5927642423 0.4658527176
## [901] 0.0236412727 0.6917162037 0.8359708698 0.4402697531 0.3722323007
## [906] 0.6970511768 0.4102844642 0.3844982425 0.6636080409 0.2358496184
## [911] 0.4232737748 0.5479586602 0.3931890265 0.1062949195 0.3955269200
## [916] 0.9544947529 0.2899988042 0.4666315657 0.3311615847 0.2937728383
## [921] 0.6274422535 0.2588622007 0.2170646535 0.8274661789 0.6988277468
## [926] 0.3977112083 0.9704776616 0.7360758015 0.9433095532 0.8623856783
## [931] 0.4475603553 0.8450153333 0.0572740012 0.1682879997 0.2207297690
## [936] 0.0565650582 0.1380104534 0.5392658697 0.2303999634 0.4091855690
## [941] 0.8165116354 0.6425841756 0.3633918806 0.9443115606 0.7223812065
## [946] 0.5874143587 0.4373038982 0.3082216072 0.7875281004 0.9136773758
## [951] 0.8613847478 0.5567718933 0.7981290373 0.5178754283 0.3832845970
## [956] 0.5144157698 0.9681519701 0.8438664221 0.9029133939 0.7648132292
## [961] 0.2962415786 0.1753941360 0.1882586994 0.0875379376 0.9686302447
## [966] 0.4379321581 0.3933523919 0.0282676511 0.7209415729 0.9840107893
## [971] 0.2819502202 0.1108359611 0.3748575980 0.8849335033 0.3767509712
## [976] 0.9121191690 0.2548391731 0.0325644030 0.1106346701 0.0916177887
## [981] 0.5434797094 0.3467785346 0.4073343517 0.9480427315 0.5643252749
## [986] 0.6799091944 0.1960254738 0.9543250930 0.1124483992 0.6935384474
## [991] 0.4730036755 0.8652128449 0.9273684321 0.6042248462 0.0745188349
## [996] 0.5717727272 0.3041401030 0.4901706567 0.5963783127 0.2782549162
summary(credit)
## checking_balance months_loan_duration credit_history
## < 0 DM :274 Min. : 4.0 critical :293
## > 200 DM : 63 1st Qu.:12.0 delayed : 88
## 1 - 200 DM:269 Median :18.0 fully repaid : 40
## unknown :394 Mean :20.9 fully repaid this bank: 49
## 3rd Qu.:24.0 repaid :530
## Max. :72.0
##
## purpose amount savings_balance employment_length
## radio/tv :280 Min. : 250 < 100 DM :603 > 7 yrs :253
## car (new) :234 1st Qu.: 1366 > 1000 DM : 48 0 - 1 yrs :172
## furniture :181 Median : 2320 101 - 500 DM :103 1 - 4 yrs :339
## car (used):103 Mean : 3271 501 - 1000 DM: 63 4 - 7 yrs :174
## business : 97 3rd Qu.: 3972 unknown :183 unemployed: 62
## education : 50 Max. :18424
## (Other) : 55
## installment_rate personal_status other_debtors residence_history
## Min. :1.000 divorced male: 50 co-applicant: 41 Min. :1.000
## 1st Qu.:2.000 female :310 guarantor : 52 1st Qu.:2.000
## Median :3.000 married male : 92 none :907 Median :3.000
## Mean :2.973 single male :548 Mean :2.845
## 3rd Qu.:4.000 3rd Qu.:4.000
## Max. :4.000 Max. :4.000
##
## property age installment_plan housing
## building society savings:232 Min. :19.00 bank :139 for free:108
## other :332 1st Qu.:27.00 none :814 own :713
## real estate :282 Median :33.00 stores: 47 rent :179
## unknown/none :154 Mean :35.55
## 3rd Qu.:42.00
## Max. :75.00
##
## existing_credits default dependents telephone foreign_worker
## Min. :1.000 Min. :1.0 Min. :1.000 none:596 no : 37
## 1st Qu.:1.000 1st Qu.:1.0 1st Qu.:1.000 yes :404 yes:963
## Median :1.000 Median :1.0 Median :1.000
## Mean :1.407 Mean :1.3 Mean :1.155
## 3rd Qu.:2.000 3rd Qu.:2.0 3rd Qu.:1.000
## Max. :4.000 Max. :2.0 Max. :2.000
##
## job
## mangement self-employed:148
## skilled employee :630
## unemployed non-resident: 22
## unskilled resident :200
##
##
##
summary(credit_rand)
## checking_balance months_loan_duration credit_history
## < 0 DM :274 Min. : 4.0 critical :293
## > 200 DM : 63 1st Qu.:12.0 delayed : 88
## 1 - 200 DM:269 Median :18.0 fully repaid : 40
## unknown :394 Mean :20.9 fully repaid this bank: 49
## 3rd Qu.:24.0 repaid :530
## Max. :72.0
##
## purpose amount savings_balance employment_length
## radio/tv :280 Min. : 250 < 100 DM :603 > 7 yrs :253
## car (new) :234 1st Qu.: 1366 > 1000 DM : 48 0 - 1 yrs :172
## furniture :181 Median : 2320 101 - 500 DM :103 1 - 4 yrs :339
## car (used):103 Mean : 3271 501 - 1000 DM: 63 4 - 7 yrs :174
## business : 97 3rd Qu.: 3972 unknown :183 unemployed: 62
## education : 50 Max. :18424
## (Other) : 55
## installment_rate personal_status other_debtors residence_history
## Min. :1.000 divorced male: 50 co-applicant: 41 Min. :1.000
## 1st Qu.:2.000 female :310 guarantor : 52 1st Qu.:2.000
## Median :3.000 married male : 92 none :907 Median :3.000
## Mean :2.973 single male :548 Mean :2.845
## 3rd Qu.:4.000 3rd Qu.:4.000
## Max. :4.000 Max. :4.000
##
## property age installment_plan housing
## building society savings:232 Min. :19.00 bank :139 for free:108
## other :332 1st Qu.:27.00 none :814 own :713
## real estate :282 Median :33.00 stores: 47 rent :179
## unknown/none :154 Mean :35.55
## 3rd Qu.:42.00
## Max. :75.00
##
## existing_credits default dependents telephone foreign_worker
## Min. :1.000 Min. :1.0 Min. :1.000 none:596 no : 37
## 1st Qu.:1.000 1st Qu.:1.0 1st Qu.:1.000 yes :404 yes:963
## Median :1.000 Median :1.0 Median :1.000
## Mean :1.407 Mean :1.3 Mean :1.155
## 3rd Qu.:2.000 3rd Qu.:2.0 3rd Qu.:1.000
## Max. :4.000 Max. :2.0 Max. :2.000
##
## job
## mangement self-employed:148
## skilled employee :630
## unemployed non-resident: 22
## unskilled resident :200
##
##
##
head(credit[1:10],10)
## checking_balance months_loan_duration credit_history purpose amount
## 1 < 0 DM 6 critical radio/tv 1169
## 2 1 - 200 DM 48 repaid radio/tv 5951
## 3 unknown 12 critical education 2096
## 4 < 0 DM 42 repaid furniture 7882
## 5 < 0 DM 24 delayed car (new) 4870
## 6 unknown 36 repaid education 9055
## 7 unknown 24 repaid furniture 2835
## 8 1 - 200 DM 36 repaid car (used) 6948
## 9 unknown 12 repaid radio/tv 3059
## 10 1 - 200 DM 30 critical car (new) 5234
## savings_balance employment_length installment_rate personal_status
## 1 unknown > 7 yrs 4 single male
## 2 < 100 DM 1 - 4 yrs 2 female
## 3 < 100 DM 4 - 7 yrs 2 single male
## 4 < 100 DM 4 - 7 yrs 2 single male
## 5 < 100 DM 1 - 4 yrs 3 single male
## 6 unknown 1 - 4 yrs 2 single male
## 7 501 - 1000 DM > 7 yrs 3 single male
## 8 < 100 DM 1 - 4 yrs 2 single male
## 9 > 1000 DM 4 - 7 yrs 2 divorced male
## 10 < 100 DM unemployed 4 married male
## other_debtors
## 1 none
## 2 none
## 3 none
## 4 guarantor
## 5 none
## 6 none
## 7 none
## 8 none
## 9 none
## 10 none
head(credit_rand[1:10],10)
## checking_balance months_loan_duration credit_history purpose amount
## 14 < 0 DM 24 critical car (new) 1199
## 448 1 - 200 DM 7 repaid radio/tv 2576
## 697 1 - 200 DM 12 repaid radio/tv 1103
## 32 < 0 DM 24 repaid furniture 4020
## 196 1 - 200 DM 9 critical education 1501
## 83 unknown 18 repaid business 1568
## 119 < 0 DM 33 critical furniture 4281
## 602 1 - 200 DM 9 repaid furniture 918
## 443 1 - 200 DM 20 delayed others 2629
## 945 < 0 DM 15 repaid furniture 1845
## savings_balance employment_length installment_rate personal_status
## 14 < 100 DM > 7 yrs 4 single male
## 448 < 100 DM 1 - 4 yrs 2 single male
## 697 < 100 DM 4 - 7 yrs 4 single male
## 32 < 100 DM 1 - 4 yrs 2 single male
## 196 < 100 DM > 7 yrs 2 female
## 83 101 - 500 DM 1 - 4 yrs 3 female
## 119 501 - 1000 DM 1 - 4 yrs 1 female
## 602 < 100 DM 1 - 4 yrs 4 female
## 443 < 100 DM 1 - 4 yrs 2 single male
## 945 < 100 DM 0 - 1 yrs 4 female
## other_debtors
## 14 none
## 448 guarantor
## 697 guarantor
## 32 none
## 196 none
## 83 none
## 119 none
## 602 none
## 443 none
## 945 guarantor
Credit_train <- credit_rand[1:900, ]
Credit_test<- credit_rand[901:1000, ]
Credit_train$default <- as.factor(Credit_train$default)
Credit_test$default <- as.factor(Credit_test$default)
library(C50)
m<- C5.0(Credit_train, Credit_train$default , trials=1, costs=NULL)
credit_model<-C5.0(Credit_train[-17], Credit_train$default)
credit_pred <-predict (credit_model, Credit_test[-17])
credit_model
##
## Call:
## C5.0.default(x = Credit_train[-17], y = Credit_train$default)
##
## Classification Tree
## Number of samples: 900
## Number of predictors: 20
##
## Tree size: 57
##
## Non-standard options: attempt to group attributes
summary(credit_model)
##
## Call:
## C5.0.default(x = Credit_train[-17], y = Credit_train$default)
##
##
## C5.0 [Release 2.07 GPL Edition] Fri Apr 11 23:10:49 2025
## -------------------------------
##
## Class specified by attribute `outcome'
##
## Read 900 cases (21 attributes) from undefined.data
##
## Decision tree:
##
## checking_balance = unknown: 1 (358/44)
## checking_balance in {< 0 DM,> 200 DM,1 - 200 DM}:
## :...foreign_worker = no:
## :...installment_plan in {none,stores}: 1 (17/1)
## : installment_plan = bank:
## : :...residence_history <= 3: 2 (2)
## : residence_history > 3: 1 (2)
## foreign_worker = yes:
## :...credit_history in {fully repaid,fully repaid this bank}: 2 (61/20)
## credit_history in {critical,delayed,repaid}:
## :...months_loan_duration <= 11: 1 (76/13)
## months_loan_duration > 11:
## :...savings_balance = > 1000 DM: 1 (13)
## savings_balance in {< 100 DM,101 - 500 DM,501 - 1000 DM,
## : unknown}:
## :...checking_balance = > 200 DM:
## :...dependents > 1: 2 (3)
## : dependents <= 1:
## : :...credit_history in {delayed,repaid}: 1 (23/3)
## : credit_history = critical:
## : :...amount <= 2337: 2 (3)
## : amount > 2337: 1 (6)
## checking_balance = < 0 DM:
## :...other_debtors = guarantor:
## : :...credit_history = critical: 2 (1)
## : : credit_history in {delayed,repaid}: 1 (11/1)
## : other_debtors in {co-applicant,none}:
## : :...job = mangement self-employed: 1 (26/6)
## : job in {skilled employee,unemployed non-resident,
## : : unskilled resident}:
## : :...purpose in {domestic appliances,others,
## : : radio/tv,repairs,
## : : retraining}: 2 (33/10)
## : purpose = business:
## : :...job = skilled employee: 2 (3)
## : : job in {unemployed non-resident,
## : : unskilled resident}: 1 (3)
## : purpose = education: [S1]
## : purpose = car (new): [S2]
## : purpose = car (used):
## : :...amount > 6229: 2 (5)
## : : amount <= 6229: [S3]
## : purpose = furniture:
## : :...months_loan_duration > 27: 2 (9/1)
## : months_loan_duration <= 27: [S4]
## checking_balance = 1 - 200 DM:
## :...savings_balance = unknown: 1 (34/6)
## savings_balance in {< 100 DM,101 - 500 DM,
## : 501 - 1000 DM}:
## :...months_loan_duration > 45: 2 (11/1)
## months_loan_duration <= 45:
## :...installment_plan = stores:
## :...age <= 35: 2 (4)
## : age > 35: 1 (2)
## installment_plan = bank:
## :...residence_history <= 1: 1 (3)
## : residence_history > 1:
## : :...existing_credits <= 1: 2 (5)
## : existing_credits > 1:
## : :...installment_rate > 2: 2 (3)
## : installment_rate <= 2: [S5]
## installment_plan = none:
## :...other_debtors = co-applicant: 2 (3/1)
## other_debtors = guarantor: 1 (7/1)
## other_debtors = none:
## :...employment_length = 4 - 7 yrs:
## :...age <= 41: 1 (16)
## : age > 41: 2 (3/1)
## employment_length in {> 7 yrs,
## : 0 - 1 yrs,
## : 1 - 4 yrs,
## : unemployed}:
## :...amount > 7980: 2 (7)
## amount <= 7980:
## :...amount > 4746: 1 (10)
## amount <= 4746: [S6]
##
## SubTree [S1]
##
## savings_balance in {< 100 DM,101 - 500 DM,501 - 1000 DM}: 2 (6)
## savings_balance = unknown: 1 (2)
##
## SubTree [S2]
##
## savings_balance = 101 - 500 DM: 1 (1)
## savings_balance in {501 - 1000 DM,unknown}: 2 (4)
## savings_balance = < 100 DM:
## :...personal_status in {divorced male,female,single male}: 2 (29/6)
## personal_status = married male: 1 (2)
##
## SubTree [S3]
##
## job in {skilled employee,unemployed non-resident}: 1 (8/1)
## job = unskilled resident: 2 (1)
##
## SubTree [S4]
##
## employment_length in {> 7 yrs,4 - 7 yrs}: 1 (7/1)
## employment_length = unemployed: 2 (2)
## employment_length = 0 - 1 yrs:
## :...job in {skilled employee,unemployed non-resident}: 1 (4)
## : job = unskilled resident: 2 (1)
## employment_length = 1 - 4 yrs:
## :...property in {building society savings,unknown/none}: 1 (5)
## property in {other,real estate}:
## :...residence_history <= 2: 1 (4/1)
## residence_history > 2: 2 (5)
##
## SubTree [S5]
##
## other_debtors = co-applicant: 2 (1)
## other_debtors in {guarantor,none}: 1 (3)
##
## SubTree [S6]
##
## housing = for free: 1 (2)
## housing = rent:
## :...credit_history = critical: 1 (1)
## : credit_history in {delayed,repaid}: 2 (10/2)
## housing = own:
## :...savings_balance = 101 - 500 DM: 1 (6)
## savings_balance in {< 100 DM,501 - 1000 DM}:
## :...residence_history <= 1: 1 (8/1)
## residence_history > 1:
## :...installment_rate <= 1: 1 (2)
## installment_rate > 1:
## :...employment_length in {> 7 yrs,unemployed}: 1 (13/6)
## employment_length in {0 - 1 yrs,1 - 4 yrs}: 2 (10)
##
##
## Evaluation on training data (900 cases):
##
## Decision Tree
## ----------------
## Size Errors
##
## 57 127(14.1%) <<
##
##
## (a) (b) <-classified as
## ---- ----
## 590 42 (a): class 1
## 85 183 (b): class 2
##
##
## Attribute usage:
##
## 100.00% checking_balance
## 60.22% foreign_worker
## 57.89% credit_history
## 51.11% months_loan_duration
## 42.67% savings_balance
## 30.44% other_debtors
## 17.78% job
## 15.56% installment_plan
## 14.89% purpose
## 12.89% employment_length
## 10.22% amount
## 6.78% residence_history
## 5.78% housing
## 3.89% dependents
## 3.56% installment_rate
## 3.44% personal_status
## 2.78% age
## 1.56% property
## 1.33% existing_credits
##
##
## Time: 0.0 secs
library(partykit)
## Loading required package: grid
## Loading required package: libcoin
## Loading required package: mvtnorm
plot(credit_model)
library(gmodels)
CrossTable(Credit_test$default, credit_pred,
prop.chisq = FALSE, prop.c= FALSE, prop.r = FALSE,
dnn=c('actual default', 'predicted default'))
##
##
## Cell Contents
## |-------------------------|
## | N |
## | N / Table Total |
## |-------------------------|
##
##
## Total Observations in Table: 100
##
##
## | predicted default
## actual default | 1 | 2 | Row Total |
## ---------------|-----------|-----------|-----------|
## 1 | 54 | 14 | 68 |
## | 0.540 | 0.140 | |
## ---------------|-----------|-----------|-----------|
## 2 | 11 | 21 | 32 |
## | 0.110 | 0.210 | |
## ---------------|-----------|-----------|-----------|
## Column Total | 65 | 35 | 100 |
## ---------------|-----------|-----------|-----------|
##
##
Credit_boost10<-C5.0(Credit_train[-17], Credit_train$default,
trials=10)
credit_boost_predict10 <- predict(Credit_boost10, Credit_test)
CrossTable(Credit_test$default, credit_boost_predict10,
prop.chisq = FALSE, prop.c = FALSE, prop.r = FALSE,
dnn=c('actual default', 'predicted default'))
##
##
## Cell Contents
## |-------------------------|
## | N |
## | N / Table Total |
## |-------------------------|
##
##
## Total Observations in Table: 100
##
##
## | predicted default
## actual default | 1 | 2 | Row Total |
## ---------------|-----------|-----------|-----------|
## 1 | 63 | 5 | 68 |
## | 0.630 | 0.050 | |
## ---------------|-----------|-----------|-----------|
## 2 | 16 | 16 | 32 |
## | 0.160 | 0.160 | |
## ---------------|-----------|-----------|-----------|
## Column Total | 79 | 21 | 100 |
## ---------------|-----------|-----------|-----------|
##
##
matrix_dimensions <- list(c('no', 'yes'), c('no', 'yes'))
names(matrix_dimensions) <- c('predicted', 'actual')
error_cost <- matrix(c(0,1,4,0), nrow=2)
M<- C5.0(Credit_train, Credit_train$default, trials=1,
costs=error_cost)
## Warning: no dimnames were given for the cost matrix; the factor levels will be
## used
credit_cost <- C5.0 (Credit_train[-17], Credit_train$default,
costs= error_cost)
## Warning: no dimnames were given for the cost matrix; the factor levels will be
## used
credit_cost_pred<- predict(credit_cost,
Credit_test)
Credit_test$default <- factor(Credit_test$default, levels = c(1, 2), labels = c("No", "Yes"))
credit_pred <- factor(credit_pred, levels = c(1, 2), labels = c("No", "Yes"))
CrossTable(Credit_test$default, credit_pred,
prop.chisq = FALSE, prop.c= FALSE, prop.r = FALSE,
dnn=c('actual default', 'predicted default'))
##
##
## Cell Contents
## |-------------------------|
## | N |
## | N / Table Total |
## |-------------------------|
##
##
## Total Observations in Table: 100
##
##
## | predicted default
## actual default | No | Yes | Row Total |
## ---------------|-----------|-----------|-----------|
## No | 54 | 14 | 68 |
## | 0.540 | 0.140 | |
## ---------------|-----------|-----------|-----------|
## Yes | 11 | 21 | 32 |
## | 0.110 | 0.210 | |
## ---------------|-----------|-----------|-----------|
## Column Total | 65 | 35 | 100 |
## ---------------|-----------|-----------|-----------|
##
##
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.