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:
seeds_dataset <- read.delim("Z:/seeds_dataset.txt", header=FALSE)
sd <- seeds_dataset
feature_name<-c('area', 'perimeter', 'compactness', 'length_of_kernel', 'width.of.kernel', 'asymetry.coefficient', 'length.of.kernel.groove', 'type.of.seed')
colnames(sd)<-feature_name
View(sd)
summary(sd)
## area perimeter compactness length_of_kernel
## Min. : 1.00 Min. : 1.00 Min. :0.8081 Min. :0.8189
## 1st Qu.:12.11 1st Qu.:13.43 1st Qu.:0.8577 1st Qu.:5.2447
## Median :14.13 Median :14.29 Median :0.8735 Median :5.5180
## Mean :14.29 Mean :14.43 Mean :0.8713 Mean :5.5639
## 3rd Qu.:17.09 3rd Qu.:15.69 3rd Qu.:0.8877 3rd Qu.:5.9798
## Max. :21.18 Max. :17.25 Max. :0.9183 Max. :6.6750
## NA's :1 NA's :9 NA's :14 NA's :11
## width.of.kernel asymetry.coefficient length.of.kernel.groove type.of.seed
## Min. :2.630 Min. :0.7651 Min. :3.485 Min. :1.000
## 1st Qu.:2.956 1st Qu.:2.6002 1st Qu.:5.045 1st Qu.:1.000
## Median :3.245 Median :3.5990 Median :5.226 Median :2.000
## Mean :3.281 Mean :3.6935 Mean :5.408 Mean :2.084
## 3rd Qu.:3.566 3rd Qu.:4.7687 3rd Qu.:5.879 3rd Qu.:3.000
## Max. :5.325 Max. :8.4560 Max. :6.735 Max. :5.439
## NA's :12 NA's :11 NA's :15 NA's :15
any(is.na(sd))
## [1] TRUE
sd<-na.omit(sd)
dim(sd)
## [1] 199 8
str(sd)
## 'data.frame': 199 obs. of 8 variables:
## $ area : num 15.3 14.9 14.3 13.8 16.1 ...
## $ perimeter : num 14.8 14.6 14.1 13.9 15 ...
## $ compactness : num 0.871 0.881 0.905 0.895 0.903 ...
## $ length_of_kernel : num 5.76 5.55 5.29 5.32 5.66 ...
## $ width.of.kernel : num 3.31 3.33 3.34 3.38 3.56 ...
## $ asymetry.coefficient : num 2.22 1.02 2.7 2.26 1.35 ...
## $ length.of.kernel.groove: num 5.22 4.96 4.83 4.8 5.17 ...
## $ type.of.seed : num 1 1 1 1 1 1 1 1 1 1 ...
## - attr(*, "na.action")= 'omit' Named int [1:22] 8 9 37 38 63 64 72 73 111 112 ...
## ..- attr(*, "names")= chr [1:22] "8" "9" "37" "38" ...
sd<- sd[, -8]
View(sd)
df_sc<-as.data.frame(scale(sd))
str(df_sc)
## 'data.frame': 199 obs. of 7 variables:
## $ area : num 0.1169 -0.0133 -0.2153 -0.3694 0.4182 ...
## $ perimeter : num 0.1863 -0.0197 -0.386 -0.5005 0.3008 ...
## $ compactness : num 0.00812 0.44123 1.4661 1.05872 1.39749 ...
## $ length_of_kernel : num 0.2702 -0.201 -0.7939 -0.7195 0.0335 ...
## $ width.of.kernel : num 0.123 0.178 0.189 0.3 0.784 ...
## $ asymetry.coefficient : num -1.005 -1.823 -0.68 -0.979 -1.594 ...
## $ length.of.kernel.groove: num -0.407 -0.943 -1.209 -1.25 -0.499 ...
dist_mat<- dist(df_sc, method = 'euclidean')
hclust_avg<-hclust(dist_mat, method = 'average')
plot(hclust_avg)
library(dendextend)
## Warning: package 'dendextend' was built under R version 4.3.2
##
## ---------------------
## Welcome to dendextend version 1.17.1
## Type citation('dendextend') for how to cite the package.
##
## Type browseVignettes(package = 'dendextend') for the package vignette.
## The github page is: https://github.com/talgalili/dendextend/
##
## Suggestions and bug-reports can be submitted at: https://github.com/talgalili/dendextend/issues
## You may ask questions at stackoverflow, use the r and dendextend tags:
## https://stackoverflow.com/questions/tagged/dendextend
##
## To suppress this message use: suppressPackageStartupMessages(library(dendextend))
## ---------------------
##
## Attaching package: 'dendextend'
## The following object is masked from 'package:stats':
##
## cutree
avg_dend_obj<-as.dendrogram(hclust_avg)
avg_col_dend<-color_branches(avg_dend_obj, h = 3)
plot(avg_col_dend)
cut_avg<-cutree(hclust_avg, k=3)
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.2
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
seeds_df_cl<- mutate(df_sc, cluster = cut_avg)
seeds_df_cl
## area perimeter compactness length_of_kernel width.of.kernel
## 1 0.1168695592 0.186326739 0.008123812 0.27017812 0.122824965
## 2 -0.0132685069 -0.019710217 0.441228579 -0.20097401 0.178333295
## 3 -0.2153249778 -0.385998139 1.466100254 -0.79385923 0.188906310
## 4 -0.3694358455 -0.500463114 1.058724484 -0.71946679 0.299922970
## 5 0.4182419227 0.300791715 1.397489598 0.03347490 0.783638417
## 6 -0.1845028043 -0.294426158 1.041571820 -0.57969917 0.122824965
## 7 -0.0783375399 -0.080758204 0.389770587 -0.18068516 -0.017267487
## 10 0.5860515341 0.659448638 0.166785954 0.92392989 0.527242798
## 11 0.5209825011 0.499197673 0.737112033 0.54295041 0.632972950
## 12 0.1168695592 0.193957738 -0.051910512 0.15971662 -0.062202802
## 13 -0.3043668125 -0.332581150 0.376906089 -0.46247471 -0.170576208
## 14 -0.3523124158 -0.439415128 0.737112033 -0.46022040 -0.175862716
## 15 -0.3899839612 -0.408891134 0.218243946 -0.37004774 -0.289522630
## 16 -0.4036827050 -0.416522132 0.153921456 -0.36328479 -0.400539290
## 17 -0.1125843994 -0.241009170 1.221674792 -0.65860024 0.178333295
## 18 -0.3180655563 -0.584404097 2.036426333 -1.18160165 0.310495985
## 19 0.2641310550 0.117647754 1.500405582 -0.26184055 0.656762234
## 20 -0.0749128539 -0.294426158 1.907781353 -0.98773044 0.529886051
## 21 -0.7530006718 -0.782810054 -0.094792172 -0.94038980 -0.572350787
## 22 -0.2598458952 -0.149437189 -0.532185105 0.03347490 -0.360890483
## 23 -0.2769693249 -0.256271167 0.059581804 -0.27762077 -0.257803584
## 24 0.3292000880 0.232112729 1.200233962 -0.05669776 0.638259458
## 25 -0.9721805725 -1.042263999 -0.189131824 -1.22668798 -0.871038468
## 26 0.0312524105 0.125278752 -0.219148986 0.32879035 -0.054273041
## 27 0.4353653524 0.430518687 0.604178887 0.42798027 0.410939630
## 28 -0.6502600933 -0.637821085 -0.287759642 -0.55941032 -0.633145625
## 29 -0.7461512999 -0.706500071 -0.617948425 -0.55941032 -0.818173392
## 30 -0.2769693249 -0.317319154 0.479822073 -0.23028012 -0.117711132
## 31 -0.5029985975 -0.439415128 -0.446421785 -0.28663803 -0.530058726
## 32 -0.6023144900 -0.592035095 -0.197708156 -0.42640565 -0.767951569
## 33 0.1956373360 0.262636723 0.068158136 0.25665223 0.278776940
## 34 -0.2838186968 -0.141806191 -0.768034235 0.16647957 -0.210225015
## 35 -0.3351889860 -0.324950152 0.085310800 -0.13109020 -0.305382152
## 36 0.0449511543 0.064230765 0.304007266 0.15520799 0.165117026
## 39 0.4387900383 0.514459669 0.111039796 0.41220006 0.524599544
## 40 0.7401624018 0.598400651 1.590457069 0.42572596 1.103472128
## 41 -0.0406659945 -0.057865209 0.492686571 0.02896627 0.059386873
## 42 -0.2187496638 -0.324950152 1.011554658 -0.55490169 0.085819411
## 43 -0.4721764240 -0.569142100 0.698518539 -0.66536319 -0.289522630
## 44 -0.4858751678 -0.569142100 0.617043385 -0.65860024 -0.284236122
## 45 -0.6023144900 -0.798072051 1.290285448 -1.13876964 -0.170576208
## 46 0.1990620219 0.201588736 0.479822073 0.52717020 0.344858285
## 47 0.0654992700 -0.042603212 1.191657630 -0.14461610 0.519313036
## 48 -0.3831345893 -0.424153131 0.368329757 -0.60224233 -0.292165883
## 49 0.1511164187 0.125278752 0.655636879 0.13041051 0.336928523
## 50 0.0244030386 -0.027341215 0.749976531 -0.16490495 0.294636462
## 51 -0.0440906804 -0.057865209 0.475533907 -0.22126286 0.067316635
## 52 -0.0201178788 0.056599767 -0.137673832 0.07856123 -0.019910741
## 53 -0.1673793746 -0.149437189 0.183938618 -0.13109020 0.017094812
## 54 0.2949532285 0.239743728 0.921503171 0.06954396 0.445301930
## 55 -0.1468312589 0.010813777 -0.729440741 0.16197094 -0.403182543
## 56 -0.2016262340 -0.241009170 0.526991899 -0.31368983 -0.175862716
## 57 -0.1365572010 0.003182778 -0.647965587 0.22058316 -0.403182543
## 58 0.0381017824 0.132909751 -0.214860820 0.13266482 -0.141500416
## 59 -0.1571053167 -0.187592181 0.471245741 -0.57519053 0.294636462
## 60 0.0004302369 -0.126544194 1.277420950 -0.58420780 0.387150346
## 61 0.1579657906 0.132909751 0.638484215 0.04249217 0.405653122
## 62 -0.9619065146 -0.859120038 -1.355512978 -1.09142900 -0.617286102
## 65 -1.2632788781 -1.500123902 0.565585393 -1.67078832 -1.021703935
## 66 -0.8762893659 -1.072787993 0.921503171 -1.27853726 -0.590853564
## 67 -0.5817663743 -0.576773098 -0.120521168 -0.55941032 -0.516842457
## 68 -0.7324525561 -0.782810054 0.033852808 -0.85923440 -0.633145625
## 69 -0.6982056966 -0.836227043 0.732823867 -1.13651532 -0.387323021
## 70 -0.1982015481 -0.172330184 0.076734468 -0.02964596 -0.199652000
## 71 -0.3112161844 -0.233378171 -0.356370299 -0.07698661 -0.284236122
## 74 -0.7495759858 -0.645452084 -1.072494022 -0.52108694 -1.013774174
## 75 0.9285201290 1.056260554 -0.150538330 1.23502555 0.780995163
## 76 0.6579699391 0.819699604 -0.364946631 0.79994248 0.577464620
## 77 0.8018067489 0.865485595 0.235396610 0.75485616 0.868222539
## 78 1.4353736494 1.269928508 1.599033401 1.15161585 1.756355819
## 79 0.6511205672 0.697603630 0.334024429 0.84277450 0.582751128
## 80 0.6339971374 0.781544612 -0.300624141 0.63988602 0.455874945
## 81 0.8223548646 1.002843565 -0.467862615 0.94872737 0.363361061
## 82 1.9833234012 2.010135351 0.235396610 2.10970033 1.449738377
## 83 1.3771539883 1.445441471 0.179650452 1.80762193 0.987168961
## 84 0.7538611456 0.728127624 0.788570025 0.46630365 0.794211432
## 85 0.5518046747 0.567876658 0.492686571 0.52266156 0.532529305
## 86 1.3018108974 1.216511520 1.153064136 0.81797702 1.563398291
## 87 1.8086644178 1.750681406 0.797146357 1.44693130 1.581901068
## 88 1.5929092030 1.636216430 0.304007266 1.67010862 1.338721717
## 89 1.5723610873 1.613323435 0.308295432 1.62953093 1.415376078
## 90 1.1477000297 1.140201536 0.694230373 1.19444786 1.018888006
## 91 1.3566058726 1.269928508 1.118758808 0.99381370 1.317575687
## 92 1.3908527321 1.575168443 -0.506456109 2.04207083 1.069109829
## 93 2.1442836408 1.994873354 1.204522128 2.09617443 2.028610962
## 94 2.0415430623 1.872777380 1.384625100 1.81889351 2.025967708
## 95 1.7744175583 1.826991390 0.162497788 2.11420896 1.373084017
## 96 1.3155096412 1.224142518 1.183081298 1.19219354 1.402159809
## 97 1.3326330709 1.292821503 0.848604349 1.41762518 1.129904666
## 98 1.2572899801 1.109677543 1.534710910 0.88786082 1.571328053
## 99 1.1785222032 1.468334466 -1.098223018 2.30582586 0.580107874
## 100 0.6682439969 0.804437608 -0.257742480 1.11780110 0.521956290
## 101 1.5038673684 1.521751455 0.458381243 1.57317302 1.439165362
## 102 1.3908527321 1.506489458 -0.090504006 1.81663919 0.757205879
## 103 1.1134531702 1.269928508 -0.304912307 1.41537087 0.651475727
## 104 1.3018108974 1.330976495 0.436940413 1.29814641 1.106115382
## 105 0.5107084433 0.499197673 0.677077709 0.16873389 0.685838026
## 106 1.0518088232 0.964688573 1.217386626 0.55647631 1.132547920
## 107 1.5552376576 1.453072469 1.187369464 1.05918887 1.655912175
## 108 1.4593464510 1.552275448 0.038140974 1.63629388 1.098185621
## 109 1.3805786742 1.392024482 0.518415567 1.36352159 1.293786403
## 110 1.3394824428 1.292821503 0.895774175 0.88786082 1.375727271
## 113 0.9285201290 0.964688573 0.394058753 0.87884356 0.812714209
## 114 1.7196225831 1.773574401 0.188226784 2.32611470 1.314932433
## 115 1.2435912363 1.239404515 0.672789543 1.14936153 1.079682844
## 116 1.2093443768 1.163094531 0.912926839 1.04566297 1.330791956
## 117 1.5278401700 1.620954434 0.033852808 1.48750899 1.388943540
## 118 1.4422230213 1.308083500 1.401777764 1.21699102 1.682344713
## 119 1.4456477072 1.537013451 0.059581804 1.38831907 1.246207834
## 120 2.0723652358 2.025397347 0.647060547 2.07363126 1.917594302
## 121 1.4182502197 1.414917477 0.625619717 1.74224675 1.198629265
## 122 1.3840033602 1.224142518 1.581880736 0.91942125 1.669128444
## 123 1.4490723932 1.414917477 0.779993693 1.35675864 1.452381631
## 124 1.3600305585 1.247035513 1.285997282 1.31618095 1.330791956
## 125 1.7504447567 1.758312404 0.441228579 1.91582911 1.563398291
## 126 1.8223631616 1.765943403 0.810010855 1.51456079 1.840939941
## 127 1.1031791124 1.163094531 0.273990104 0.93745579 0.786281671
## 128 0.4285159805 0.598400651 -0.515032441 0.26792381 0.321069000
## 129 1.2024950049 1.048629556 1.581880736 0.75936479 1.336078464
## 130 0.3668716334 0.224481731 1.526134578 -0.63154845 0.836503493
## 131 1.3120849552 1.208880521 1.247403788 1.05468024 1.595117337
## 132 1.2778380958 1.384393484 -0.043334180 1.44693130 0.868222539
## 133 1.0483841372 0.957057575 1.221674792 0.75711047 1.114045143
## 134 1.7949656740 1.857515383 0.115327962 1.96091544 1.341364971
## 135 0.9011226414 0.812068606 1.213098460 0.33329898 1.121974905
## 136 1.1579740876 0.987581569 1.714813883 0.75711047 1.293786403
## 137 1.3771539883 1.315714499 1.002978326 1.12907268 1.478814169
## 138 0.1579657906 0.232112729 -0.009028852 0.54295041 0.006521797
## 139 0.4250912946 0.560245660 -0.274895144 0.45503207 0.342215031
## 140 0.2196101376 0.224481731 0.492686571 0.29948424 0.376577330
## 143 0.8360536084 0.888378590 0.329736262 1.13132700 0.815357463
## 144 0.2230348236 0.422887689 -0.776610567 0.62410580 -0.091278594
## 145 0.2333088814 0.392363695 -0.549337769 0.42572596 0.054100366
## 146 0.4490640962 0.445780684 0.608467053 0.51589861 0.545745574
## 147 -0.6331366636 -0.515725111 -0.978154370 -0.38582796 -0.717729747
## 148 -0.5475195148 -0.500463114 -0.407828291 -0.23028012 -0.508912696
## 149 -0.5406701430 -0.492832116 -0.377811129 -0.57293622 -0.506269442
## 150 -0.9242349692 -0.973585014 -0.240589816 -0.94489843 -0.789097600
## 151 -1.0612224071 -0.912537027 -1.861516567 -0.74200995 -1.291315824
## 152 -1.2701282500 -1.118573983 -2.320350330 -0.82091103 -1.529208667
## 153 -1.1947851591 -1.118573983 -1.599938441 -1.05310562 -1.444624545
## 154 -0.8317684486 -0.866751036 -0.214860820 -0.84796282 -0.789097600
## 155 -0.7598500437 -0.675976077 -0.930984544 -0.57969917 -0.937119813
## 156 -1.4139650598 -1.271193950 -2.577640290 -0.73524700 -1.632295565
## 157 -1.0577977212 -1.042263999 -0.909543713 -0.85698009 -1.124790834
## 158 -0.9961533741 -0.820965046 -1.968720717 -0.53686716 -1.293959077
## 159 -0.9105362254 -0.759917059 -1.608514773 -0.53010421 -1.143293610
## 160 -1.2804023079 -1.187252968 -1.895821895 -0.95391569 -1.513349144
## 161 -1.2187579608 -1.179621970 -1.398394638 -1.05535993 -1.349467407
## 162 -1.2769776219 -1.179621970 -1.951568053 -0.88628620 -1.560927712
## 163 -1.2256073327 -1.316979941 -0.480727113 -1.33038654 -1.101001549
## 164 -0.9550571427 -0.660714080 -2.689132606 -0.56166464 -1.375899946
## 165 -1.0851952088 -0.820965046 -2.684844440 -0.44894882 -1.552997951
## 166 -1.1742370434 -1.049894997 -1.908686393 -0.76455311 -1.508062636
## 167 -0.8146450188 -0.706500071 -1.214003500 -0.43316860 -1.021703935
## 168 -0.9927286882 -0.965954015 -0.879526551 -0.66085456 -1.204088448
## 169 -0.9824546303 -0.904906028 -1.252596994 -0.84796282 -1.106288057
## 170 -0.8112203329 -0.782810054 -0.643677421 -0.69917794 -0.786454346
## 171 -1.2941010516 -1.378027928 -0.643677421 -1.42506783 -1.246380509
## 172 -0.9653312006 -1.103311986 0.364041591 -1.21316208 -0.857822199
## 173 -0.8488918783 -0.767548058 -1.055341358 -0.73073837 -0.974125366
## 174 -0.9482077708 -0.874382035 -1.136816512 -0.50981536 -1.132720595
## 175 -1.2221826467 -1.126204981 -1.788617745 -1.05310562 -1.579430489
## 180 -1.1536889278 -1.141466978 -1.085358520 -1.07339446 -1.111574565
## 183 -1.2050592170 -1.156728975 -1.428411800 -1.14327827 -1.328321377
## 184 -1.4002663161 -1.248300955 -2.611945618 -0.82316534 -1.650798342
## 185 -1.4105403739 -1.545909892 -0.506456109 -1.49269732 -1.175012656
## 186 -1.2530048203 -1.210145963 -1.514175120 -1.03056245 -1.468413829
## 187 -1.4310884896 -1.423813918 -1.625667437 -1.12298943 -1.648155088
## 188 -1.1776617294 -1.179621970 -1.008171532 -1.04408835 -1.341537646
## 189 -0.9276596551 -0.859120038 -1.093934852 -0.64507434 -0.984698382
## 190 -1.2016345310 -1.255931954 -0.635101089 -1.24697683 -1.296602331
## 191 -0.8420425064 -0.904906028 -0.009028852 -0.91784663 -0.656934909
## 192 -0.9345090270 -0.943061020 -0.553625935 -0.90882937 -0.942406321
## 193 -1.1194420683 -1.164359973 -0.570778599 -1.20639913 -1.098358296
## 194 -0.6947810106 -0.630190087 -0.716576243 -0.33397868 -0.633145625
## 195 -1.1502642418 -0.981216012 -2.187417184 -0.63154845 -1.539781682
## 196 -1.0646470931 -0.874382035 -2.187417184 -0.51883262 -1.452554306
## 197 -1.3728688285 -1.370396929 -1.441276298 -1.25148546 -1.560927712
## 198 -1.2632788781 -1.355134932 -0.489303445 -1.24923115 -1.175012656
## 199 -1.4824587788 -1.668005866 -0.257742480 -1.67755127 -1.264883286
## 200 -1.3660194566 -1.370396929 -1.364089310 -1.34616675 -1.449911052
## 201 -1.2495801343 -1.324610939 -0.622236591 -1.24472251 -1.219947971
## 202 -1.0440989774 -1.202514965 0.372617923 -1.15229554 -0.826103153
## 203 -1.4036910020 -1.347503934 -1.938703555 -1.04408835 -1.679874134
## 204 -0.9619065146 -1.011740006 -0.296335975 -0.91784663 -0.767951569
## 205 -0.7256031842 -0.859120038 0.651348713 -1.08917468 -0.368820244
## 206 -0.7290278701 -0.813334048 0.334024429 -0.94489843 -0.559134518
## 207 -0.5303960851 -0.622559088 0.604178887 -0.72848405 -0.363533736
## 208 -0.7872475313 -0.706500071 -0.973866204 -0.52559557 -0.937119813
## 209 -0.7393019280 -0.927799023 1.097317978 -1.28530021 -0.292165883
## 210 -0.8694399940 -0.882013033 -0.424980955 -0.95617001 -0.730946016
## 213 -1.2804023079 -1.431444916 -0.120521168 -1.42957646 -1.204088448
## 216 -0.8728646800 -0.859120038 -0.605083927 -0.98998476 -0.807600376
## 217 -0.9345090270 -1.065156994 0.321159930 -1.14102396 -0.752092046
## 218 -1.2632788781 -1.309348942 -0.845221223 -1.13426101 -1.243737255
## 219 -0.5886157462 -0.714131069 0.749976531 -0.91784663 -0.088635340
## 220 -1.0543730352 -1.057525996 -0.802339563 -1.05535993 -1.135363849
## 221 -0.8968374816 -0.958323017 -0.103368504 -0.90206642 -0.770594823
## asymetry.coefficient length.of.kernel.groove cluster
## 1 -1.004836349 -0.40723767 1
## 2 -1.822590479 -0.94304128 1
## 3 -0.679909936 -1.20891353 1
## 4 -0.979005379 -1.24950471 1
## 5 -1.593510561 -0.49856783 1
## 6 -0.841013618 -0.94304128 1
## 7 -0.076960714 -0.40926723 1
## 10 -1.127873338 0.92618268 2
## 11 -1.176136466 0.22801434 2
## 12 0.573571873 -0.21645911 3
## 13 -1.347436583 -0.85171112 1
## 14 0.194944234 -1.38548517 1
## 15 -0.382853781 -1.11352425 1
## 16 -0.521525304 -1.20891353 1
## 17 0.330216945 -1.29821413 1
## 18 1.043287671 -1.29821413 1
## 19 -1.427648543 -0.76038096 1
## 20 -1.313448464 -1.56611593 1
## 21 0.273796668 -1.02828276 3
## 22 -0.426358572 -0.49653827 1
## 23 -0.687387322 -0.40926723 1
## 24 -1.994502383 -0.66905080 1
## 25 -1.552724819 -0.93289348 1
## 26 -1.297134168 -0.85171112 1
## 27 -1.900763152 -0.23066602 1
## 28 -0.221750099 -1.20891353 1
## 29 -0.812463598 -1.11961292 1
## 30 -0.642523006 -0.77661743 1
## 31 -0.114347645 -0.65687344 3
## 32 -1.933323769 -0.74008537 1
## 33 -0.195239367 -0.39100120 2
## 34 0.150079917 -0.24690250 3
## 35 -1.070773299 -0.82938597 1
## 36 -1.067374487 -0.12309939 1
## 39 -0.595619402 0.21583698 2
## 40 -0.505211007 0.12856594 1
## 41 -0.399168077 -0.22660691 1
## 42 2.029622869 -0.85171112 1
## 43 -0.756043321 -0.49247915 1
## 44 -0.985803002 -0.49653827 1
## 45 -0.841693380 -1.29415501 1
## 46 0.687771951 0.21786654 2
## 47 -0.388291880 -0.48842003 1
## 48 -1.454159275 -0.93289348 1
## 49 -1.585353412 -0.58583887 1
## 50 -0.503851482 -0.49856783 1
## 51 -0.676511124 -0.62845961 1
## 52 -1.067374487 -0.14136542 1
## 53 0.187466847 -0.56148416 1
## 54 1.287322361 -0.57772064 1
## 55 0.283313342 -0.05003526 3
## 56 -0.252339406 -0.39911943 1
## 57 -1.507860502 0.13465462 1
## 58 -1.200607911 0.03723578 1
## 59 -0.609894412 -0.76444008 1
## 60 -1.738299945 -0.67513947 1
## 61 -1.155743595 -0.40317855 1
## 62 -1.493585492 -1.82995862 1
## 65 -0.972207755 -1.45651974 1
## 66 -0.325753742 -1.65541653 1
## 67 0.311183599 -0.67513947 3
## 68 -1.715188025 -1.29618457 1
## 69 -0.915787478 -1.65135742 1
## 70 -1.622060580 -0.54930681 1
## 71 -1.007555398 -0.58583887 1
## 74 -0.112988120 -0.71776022 3
## 75 0.256122847 1.29759200 2
## 76 0.663300506 0.92618268 2
## 77 0.570852824 0.75164059 2
## 78 -0.518806254 1.33615362 2
## 79 0.207179956 0.85311855 2
## 80 0.829842287 0.75975883 2
## 81 0.084822730 1.01751284 2
## 82 0.511033735 2.09114962 2
## 83 0.927728068 1.91051886 2
## 84 -0.571827719 0.66031043 2
## 85 1.245856857 0.93227136 2
## 86 1.104466284 0.93024180 2
## 87 1.001822166 1.55534601 2
## 88 -1.513978364 1.72988810 2
## 89 -0.501132433 1.55128689 2
## 90 -0.853929103 1.57564160 2
## 91 -1.393660424 1.39704040 2
## 92 -0.005585665 2.18653890 2
## 93 1.414437925 1.64464661 2
## 94 0.895099474 1.82730693 2
## 95 -1.185653139 2.08709050 2
## 96 -0.393729978 1.28338509 2
## 97 -0.314197781 1.28338509 2
## 98 1.564665408 0.92618268 2
## 99 0.838679198 2.08506094 2
## 100 -0.002186854 1.10884300 2
## 101 -0.151054813 1.65885353 2
## 102 -1.057178051 2.09520874 2
## 103 -0.575226531 1.72988810 2
## 104 -1.027268507 1.37268569 2
## 105 0.351969341 0.40052687 2
## 106 -1.108839991 0.84500032 2
## 107 0.413827717 1.19408449 2
## 108 -0.232626297 1.64058749 2
## 109 -0.225148911 1.47619320 2
## 110 -0.779155242 0.93024180 2
## 113 0.032481027 1.03171976 2
## 114 -0.304001346 2.29207598 2
## 115 -1.333161573 0.96068519 2
## 116 -0.995319676 0.75772927 2
## 117 -0.014422576 1.10478388 2
## 118 -1.080969734 1.02157196 2
## 119 2.027583582 1.28338509 2
## 120 0.664660031 1.81715914 2
## 121 -0.986482765 1.50663659 2
## 122 0.431501538 0.66842867 2
## 123 -0.418201424 1.55128689 2
## 124 -0.040933309 1.10681344 2
## 125 -0.432476434 1.82527738 2
## 126 1.496689171 1.55737557 2
## 127 -0.054528556 1.19814360 2
## 128 0.398872944 0.57303939 2
## 129 -0.486177661 0.98301034 2
## 130 -0.246901307 -0.56148416 1
## 131 0.332256232 1.15958198 2
## 132 0.470247993 1.38283348 2
## 133 -0.980364903 1.01142416 2
## 134 -1.216242446 1.55128689 2
## 135 1.133016304 0.48779791 2
## 136 -0.586102729 1.09869521 2
## 137 -0.537839601 1.07231094 2
## 138 0.518511121 0.75975883 2
## 139 0.385277697 0.75975883 2
## 140 0.865189930 0.86529591 2
## 143 -0.117746456 1.11696124 2
## 144 -0.720015916 0.93024180 2
## 145 -0.662236114 0.67248779 2
## 146 0.047435799 1.01751284 2
## 147 1.090871037 -0.05206482 3
## 148 2.267539698 0.03926534 3
## 149 1.560586834 -0.23066602 3
## 150 1.203031828 -0.40520811 3
## 151 0.524628983 -0.49247915 3
## 152 1.678865486 -0.29561192 3
## 153 -1.004836349 -0.58583887 3
## 154 0.490640864 -0.84968156 3
## 155 -0.298563247 -0.21239999 3
## 156 1.198273491 -0.46000621 3
## 157 1.016776938 -0.23066602 3
## 158 2.238309916 -0.30575971 3
## 159 0.718361258 -0.12309939 3
## 160 -0.249620356 -0.85171112 3
## 161 0.237089500 -0.31996663 3
## 162 1.436870083 -0.40926723 3
## 163 -0.239423921 -0.84765200 3
## 164 0.765264862 -0.40723767 3
## 165 0.461411082 -0.22457735 3
## 166 1.147971076 -0.22457735 3
## 167 -0.419560949 0.14277286 3
## 168 0.388676509 -0.22863647 3
## 169 0.876066128 -0.76038096 3
## 170 0.489281340 -0.49653827 3
## 171 1.827733445 -0.75429228 3
## 172 -1.018431596 -0.74008537 1
## 173 0.832561336 -0.30575971 3
## 174 -0.041613071 -0.16774969 3
## 175 0.433540825 -0.58583887 3
## 180 2.050015740 -0.94304128 3
## 183 1.283923550 -0.67310992 3
## 184 1.007940028 -0.47827224 3
## 185 0.729917218 -0.72587845 3
## 186 1.111943670 -0.66702124 3
## 187 0.681654090 -0.92883437 3
## 188 1.479695112 -0.84968156 3
## 189 -1.385503276 -0.49247915 3
## 190 0.854993494 -1.20891353 3
## 191 0.875386365 -0.55539549 3
## 192 0.787017257 -0.53307033 3
## 193 1.026293612 -0.57975020 3
## 194 1.689741684 -0.21239999 3
## 195 0.246606174 -0.48436092 3
## 196 0.814887515 -0.13933586 3
## 197 0.326138371 -0.94304128 3
## 198 2.599943497 -0.94101172 3
## 199 0.867229217 -1.27182986 3
## 200 1.154768699 -0.76241052 3
## 201 0.194264471 -0.85171112 3
## 202 -0.069483328 -0.58583887 1
## 203 0.784298208 -0.67310992 3
## 204 0.294189540 -0.82938597 3
## 205 0.797893455 -1.02828276 1
## 206 1.212548501 -0.93898216 1
## 207 0.659901694 -0.66905080 1
## 208 -0.267294178 -0.38491252 3
## 209 -0.592220590 -1.19876573 1
## 210 1.205071115 -0.76241052 3
## 213 0.239128788 -1.20282485 3
## 216 0.149400155 -0.85171112 3
## 217 -0.046371408 -1.11758336 1
## 218 0.425383677 -0.84765200 3
## 219 3.137635531 -0.74008537 1
## 220 -0.068803566 -0.76444008 3
## 221 1.317231906 -0.72587845 3
count(seeds_df_cl, cluster)
## cluster n
## 1 1 63
## 2 2 72
## 3 3 64
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.2
ggplot(seeds_df_cl, aes(x=area, y=perimeter, color=factor(cluster))) + geom_point()
library(clValid)
## Warning: package 'clValid' was built under R version 4.3.2
## Loading required package: cluster
?dunn
## starting httpd help server ...
## done
dunn(dist_mat, cut_avg)
## [1] 0.1068389
set.seed(1234)
data(iris)
ir3<- kmeans(iris[,-5], center=3, iter.max=200)
ir3
## K-means clustering with 3 clusters of sizes 50, 62, 38
##
## Cluster means:
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## 1 5.006000 3.428000 1.462000 0.246000
## 2 5.901613 2.748387 4.393548 1.433871
## 3 6.850000 3.073684 5.742105 2.071053
##
## Clustering vector:
## [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
## [38] 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
## [75] 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 3 3 3 3 2 3 3 3 3
## [112] 3 3 2 2 3 3 3 3 2 3 2 3 2 3 3 2 2 3 3 3 3 3 2 3 3 3 3 2 3 3 3 2 3 3 3 2 3
## [149] 3 2
##
## Within cluster sum of squares by cluster:
## [1] 15.15100 39.82097 23.87947
## (between_SS / total_SS = 88.4 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault"
table(ir3$cluster, iris$Species)
##
## setosa versicolor virginica
## 1 50 0 0
## 2 0 48 14
## 3 0 2 36
cm<-table(ir3$cluster, iris$Species)
1-sum(diag(cm))/sum(cm)
## [1] 0.1066667
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.