R Markdown

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:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

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.

library(readr)
seeds_dataset <- read_delim("C:/Users/dnred/Downloads/seeds_dataset.txt", 
     delim = "\t", escape_double = FALSE, 
     col_names = FALSE, trim_ws = TRUE)
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
## Rows: 210 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: "\t"
## chr (1): X8
## dbl (7): X1, X2, X3, X4, X5, X6, X7
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
sd <- seeds_dataset
str(sd)
## spc_tbl_ [210 × 8] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ X1: num [1:210] 15.3 14.9 14.3 13.8 16.1 ...
##  $ X2: num [1:210] 14.8 14.6 14.1 13.9 15 ...
##  $ X3: num [1:210] 0.871 0.881 0.905 0.895 0.903 ...
##  $ X4: num [1:210] 5.76 5.55 5.29 5.32 5.66 ...
##  $ X5: num [1:210] 3.31 3.33 3.34 3.38 3.56 ...
##  $ X6: num [1:210] 2.22 1.02 2.7 2.26 1.35 ...
##  $ X7: num [1:210] 5.22 4.96 4.83 4.8 5.17 ...
##  $ X8: chr [1:210] "1" "1" "1" "1" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   X1 = col_double(),
##   ..   X2 = col_double(),
##   ..   X3 = col_double(),
##   ..   X4 = col_double(),
##   ..   X5 = col_double(),
##   ..   X6 = col_double(),
##   ..   X7 = col_double(),
##   ..   X8 = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
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.   :10.59   Min.   :12.41   Min.   :0.8081   Min.   :0.8189  
##  1st Qu.:12.27   1st Qu.:13.45   1st Qu.:0.8577   1st Qu.:5.2447  
##  Median :14.36   Median :14.32   Median :0.8735   Median :5.5180  
##  Mean   :14.85   Mean   :14.56   Mean   :0.8713   Mean   :5.5639  
##  3rd Qu.:17.30   3rd Qu.:15.71   3rd Qu.:0.8877   3rd Qu.:5.9798  
##  Max.   :21.18   Max.   :17.25   Max.   :0.9183   Max.   :6.6750  
##                                  NA's   :3                        
##  width_of_kernel asymetry_coefficient length_of_kernel_groove
##  Min.   :2.630   Min.   :0.7651       Min.   :3.485          
##  1st Qu.:2.956   1st Qu.:2.6002       1st Qu.:5.045          
##  Median :3.245   Median :3.5990       Median :5.226          
##  Mean   :3.281   Mean   :3.6935       Mean   :5.408          
##  3rd Qu.:3.566   3rd Qu.:4.7687       3rd Qu.:5.879          
##  Max.   :5.325   Max.   :8.4560       Max.   :6.735          
##  NA's   :1                            NA's   :4              
##  type_of_seed      
##  Length:210        
##  Class :character  
##  Mode  :character  
##                    
##                    
##                    
## 
any(is.na(sd))
## [1] TRUE
sd<-na.omit(sd)
str(sd)
## tibble [203 × 8] (S3: tbl_df/tbl/data.frame)
##  $ area                   : num [1:203] 15.3 14.9 14.3 13.8 16.1 ...
##  $ perimeter              : num [1:203] 14.8 14.6 14.1 13.9 15 ...
##  $ compactness            : num [1:203] 0.871 0.881 0.905 0.895 0.903 ...
##  $ length_of_kernel       : num [1:203] 5.76 5.55 5.29 5.32 5.66 ...
##  $ width_of_kernel        : num [1:203] 3.31 3.33 3.34 3.38 3.56 ...
##  $ asymetry_coefficient   : num [1:203] 2.22 1.02 2.7 2.26 1.35 ...
##  $ length_of_kernel_groove: num [1:203] 5.22 4.96 4.83 4.8 5.17 ...
##  $ type_of_seed           : chr [1:203] "1" "1" "1" "1" ...
##  - attr(*, "na.action")= 'omit' Named int [1:7] 8 36 61 136 170 171 202
##   ..- attr(*, "names")= chr [1:7] "8" "36" "61" "136" ...
sd<-sd[,-8]
View(sd)
df_sc<-as.data.frame(scale(sd))
str(df_sc)
## 'data.frame':    203 obs. of  7 variables:
##  $ area                   : num  0.12107 -0.00908 -0.21114 -0.36526 0.42245 ...
##  $ perimeter              : num  0.1918 -0.0143 -0.3807 -0.4953 0.3064 ...
##  $ compactness            : num  0.003 0.436 1.46 1.053 1.391 ...
##  $ length_of_kernel       : num  0.2766 -0.1945 -0.7875 -0.7131 0.0399 ...
##  $ width_of_kernel        : num  0.126 0.182 0.192 0.303 0.787 ...
##  $ asymetry_coefficient   : num  -0.99 -1.79 -0.672 -0.965 -1.566 ...
##  $ length_of_kernel_groove: num  -0.405 -0.941 -1.207 -1.248 -0.497 ...
dist_mat<-dist(df_sc, method='euclidean')
hclust_avg<-hclust(dist_mat, method='average')
plot(hclust_avg)

library(dendextend)
## 
## ---------------------
## 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)

hclust_avg
## 
## Call:
## hclust(d = dist_mat, method = "average")
## 
## Cluster method   : average 
## Distance         : euclidean 
## Number of objects: 203
cut_avg<-cutree(hclust_avg, k=3)

library(dplyr)
## 
## 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.121066845  0.19183791  0.002997608       0.27664105     0.126036292
## 2   -0.009076639 -0.01429100  0.435814160      -0.19453719     0.181530271
## 3   -0.211141523 -0.38074240  1.460003823      -0.78745525     0.192100553
## 4   -0.365258806 -0.49525846  1.052899145      -0.71305869     0.303088513
## 5    0.422451756  0.30635397  1.391438825       0.03992471     0.786678907
## 6   -0.180318066 -0.28912955  1.035757896      -0.57328333     0.126036292
## 7   -0.074148381 -0.07536624  0.384390411      -0.17424721    -0.014019943
## 8    0.590268354  0.66517097  0.161554166       0.93042904     0.530349572
## 9    0.525196612  0.50484848  0.731500716       0.54942845     0.636052391
## 10   0.121066845  0.19947231 -0.056996766       0.16617343    -0.058943641
## 11  -0.300187064 -0.32730157  0.371534474      -0.45605238    -0.167289030
## 12  -0.348134664 -0.43418323  0.731500716      -0.45379794    -0.172574171
## 13  -0.385807778 -0.40364561  0.212977915      -0.36362029    -0.286204700
## 14  -0.399507092 -0.41128002  0.148698229      -0.35685696    -0.397192660
## 15  -0.108396667 -0.23568872  1.215741017      -0.65218877     0.181530271
## 16  -0.313886378 -0.57923691  2.029950372      -1.17521916     0.313658795
## 17   0.268334472  0.12312827  1.494286323      -0.25540710     0.659835525
## 18  -0.070723553 -0.28912955  1.901391000      -0.98133721     0.532992143
## 19  -0.748839602 -0.77773142 -0.099849890      -0.93399394    -0.568959740
## 20  -0.255664293 -0.14407587 -0.536951755       0.03992471    -0.357554103
## 21  -0.272788436 -0.25095753  0.054421356      -0.27118819    -0.254493855
## 22   0.333406214  0.23764433  1.194314455      -0.05025294     0.641337532
## 23  -0.968028628 -1.03730116 -0.194126763      -1.22030799    -0.867570202
## 24   0.035446132  0.13076268 -0.224123949       0.33525653    -0.051015929
## 25   0.439575898  0.43613884  0.598656031       0.43445194     0.414076472
## 26  -0.646094746 -0.63267774 -0.292688948      -0.55299336    -0.629738861
## 27  -0.741989945 -0.70138738 -0.622658003      -0.55299336    -0.814718793
## 28  -0.272788436 -0.31203276  0.474381972      -0.22384492    -0.114437620
## 29  -0.498827119 -0.43418323 -0.451245507      -0.28020596    -0.526678612
## 30  -0.598147147 -0.58687131 -0.202697387      -0.41998132    -0.764509954
## 31   0.199837901  0.26818195  0.062991981       0.26311440     0.281947949
## 32  -0.279638093 -0.13644147 -0.772643937       0.17293675    -0.206927587
## 33  -0.331010521 -0.31966717  0.080133231      -0.12464950    -0.302060123
## 34   0.049145446  0.06968744  0.298684163       0.16166454     0.168317419
## 35   0.443000727  0.52011729  0.105845105       0.41867085     0.527707002
## 36   0.744385638  0.60409573  1.584277883       0.43219750     1.106429933
## 37  -0.036475267 -0.05246302  0.487237909       0.03541583     0.062614601
## 38  -0.214566351 -0.31966717  1.005760709      -0.54848447     0.089040305
## 39  -0.468003662 -0.56396810  0.692932904      -0.65895210    -0.286204700
## 40  -0.481702976 -0.56396810  0.611511968      -0.65218877    -0.280919559
## 41  -0.598147147 -0.79300023  1.284306015      -1.13238478    -0.167289030
## 42   0.203262730  0.20710672  0.474381972       0.53364736     0.348012211
## 43   0.069694417 -0.03719422  1.185743830      -0.13817615     0.522421861
## 44  -0.378958121 -0.41891442  0.362963849      -0.59582774    -0.288847271
## 45   0.155315130  0.13076268  0.650079780       0.13686569     0.340084499
## 46   0.028596475 -0.02192541  0.744356653      -0.15846612     0.297803372
## 47  -0.039900096 -0.05246302  0.470096659      -0.21482716     0.070542312
## 48  -0.015926296  0.06205304 -0.142703014       0.08501354    -0.016662513
## 49  -0.163193923 -0.14407587  0.178695416      -0.12464950     0.020333473
## 50   0.299157929  0.24527874  0.915769149       0.07599577     0.448429888
## 51  -0.142644952  0.01624661 -0.734076125       0.16842787    -0.399835230
## 52  -0.197442208 -0.23568872  0.521520408      -0.30725925    -0.172574171
## 53  -0.132370466  0.00861221 -0.652655189       0.22704334    -0.399835230
## 54   0.042295789  0.13839708 -0.219838637       0.13912013    -0.138220755
## 55  -0.152919437 -0.18224789  0.465811347      -0.56877445     0.297803372
## 56   0.004622675 -0.12117266  1.271450078      -0.57779221     0.390293338
## 57   0.162164787  0.13839708  0.632938530       0.04894248     0.408791331
## 58  -0.957754142 -0.85407546 -1.359731735      -1.08504151    -0.613883438
## 59  -1.259139053 -1.49536541  0.560088220      -1.66443293    -1.018196718
## 60  -0.872133429 -1.06783878  0.915769149      -1.27216014    -0.587457733
## 61  -0.577598175 -0.57160251 -0.125561764      -0.55299336    -0.513465760
## 62  -0.728290631 -0.77773142  0.028709482      -0.85283405    -0.629738861
## 63  -0.694042345 -0.83117225  0.727215403      -1.13013034    -0.383979808
## 64  -0.194017380 -0.16697909  0.071562606      -0.02319964    -0.196357305
## 65  -0.307036721 -0.22805432 -0.361253946      -0.07054291    -0.280919559
## 66  -0.183742894 -0.15171028  0.071562606      -0.16072057    -0.294132412
## 67  -0.745414773 -0.64031214 -1.076901117      -0.51466785    -1.010269007
## 68   0.932751207  1.06215998 -0.155558951       1.24154194     0.784036337
## 69   0.662189753  0.82549345 -0.369824571       0.80643476     0.580558411
## 70   0.806032551  0.87129988  0.230119165       0.76134594     0.871241162
## 71   1.439625830  1.27592330  1.592848508       1.15812761     1.759144837
## 72   0.655340096  0.70334299  0.328681350       0.84926915     0.585843552
## 73   0.638215953  0.78732143 -0.305544885       0.64636943     0.459000170
## 74   0.826581522  1.00871915 -0.472672069       0.95522789     0.366510204
## 75   1.987598395  2.01646050  0.230119165       2.11626517     1.452606664
## 76   1.381403745  1.45151459  0.174410104       1.81417004     0.990156833
## 77   0.758084952  0.73388060  0.782924464       0.47277745     0.797249189
## 78   0.556020069  0.57355812  0.487237909       0.52913848     0.535634713
## 79   1.306057517  1.22248247  1.147176018       0.82447029     1.566237194
## 80   1.812932140  1.75689076  0.791495089       1.45345942     1.584735187
## 81   1.597167942  1.64237470  0.298684163       1.67664911     1.341618704
## 82   1.576618971  1.61947149  0.302969476       1.63606917     1.418253248
## 83   1.151940233  1.14613843  0.688647592       1.20096200     1.021867678
## 84   1.360854773  1.27592330  1.112893519       1.00031672     1.320478141
## 85   1.395103059  1.58129947 -0.511239880       2.04863193     1.072076517
## 86   2.148565336  2.00119169  1.198599767       2.10273853     2.031329595
## 87   2.045820480  1.87904123  1.378582888       1.82544224     2.028687025
## 88   1.778683854  1.83323480  0.157268854       2.12077406     1.375972120
## 89   1.319756831  1.23011687  1.177173205       1.19870755     1.405040395
## 90   1.336880974  1.29882651  0.842918838       1.42415169     1.132855638
## 91   1.261534746  1.11560081  1.528568822       0.89435797     1.574164905
## 92   1.182763690  1.47441781 -1.102612991       2.31240157     0.583200982
## 93   0.672464239  0.81022465 -0.262691761       1.12431099     0.525064432
## 94   1.508122400  1.52785864  0.452955410       1.57970814     1.442036382
## 95   1.395103059  1.51258983 -0.095564577       1.82318780     0.760253203
## 96   1.117691948  1.27592330 -0.309830197       1.42189724     0.654550384
## 97   1.306057517  1.33699853  0.431528848       1.30466630     1.109072504
## 98   0.514922126  0.50484848  0.671506342       0.17519119     0.688903800
## 99   1.056045034  0.97054713  1.211455704       0.56295510     1.135498208
## 100  1.559494828  1.45914900  1.181458517       1.06569552     1.658727160
## 101  1.463599629  1.55839625  0.032994794       1.64283249     1.101144792
## 102  1.384828573  1.39807377  0.512949783       1.37004509     1.296695006
## 103  1.343730631  1.29882651  0.890057274       0.89435797     1.378614691
## 104  1.350580288  1.20721366  1.485715698       1.15361873     1.431466100
## 105  0.932751207  0.97054713  0.388675724       0.88534021     0.815747182
## 106  1.723886598  1.77979397  0.182980728       2.33269154     1.317835570
## 107  1.247835432  1.24538568  0.667221030       1.15587317     1.082646799
## 108  1.213587147  1.16904164  0.907198524       1.05216887     1.333690993
## 109  1.532096200  1.62710589  0.028709482       1.49403937     1.391827543
## 110  1.446475487  1.31409532  1.395724137       1.22350641     1.685152864
## 111  1.449900315  1.54312744  0.054421356       1.39484395     1.249128738
## 112  2.076643936  2.03172931  0.641509155       2.08019411     1.920341636
## 113  1.422501687  1.42097698  0.620082593       1.74879124     1.201562470
## 114  1.388253402  1.23011687  1.575707258       0.92592015     1.671940012
## 115  1.453325144  1.42097698  0.774353839       1.36328177     1.455249234
## 116  1.364279602  1.25302009  1.280020703       1.32270183     1.333690993
## 117  1.754710054  1.76452517  0.435814160       1.92238322     1.566237194
## 118  1.826631454  1.77215957  0.804351026       1.52109266     1.843707092
## 119  1.107417462  1.16904164  0.268686976       0.94395568     0.789321478
## 120  0.432726241  0.60409573 -0.519810505       0.27438661     0.324229076
## 121  1.206737489  1.05452558  1.575707258       0.76585482     1.338976134
## 122  0.371079328  0.23000993  1.519998197      -0.62513548     0.839530317
## 123  1.316332002  1.21484807  1.241452891       1.06118663     1.597948039
## 124  1.282083717  1.39043936 -0.048426141       1.45345942     0.871241162
## 125  1.052620206  0.96291273  1.215741017       0.76360038     1.117000215
## 126  1.799232825  1.86377242  0.110130418       1.96747205     1.344261275
## 127  0.905352579  0.81785905  1.207170392       0.33976541     1.124927926
## 128  1.162214719  0.99345035  1.708551942       0.76360038     1.296695006
## 129  1.381403745  1.32172972  0.997190084       1.13558320     1.481674939
## 130  0.162164787  0.23764433 -0.014143642       0.54942845     0.009763191
## 131  0.429301413  0.56592371 -0.279833011       0.46150524     0.345369640
## 132  0.223811701  0.23000993  0.487237909       0.30594879     0.379723056
## 133  0.840280837  0.89420309  0.324396038       1.13783764     0.818389753
## 134  0.227236530  0.42850444 -0.781214561       0.63058834    -0.088011916
## 135  0.237511015  0.39796682 -0.554093004       0.43219750     0.057329460
## 136  0.453275213  0.45140765  0.602941344       0.52237516     0.548847566
## 137 -0.628970603 -0.51052727 -0.982624244      -0.37940137    -0.714301115
## 138 -0.543349890 -0.49525846 -0.412677695      -0.22384492    -0.505538049
## 139 -0.536500233 -0.48762406 -0.382680508      -0.56652000    -0.502895478
## 140 -0.920081029 -0.96859152 -0.245550511      -0.93850282    -0.785650518
## 141 -1.057074170 -0.90751629 -1.865398598      -0.73560310    -1.287738906
## 142 -1.265988710 -1.11364520 -2.323927025      -0.81450855    -1.525570247
## 143 -1.190642482 -1.11364520 -1.603994542      -1.04671601    -1.441007992
## 144 -0.827610658 -0.86170986 -0.219838637      -0.84156185    -0.785650518
## 145 -0.755689259 -0.67084976 -0.935485808      -0.57328333    -0.933634464
## 146 -1.409831508 -1.26633328 -2.581045769      -0.72883978    -1.628630495
## 147 -1.053649341 -1.03730116 -0.914059246      -0.85057961    -1.121256966
## 148 -0.992002428 -0.81590344 -1.972531408      -0.53044894    -1.290381476
## 149 -0.906381714 -0.75482821 -1.612565167      -0.52368562    -1.139754960
## 150 -1.276263196 -1.18235484 -1.899681097      -0.94752059    -1.509714824
## 151 -1.214616282 -1.17472043 -1.402584859      -1.04897045    -1.345875456
## 152 -1.272838367 -1.17472043 -1.955390159      -0.87988735    -1.557281093
## 153 -1.221465939 -1.31213971 -0.485528006      -1.32401229    -1.097473832
## 154 -0.950904485 -0.65558095 -2.692463891      -0.55524780    -1.372301160
## 155 -1.081047969 -0.81590344 -2.688178579      -0.44252573    -1.549353381
## 156 -1.170093511 -1.04493556 -1.912537035      -0.75814752    -1.504429684
## 157 -0.810486515 -0.70138738 -1.218316426      -0.42674464    -1.018196718
## 158 -0.988577599 -0.96095712 -0.884062059      -0.65444322    -1.200534080
## 159 -0.978303114 -0.89988188 -1.256884238      -0.84156185    -1.102758973
## 160 -0.807061687 -0.77773142 -0.648369877      -0.69276872    -0.783007947
## 161 -1.289962510 -1.37321494 -0.648369877      -1.41869883    -1.242815208
## 162 -0.961178971 -1.09837639  0.358678537      -1.20678134    -0.854357350
## 163 -0.844734801 -0.76246261 -1.059759867      -0.72433090    -0.970630450
## 164 -0.944054828 -0.86934427 -1.141180803      -0.50339565    -1.129184678
## 165 -1.218041111 -1.12127961 -1.792548287      -1.04671601    -1.575779086
## 166 -1.149544540 -1.13654841 -1.089757054      -1.06700598    -1.108044114
## 167 -1.245439739 -1.23579567 -1.244028300      -1.24510684    -1.324734892
## 168 -1.200916968 -1.15181722 -1.432582046      -1.13689366    -1.324734892
## 169 -1.396132194 -1.24343007 -2.615328268      -0.81676299    -1.647128488
## 170 -1.406406680 -1.54117183 -0.511239880      -1.48633207    -1.171465805
## 171 -1.248864568 -1.20525805 -1.518288294      -1.02417159    -1.464791127
## 172 -1.426955651 -1.41902137 -1.629706416      -1.11660369    -1.644485918
## 173 -1.173518340 -1.17472043 -1.012621431      -1.03769824    -1.337947744
## 174 -0.923505857 -0.85407546 -1.098327679      -0.63866213    -0.981200732
## 175 -1.197492140 -1.25106448 -0.639799252      -1.24059796    -1.293024047
## 176 -0.837885144 -0.89988188 -0.014143642      -0.91144953    -0.653521995
## 177 -0.930355514 -0.93805391 -0.558378317      -0.90243176    -0.938919605
## 178 -1.115296255 -1.15945163 -0.575519566      -1.20001802    -1.094831262
## 179 -0.690617517 -0.62504334 -0.721220188      -0.32754922    -0.629738861
## 180 -1.146119712 -0.97622593 -2.191082341      -0.62513548    -1.536140529
## 181 -1.060498998 -0.86934427 -2.191082341      -0.51241341    -1.448935704
## 182 -1.368733566 -1.36558054 -1.445437983      -1.24510684    -1.557281093
## 183 -1.259139053 -1.35031173 -0.494098631      -1.24285240    -1.171465805
## 184 -1.478328079 -1.66332230 -0.262691761      -1.67119625    -1.261313201
## 185 -1.361883909 -1.36558054 -1.368302360      -1.33979338    -1.446293133
## 186 -1.245439739 -1.31977411 -0.626943315      -1.23834352    -1.216389503
## 187 -1.039950027 -1.19762365  0.367249162      -1.14591143    -0.822646504
## 188 -1.399557023 -1.34267733 -1.942534221      -1.03769824    -1.676196764
## 189 -0.957754142 -1.00676354 -0.301259573      -0.91144953    -0.764509954
## 190 -0.721440974 -0.85407546  0.645794468      -1.08278707    -0.365481814
## 191 -0.724865802 -0.80826903  0.328681350      -0.93850282    -0.555746888
## 192 -0.526225747 -0.61740893  0.598656031      -0.72207646    -0.360196673
## 193 -0.783087887 -0.70138738 -0.978338932      -0.51917674    -0.933634464
## 194 -0.735140288 -0.92278510  1.091466957      -1.27892346    -0.288847271
## 195 -0.865283772 -0.87697867 -0.429818945      -0.94977503    -0.727513968
## 196 -1.276263196 -1.42665577 -0.125561764      -1.42320771    -1.200534080
## 197 -0.755689259 -0.89988188  0.705788841      -1.03093492    -0.457971780
## 198 -0.868708601 -0.85407546 -0.609802065      -0.98359165    -0.804148511
## 199 -0.930355514 -1.06020437  0.315825413      -1.13463922    -0.748654531
## 200 -1.259139053 -1.30450530 -0.849779560      -1.12787589    -1.240172637
## 201 -0.584447832 -0.70902178  0.744356653      -0.91144953    -0.085369345
## 202 -1.050224513 -1.05256997 -0.806926436      -1.04897045    -1.131827248
## 203 -0.892682400 -0.95332271 -0.108420515      -0.89566844    -0.767152525
##     asymetry_coefficient length_of_kernel_groove cluster
## 1           -0.990010499             -0.40539297       1
## 2           -1.789636480             -0.94117151       1
## 3           -0.672287126             -1.20703132       1
## 4           -0.964752156             -1.24762060       1
## 5           -1.565634854             -0.49671885       1
## 6           -0.829819426             -0.94117151       1
## 7           -0.082704212             -0.40742243       1
## 8           -1.110319978              0.92796500       2
## 9           -1.157513199              0.22982932       2
## 10           0.553407229             -0.21462333       3
## 11          -1.325015898             -0.84984562       1
## 12           0.183173088             -1.38359470       3
## 13          -0.381816175             -1.11164650       3
## 14          -0.517413598             -1.20703132       3
## 15           0.315447045             -1.29632774       3
## 16           1.012710265             -1.29632774       3
## 17          -1.403449701             -0.75851973       1
## 18          -1.291781235             -1.56421701       1
## 19           0.260277505             -1.02640900       3
## 20          -0.424356543             -0.49468939       1
## 21          -0.679598751             -0.40742243       1
## 22          -1.957737403             -0.66719385       1
## 23          -1.525753259             -0.93102419       1
## 24          -1.275828597             -0.84984562       1
## 25          -1.866076204             -0.22882958       1
## 26          -0.224283875             -1.20703132       3
## 27          -0.801902309             -1.11773489       3
## 28          -0.635728997             -0.77475545       1
## 29          -0.119262341             -0.65501706       3
## 30          -1.897915011             -0.73822509       1
## 31          -0.198360838             -0.38915725       2
## 32           0.139303334             -0.24506530       3
## 33          -1.054485745             -0.82752152       1
## 34          -1.051162278             -0.12126798       1
## 35          -0.589865162              0.21765253       2
## 36          -0.501460960              0.13038558       1
## 37          -0.397768813             -0.22477066       1
## 38           1.977180172             -0.84984562       3
## 39          -0.746732770             -0.49063046       1
## 40          -0.971399088             -0.49468939       1
## 41          -0.830484119             -1.29226881       1
## 42           0.665075695              0.21968200       2
## 43          -0.387133721             -0.48657153       1
## 44          -1.429372738             -0.93102419       1
## 45          -1.557658535             -0.58398581       1
## 46          -0.500131574             -0.49671885       1
## 47          -0.668963659             -0.62660456       1
## 48          -1.051162278             -0.13953316       1
## 49           0.175861462             -0.55963224       1
## 50           1.251335142             -0.57586796       3
## 51           0.269583211             -0.04820727       3
## 52          -0.254195071             -0.39727511       1
## 53          -1.481883505              0.13647397       1
## 54          -1.181442156              0.03905969       1
## 55          -0.603823721             -0.76257866       1
## 56          -1.707214517             -0.67328224       1
## 57          -1.137572401             -0.40133404       1
## 58          -1.467924947             -1.82804735       1
## 59          -0.958105223             -1.45462595       1
## 60          -0.325981942             -1.65351343       1
## 61           0.296835634             -0.67328224       3
## 62          -1.684614946             -1.29429828       1
## 63          -0.902935684             -1.64945451       1
## 64          -1.593551971             -0.54745546       1
## 65          -0.992669272             -0.58398581       1
## 66          -1.493183290             -0.24303583       1
## 67          -0.117932954             -0.71590099       3
## 68           0.242995481              1.29935694       2
## 69           0.641146738              0.92796500       2
## 70           0.550748456              0.75343108       2
## 71          -0.514754825              1.33791676       2
## 72           0.195137567              0.85490429       2
## 73           0.803996584              0.76154893       2
## 74           0.075492782              1.01929088       2
## 75           0.492255450              2.09287743       2
## 76           0.899712412              1.91225512       2
## 77          -0.566600899              0.66210519       2
## 78           1.210788854              0.93405339       2
## 79           1.072532658              0.93202392       2
## 80           0.972163977              1.55709889       2
## 81          -1.487865744              1.73163281       2
## 82          -0.497472801              1.55303996       2
## 83          -0.842448598              1.57739353       2
## 84          -1.370215039              1.39880068       2
## 85          -0.012911421              2.18826225       2
## 86           1.375632780              1.64639531       2
## 87           0.867807136              1.82904709       2
## 88          -1.166818904              2.08881850       2
## 89          -0.392451267              1.28515069       2
## 90          -0.314682157              1.28515069       2
## 91           1.522529988              0.92796500       2
## 92           0.812637597              2.08678904       2
## 93          -0.009587955              1.11061677       2
## 94          -0.155155776              1.66060156       2
## 95          -1.041191880              2.09693636       2
## 96          -0.569924365              1.73163281       2
## 97          -1.011945377              1.37444711       2
## 98           0.336717229              0.40233377       2
## 99          -1.091708567              0.84678643       2
## 100          0.397204315              1.19585427       2
## 101         -0.234918967              1.64233639       2
## 102         -0.227607341              1.47794979       2
## 103         -0.769332340              0.93202392       2
## 104         -0.576571297              1.58348192       2
## 105          0.024311401              1.03349713       2
## 106         -0.304711758              2.29379439       2
## 107         -1.311057339              0.96246589       2
## 108         -0.980704794              0.75951947       2
## 109         -0.021552433              1.10655784       2
## 110         -1.064456143              1.02334981       2
## 111          1.975186092              1.28515069       2
## 112          0.642476124              1.81889977       2
## 113         -0.972063782              1.50839175       2
## 114          0.414486339              0.67022305       2
## 115         -0.416380224              1.55303996       2
## 116         -0.047475470              1.10858731       2
## 117         -0.430338782              1.82701763       2
## 118          1.456060663              1.55912835       2
## 119         -0.060769335              1.19991320       2
## 120          0.382581063              0.57483823       2
## 121         -0.482849549              0.98478999       2
## 122         -0.248877525             -0.55963224       1
## 123          0.317441125              1.16135338       2
## 124          0.452373855              1.38459444       2
## 125         -0.966081542              1.01320249       2
## 126         -1.196730100              1.55303996       2
## 127          1.100449774              0.48960073       2
## 128         -0.580559457              1.10046945       2
## 129         -0.533366236              1.07408642       2
## 130          0.499567075              0.76154893       2
## 131          0.369287198              0.76154893       2
## 132          0.838560633              0.86708107       2
## 133         -0.122585807              1.11873463       2
## 134         -0.711504027              0.93202392       2
## 135         -0.655005101              0.67428197       2
## 136          0.038934653              1.01929088       2
## 137          1.059238793             -0.05023674       3
## 138          2.209822810              0.04108915       3
## 139          1.518541829             -0.22882958       3
## 140          1.168913179             -0.40336350       3
## 141          0.505549315             -0.49063046       3
## 142          1.634198454             -0.29377244       3
## 143         -0.990010499             -0.58398581       3
## 144          0.472314652             -0.84781616       3
## 145         -0.299394212             -0.21056441       3
## 146          1.164260326             -0.45815904       3
## 147          0.986787228             -0.22882958       3
## 148          2.181241000             -0.30391976       3
## 149          0.694986891             -0.12126798       3
## 150         -0.251536298             -0.84984562       3
## 151          0.224384070             -0.31812601       3
## 152          1.397567657             -0.40742243       3
## 153         -0.241565899             -0.84578669       3
## 154          0.740850725             -0.40539297       3
## 155          0.443732842             -0.22274119       3
## 156          1.115073026             -0.22274119       3
## 157         -0.417709611              0.14459182       3
## 158          0.372610665             -0.22680012       3
## 159          0.849195725             -0.75851973       3
## 160          0.470985266             -0.49468939       3
## 161          1.779766276             -0.75243134       3
## 162         -1.003304364             -0.73822509       1
## 163          0.806655357             -0.30391976       3
## 164         -0.048140163             -0.16591619       3
## 165          0.416480419             -0.58398581       3
## 166          1.997120969             -0.94117151       3
## 167          0.397869008             -0.85187509       3
## 168          1.248011676             -0.67125277       3
## 169          0.978146216             -0.47642421       3
## 170          0.706286676             -0.72401884       3
## 171          1.079844283             -0.66516438       3
## 172          0.659093456             -0.92696526       3
## 173          1.439443332             -0.84781616       3
## 174         -1.362238720             -0.49063046       3
## 175          0.828590235             -1.20703132       3
## 176          0.848531032             -0.55354385       3
## 177          0.762120910             -0.53121975       3
## 178          0.996092934             -0.57789742       3
## 179          1.644833546             -0.21056441       3
## 180          0.233689775             -0.48251261       3
## 181          0.789373333             -0.13750370       3
## 182          0.311458886             -0.94117151       3
## 183          2.534857809             -0.93914205       3
## 184          0.840554713             -1.26994471       3
## 185          1.121719958             -0.76054920       3
## 186          0.182508395             -0.84984562       3
## 187         -0.075392586             -0.58398581       3
## 188          0.759462137             -0.67125277       3
## 189          0.280218303             -0.82752152       3
## 190          0.772756002             -1.02640900       3
## 191          1.178218884             -0.93711258       3
## 192          0.637823272             -0.66719385       3
## 193         -0.268818322             -0.38306886       3
## 194         -0.586541696             -1.19688400       1
## 195          1.170907259             -0.76054920       3
## 196          0.226378149             -1.20094292       3
## 197          3.154351919             -0.85187509       3
## 198          0.138638640             -0.84984562       3
## 199         -0.052793016             -1.11570543       3
## 200          0.408504100             -0.84578669       3
## 201          3.060630171             -0.73822509       3
## 202         -0.074727893             -0.76257866       3
## 203          1.280581645             -0.72401884       3
count(seeds_df_cl,cluster)
##   cluster  n
## 1       1 49
## 2       2 73
## 3       3 81
library(ggplot2)
ggplot(seeds_df_cl, aes(x=area, y = perimeter, color = factor(cluster))) +geom_point()

library(clValid)
## Loading required package: cluster
dunn(dist_mat,cut_avg)
## [1] 0.105588
#This is an algorithm for the k-means clustering applied to the iris dataset
set.seed(1234) #setting a seed for the random number generator
data(iris) 
ir3<-kmeans(iris[,-5],center=3, iter.max=200) #not using species info
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"
ir3$betweenss
## [1] 602.5192
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