0% found this document useful (0 votes)
21 views25 pages

DM Using R Lab

The document outlines various data mining algorithms including the Apriori algorithm for association rule extraction, K-means clustering, hierarchical clustering, KNN classification, and decision trees. Each algorithm is described with a series of steps for implementation, including data preparation, function calls, and plotting methods. The document also includes snippets of R programming code for executing these algorithms.

Uploaded by

ponni.world009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
21 views25 pages

DM Using R Lab

The document outlines various data mining algorithms including the Apriori algorithm for association rule extraction, K-means clustering, hierarchical clustering, KNN classification, and decision trees. Each algorithm is described with a series of steps for implementation, including data preparation, function calls, and plotting methods. The document also includes snippets of R programming code for executing these algorithms.

Uploaded by

ponni.world009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 25
€bcle . WEdIGEtTtdididid CESESEEEE SE: EX.No:o4 APRIORI ALGORITHM TO EXTRACT DATE @ior.a4| ASSOCIATION RULE 4 AIM. Wrike to implement Apriori Algoritim to extract Bssocation ywe of Data mining. ALGORITHM. SEePL: Skark tRe process, Skepa: click R> Ri 3863.22 in Desktop +o open RTeol = window step 3. Select Pac > load pack ules. Now, arules mie on ‘elleted” Tom librany, sep 4: patterns is designed in tRe nikemssiooo steps: The pattems Summary axe displayed on te Screen. step 6: items =io00 yeprenents tRe columns and trans 1000 Yepresents ‘tRe rows. step 7: Rulos of apriori is lisk the. Some Parameters ep and thon daclone § pod moe. ‘tonfitied =09 and Larget = 1 en. step & Rexk 1 call ules) function tRat Inscect “ to visit the list” and sor “ skep 4: Stop te process. De) PROGRAM: Be local (pkg select sist (sort packages (all .awailable = . TRUE)), Qvaphics= TRUE > sif (nehar( pkg) library (pkg, character. only =TRVED } ) Loading equine package: Matrin Attaching Package : ‘aoules’ The following objects ane masked from ‘package hage’ : abbreviate , wyike > UibvavyC “ovules” > Patterns random . patkerns inikeensioaa’s Summary (oatterns)s Set of 2009 itemsets mast Lrequant items: ikemuiaa Ytem34qttemo3i itemgo4 ikem 4a) (othe ba 55 54 54 53 1633 a bans “onto transacting WThems=l008, nTrans=1000, 7IMOG¢6 rans) ; > agrawal, Patterna= patterns) “aK —| | | | ! | aiargactions (Reus) ff | PPO OHEEEELELELEEEE ECE EEE EEEYY YEU >datal "Adult", >ruley( aprioy ; (Adult, povametes click (suppor:=0-6. confidence =0.4 , target=“wles">) ; Aprvioy : Parameter specification: Confidence minval Sman orem wal 2.4 +) \ non FALSE >Tuler, Set of 5a vules >inapect (hand (sovt (-yules by- “lifE"), 305 O14 { gex=Hale, ‘ hakive~country = Sie kes 42> {racswhike} o54'5421 oFosteto 0.598R1T0 10 rhood (qualikytrulesy) ; Support confidance coverage |i lank O-4I738G7 0-9)73867 = |.008@0 = Lo0p0e 4.4 807 0-4539779 1538774 L.ovop00 Wpov0D AEtED \ 2 3 O.54d5 BIS —>SFBSCIS 0-6809327 098712 gE gy 4 ©. 5G0bb5D oBbobbso F682 Of 92 44,900 > Summary mes)» Seb of Sa rules Yke TengiR duatyibulion ‘ Sizoy 12 3 4 2 1% a4 13 minifig info: dota Lronsec Hons, Suuppor bortidanes Beek U ehh eh ee hk ee Eee ee Lei Be EX no.0g K-MEANS CLUSTERING TECHNIQUE Bao DATE:31.07 25 = ° _ sp AIM: . Be hike to implomont k-means clustering techniqne = tap ALGORITHM: Se Skepa: Start tho process = Step a: Select Rhool-s Ri 3863.2.2 ; step 3: $d yaluas are Gtoved in. tRe X Variables 3 ‘ wee wad vin formed ton given valus 100 : Skee 4+ Put wy values $6, column % auld , Y ams » Step 5. Then, call kmoans vd function with a porameters — %,a ond Started in that is, Corekmaanms = (4.29). Thes function displays & clusters OS of Size 0,50 clustering mean value , a Sum. of Squaw, and oWNoiloble components. "> Shep b: Plokt> metfiod to be used +o plot by = tep Eels on the Screan witR tdi Gf aby “9 skept: Prinkt motRod be be used Tk con ; di layeat tRe conker point centroid each <| , o| step 8 Next call k-meanat) clustering function - to set Clustering starting Voluors ab 20. 2 stepg: Again. plokL> method to be used. 2 ~daplayed the different sizes oF ahead 2 : is Skop to: stop the Procoas. 2 —_ = _ 2 i | PRosiean: > =rbind (matyie(vnorm live, Sd=0-3) hdol=s), motrin Anorm (no. meary=!, $d= 0.3, Ncol =2)) > Colramosn) =e("%", "4" r= Kmeans(n,a)) k-means clustering with @ clusters of Sizes 50,50 duster means: ‘ y (105309944 = 1.085 33893 2 -O. 01609549 -0. 02649584 clustering vector: aa CY) sasaare re 22a ze aaa eee Se dorrzare 22 2Ke2a2 BRR * yal By wpyeyey ayy wet | phe Oc als ci gcluster > 4 15 2 | iF 6 a) “og2 daal °,°? yD ©. 2 49 ! 100° -95T COCCTeT eee eee eee eeTY —2 > points (eibebnkev’ Clete, Peh=8, won=ea) >x=vhind Gratrin Crnorm (loo, Sd=0-3) ncol=2), motrin Cinorm(ito0, s4=0.3), nenl=2)) matrix (ynorm (too, $420.3), neol= 2). makyix (norm (v0, means!,$d-03),neol=a), tratrin Crnprm (100, maan =}, Sd=0.3),neol=@), Mottin (norm (00, mean=1, sdz0.3), neol=2a)) >colnamas OO) =cO'"%", ”y") © 1 = Wmnaanalx.b dS K-means clustering with b dusters of Size 46,50, A421, 16, 47 Cluster moans: * y ob Hob 22 149462484 \.25pIogo> =:308 27611 ) 2 3 -0.04824088 -0-03915459 4 \45ggeon 91853549 s \eprb8 0a 30 9-80RIR34S 6 — co.6y5324a0 O-1E138673 Available Componont § : O} “cluster” “Centers” “totgs” "wi ase “Lok -wilRings” “betweanse’ “size” “ites” XS vidaul” SSLSELEEKRELDELEGELEGEREEELEEETESEUEE | a » -o3 bo Gb te ye 50 5 >poinks Cer fanters , clel.b, peh = 8) he 2, ogo be, 99 go ‘© 007 90 aoe 25 4 Be ob:O 960 9¢ 0° SS ——41— +05 09 85 lg 16 20 SVHV.ovuuesRBELELEDELE ~ eS » ] to FeNo:03 HIERARCHICAL CLUSTERING a [DATE 0202.01, | ww AIM: . Write bo implement any one hierarchical clustering ALGORITHM: Step 4: Skat the PTOcoas . Stepa: th Desktop Rbool > Ri 386.22 SEPA Using 4 variable be define matrix format and iks volun ore miliolized Step4: Spearman and tefaplete method ano inikilized tditg cand by variable. step 5 plokid is used be declare \Vaninus valussand coll Re dendrogram. method using as Vouoble. Skop 6 Tide He variable unclassc) method mar height Values and label valuos one. cLisplayed. Using dondrogramc) meted to dus dordrograrn treo stuckune. Poy eps rd ond hig PLO method. qa skep 7: 2 Voluos one plotted uaing, stepq: Distance values ano erage and Stored SeeeaKeLETETETEETEEL EGER EE EEE Bs motrin fon Lowi rm i oe d= AOE (on.malvin onbeat sy) owing one. step le: ee matiiod Set of clusters [or tices cts ont or S a de) PROGRAM: SSS — | Se) > y2-matrix (xno rms), 10,5, damnames -list (pasteCg : \t0, sep=" "J, sae tpoate ("4") \5,sep=" "DD Be ><<- corlkty>, method ="Spearman”) ; =e rd ean, distlt-e) ; dhre-helust(d smethod -"Lomple te", members=NULL) rPax(mfyow =c2,29)5 SPbL Chr shang =D = Pal DOEETETEULECEETECEECEEEY 3148 $5 gn gq beELE S_ os = >ple( an dondrogyamthr),ecgapar “bist (tall =4), ~ a ry] ~ | | | | | ETH | 3 | tun class (hy) D1 ol 0.2 0.3 0.406 0.7 1.0 [.2 1.4 mp $ oydoy me 0134461765210 CeeCuC ery | > sty (as dondsogromthy )) Pp -- [dondagaam wi, branehoa and \o mombers at h=19] | E '_.Cdandiogyam. wis branchas and Tmember ak h-=i ' | 1 \ \--[dendvogram w)2 branches and 4 mambers. my | | 1 plandregiam vol? branches and Smambers ak | 207 eudud |.=-[dandwoqram vale branchss and 3 mombers ot be = mh }labels [hrs Ordon] hab] ad chaxacter (o> ~ Q a. a oe s i >pay (mf yoo =eC 2,295 - | | | >Wid 2-04 dand voqnarnthy ds >ploeChyelads to 25 R 9843 9) i a we ss 4 x shel 2c sates chrdi, sarveple(s s1o))5 | >plok Girdads SSEESISTRESSEFSESSS UCU EVEVE EFF) : | | . haf a EI > labels Crd) oom eit . : 30 ‘ys sgn "ga “gb “ga” “4d “qa” gs) “ga” “gio! ® Jabels(hrda) * Cin" "RT QS" og gn Ogee nga’ ge” "a4 ge! 2 seo yar™ Clumern dis dist (os. matrixtntuars,)) helust id) lush Che, Ke 3, border ="red “> >he sd » > Plot the) b >yeck he | -[- Fret auty rttirmies, Qieic Sworn, BRING FBI Ca paved pay pepe yu WEAN “comelere” ) Relask AC, Syrom gaa] | Pere? (etathuy tayshays — pasg suvarel T TT TT-T 35 —— Ex:no - "A CLASSIFICATION ALGORITHM USING KNN DATE 4.03.24 AM: Write to implement classification algovithun Algoritim, Step 4: Stark the procoss Step a: selecl RT 2 Ri 38622. Step & The tow Q colummn ave mentioned at Al,Aa,A3, BI,Ba,B3 and VW-¥a Shep 4: hind) method one usedto create te tuo variables. Step 5: Tha groups ome gloyed in tratn variable. CUECEEEEEE EYEE E YEE! » | step &: plotc> metfind Is used to drow the 2 Point for Parkeuler value. | » stept: Stop the P10 cos. 2 < | ° | 2 e . > | » » 2 \ | VVSCSCUVOUSEREVEVEUEDER EEE EEE YY YEE KE PROGRAM >Al\=c(o,0) rAa=c() AB = 09,2) YBI= 6 (bb) yBaz ¢(8 6.1) >B3=¢(b.6,6) Shaun = vind (AL, Aa .A3,B1, B2.83 ) det =factoy(ccrep('A", 3), vep'B’. 8D) yheat = (4.4) >libraryclaas ) © Strmany(tnn Chron beat, #1, k= 19) ou >plot reat Tet 7 i? a >Plob(trainy ** '* ter °° oC oO | ———4 | 7Sunumary Chest) Min dst Qu. Median Heo axd@a. Mare 4 4 4 4 4 + Summary (train) VI vo Min . : 0-000 Min. 0.00 Ast Qu: |a50 Act Quik 26 Meduan: 3-760 Heduan:3 50 Man: b.500 Hoax: 400 | Print (test 3 Cl 4 4 >prindltrad Prntlbtginy 4 Al 0.0 Az 10 0 | Ad 30 2 B) 6&0 & Ba 56 7 B38 65 5 >View Chest) o [RowiG ety Fol TTT TPE FOO CUELEUEUUEUEEEUEEEY YY YUKU, . pb YNo-og DECISION TREE B& DATE 2302.24 . a AIM: Wrike to implemont decision tree ALGerTHM: Step4: Start Ra process. Skepa. Create cota. set in MS Excel with weather , tempeyalure , huumodiky , wind, golf play and Sowed ik ih "Cll Sweat I Booka.csv” steps Read Lablec) metRod used to retrjewe dota from tstrcal dake set and Stored inks Play-bost Voriable step 4° Next, use print data set values using print() mothod. Steps The doka set sammory Yeport also displayed using —summany 9 method. b: The ypartt method dito du step necoatandy Kad Vale - duplay skept Plott method used to draw te "e docsion trea without ‘slo. omer Step 8 Then next meticd used bo insert Voluss inks decision treo : stepd Tha deusion & : | *e coupe veule fled He skep 0 Stop the process te Cs PROGRAM > Ploy base <- yeadtable (esi! SweakM Book 4.cev", header = TRUE, sep="5"5 Print (play-bare) x neater Lemporatuna huenady wind me poy So, @ & re Ta 33 Gita hak hgh rene wes : : Tain “sy Nat nono yeh 8 5 youn cold een fio he ff we 4 Todo fo ge 7 1 TOL. coli ah, rand Ro 8 8 tino. wort : fone 4 q fine Gold , pedi none ed 1010 Youn, worm rods. ‘feu No u y faing warm. he ‘te ho \2 12 cloud Matin ¥ hone ye fag aki = M4 M4 R warn high. few yr ySumumaoyy (ploy-bare) Ly weather temperature humadily wind golf fey Min. s100 clouds 3 Cold 4 hah prea yest | At Qe 425 fines — hot4 . 1b aig | pe Medion: 7.60 tan: una meio Hone 8 > Hens 7-50 2 oI 3rd Qu slots we Mow. :t4,00 > Cd a | es s 2 ~~ — - —_____35 Sw > local CLpkg z ~select .}ist (sort (- packages (all-available =TRUE.)) a ics =TROE ) HE chor (93) Wbrory (tha charade only TRUE >4) fit < ~* part (golf play ~ weathor y temperatuna & st +wind, motod ="closs”, dota = play base , Cantro}= Ypovt. control (minsplit =1) > > Summary (SE) Variable importance weatfior temperature husrodliy Wind Ad a ao 15 Node number 1:14 observations, tamgleniky payam = 0:3 Predicted clas - yen ee el eta bovine CP nod) =I Clays counts . 5 tg Probabilities: 0, 457 0643 lef som. a Hobs) night Son =3C1 bs) PP PLORED N=4 nada), split, 1, loss, yval, (yprob) ¥ denotes terminal node Nvook 44 5 yes(n-251429 0.642964) Shumadile high F & nolo.514286 0.4286 714) A)weatfor=fine 3 0 Nolkoooo0e 0.00000 0) weather = cloud, Yarn 4 I Yed(0.2800000 0-1sPe000) lo) weathar =Tair 2 1 hop. 5000000 ©. 50000000) do) wind =few 1-9 Noll. 0000000 0.00060 00) * 21) Wind stone 10 Yer (0.0900680 |.9005900) + \\) weatfer = cloud @ 0 yes (p.0000000 |.0000000)* 3D humadily = moduiam 71 yeoto.42867) 0 11429) vv CURR CERO cd » » » >plok (tit uniform “TRUE , maan = “Deniicn Tree for dataset" > We Sian wey) CRP vA [lays] | |. | | oben (fit n=TRUE » a\l=TRUE , can =0-8) ReGraphicr Don eae Ac bye) [lel] | Decision Thee toy datoret EX:No:ob CUELELEUUV IU Vue neem erin ee — LINEAR REGRESSION DATE 05 03,24 AM. Wrike to implement Vineot veg reasion. ALGORITHM: Stepa Gort tha process, crogke databane in NSEncal with brain. era og, boly-weight 4 Tndax and Ren Soe iL, ¢ Step 3: Next, print tRe data set value using Print) method. Step 4: Read Lablec) matRed used to tebriove doko from Ms-Exco) database and Stored it by using di voriable. Step 5: plokid) metod used to display volus vf bron weight ond bodyweight. Steps Ablinet) metRod is used to drow tka Stiaight \ine for the rule of Bracn_ wei and be -weight . Steet. Agouir lokO mathiod to be used. ea diiplay fa varigua types of Standardalizod on te sereans Aubpul yeaults, | step 8: Stop the process. Sbede PROGRAM: od <—yead Lable (“c:/! sweat! Booka.cav”, has ve TRUE. | sepe".”) >printidey Index Brain weight fhody_weight \ \ 2.6410 46.914 75 Ao 2 2 2.9 tbo Tana 404 a 54. a2. a . o & 5400 60.151 > fila - Am (hog (Basi weight) «log (Body-weight), data=d)) >Par (mfrow =< U,199 . RRovjtia- Dacor FBR >plot Clog (dt $Body weight), Log (AL-4 Brainweight, +trlab=" 0 (Body weight y", ylab=" log (Brain weight bu Tmain="Simple linear Yeavession" > CUUUUUN UC CE Ue __Sirple linear. teqression _ Yo 3 Bram_weghts pabline (f1) ungie [neon Fagregore >Par (wtroweetaa)) “Log com cbeight ) Plot (fit) VEUHUUV UC ECU | jo a Ea | PiRsvapiics Dewicad ACTIVE), iP | Foxduala ve teed Mopral QQ 5 > ay 3 | 3384 . 5 "| 2 | = a 33%) ° 38. ° “ ° / - £ oe ot or yO - 2 al a Hel, sad ne 2, de ted Webs 3 “Thaovec tical Quanbbds 2 Gente. Locabiors Residuals vs leverage s S 3 Y 7 ~! q 3}! oy | 2S 3 ' > 2 |3 el Cache eo a & ' - . | 9 |S. et oN JT tl ° . fal ° Se Yo ro Ns o Nabe bt ot tae, y 5 s ae Fite Voliue ag | ? 2 SSSVSROCHUECCEUEYUKHUEYECEC CCH EH we Tee EX\ND sof DATE C1 08.4 DATA VISUALIZATION AIM: Write to implemont dota visualization ALGORITHM: Step 1: Start the Prowas. step a Create a table in MS-Encel. stepa: The toble is Soved in the c directory, and Mud is Soved in the form of “av in extension. skepy: Th tha table, the following fields ore inserted — housing , food, cloth , errker toxin and other steps: The appropriate integer yaluos ane jnserted in Rat fields stepb: Select Ro Ri 3863.22 in Desktop to open Ric) Window cept: ‘The table is Viewed by using te Variable “ene”. chops: Plot ta points In ta table. . bunplot O motRod is used to dirgl | Shep 4 to Data Viigualiza tion groph. “ shep jo’ Stop tRa Procads. . ab 47 » PROGRAM: - »| > « » exp ¢-vead table ("¢ :// Sweet HI Rooks.csv", header =TRUE, > xe sep" ") ™p eee » » \ X housing food clotR entertain othor ' (oo. Woo joo too 200 : 2 2 2.00 Joo = 2.00 200 400 3 3 300 Ron 300 300 boo v4 pe ft 40 “joo 400 Ape Bee ape f mm boo toe oe boo p00 loo 9 + » se 2 “100 4oo0 100 Too goo » 4 a oo Boo Bou 800 70 P q qoo a90 700 qoo Joo ye © oo 100 &p0 Joo 400 ® >Viewtexp) » > | PData teup = lof] | 2 FB} 3 ts housing food | clotR [entertain | otfer | (| oo \oo \oo { » 2 |? ao | 400 200 | = 3 | 3] 300 | aoo Apo | e 4 | +] 400 Too | bon ~ [8 |5| 500 | 600 foo = 616] boo | Bee. \o9 ° 7 || too 4oo oo | &| a0 50 a | 600 | Joo | __ 5° | a 4} 40 op &oo > yo | to | 100 too | 700 - ) 7 2 E a [ > plot cong) - ] Roche Deyers ACT - IF | &@eeveees EVEN UNVC CCV UN TCU C YUE e wew Ars]

You might also like