最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

拓端tecdat|R語(yǔ)言聚類有效性:確定最優(yōu)聚類數(shù)分析IRIS鳶尾花數(shù)據(jù)和可視化

2021-08-02 11:49 作者:拓端tecdat  | 我要投稿

原文鏈接:http://tecdat.cn/?p=22879

原文出處:拓端數(shù)據(jù)部落公眾號(hào)

數(shù)據(jù)集概述

這個(gè)數(shù)據(jù)集常用于數(shù)據(jù)概述、可視化和聚類模型。它包括三個(gè)鳶尾花品種,每個(gè)品種有50個(gè)樣本,以及一些屬性。其中一個(gè)花種與其他兩個(gè)花種是線性可分離的,但其他兩個(gè)花種之間不是線性可分離的。

這個(gè)數(shù)據(jù)集的給定列是:

i> Id
ii> 萼片長(zhǎng)度(Cm)
iii>萼片寬度(Cm)
iv> 花瓣長(zhǎng)度(Cm)
v> 花瓣寬度 (Cm)
vi> 品種

讓我們把這個(gè)數(shù)據(jù)集可視化,并用kmeans進(jìn)行聚類。

基本可視化

IRIS數(shù)據(jù),聚類前的基本可視化

plot(data, aes(x , y ))

plot(data,geom_density(alpha=0.25)

火山圖

plot( iris, stat_density(aes(ymax = ..density.., ?ymin = -..density..,

plot(data, aes(x ),stat_density= ..density.., ?facet_grid. ~ Species)

聚類數(shù)據(jù) :: 方法-1


  1. # 在一個(gè)循環(huán)中進(jìn)行15次的kmeans聚類分析

  2. for (i in 1:15)

  3. kmeans(Data, i)

  4. totalwSS[i]<-tot



  5. # 聚類碎石圖 - 使用plot函數(shù)繪制total_wss與no-of-clusters的數(shù)值。

  6. plot(x=1:15, ? ? ? ? ? ? ? ? ? ? ? ? # x= 類數(shù)量, 1 to 15

  7. totalwSS, ? ? ? ? ? ? ? ? ? ? ?#每個(gè)類的total_wss值

  8. type="b" ? ? ? ? ? ? ? ? ? ? ? # 繪制兩點(diǎn),并將它們連接起來(lái)

聚類數(shù)據(jù) :: 方法-2

使用聚類有效性測(cè)量指標(biāo)

  1. library(NbClust)


  2. # 設(shè)置邊距為: c(bottom, left, top, right)

  3. par(mar = c(2,2,2,2))


  4. # 根據(jù)一些指標(biāo)來(lái)衡量聚類的合適性。

  5. # 默認(rèn)情況下,它檢查從2個(gè)聚類到15個(gè)聚類的情況 # 花費(fèi)時(shí)間

休伯特指數(shù)

休伯特指數(shù)是一種確定聚類數(shù)量的圖形方法。
在休伯特指數(shù)圖中,我們尋找一個(gè)明顯的拐點(diǎn),對(duì)應(yīng)于測(cè)量值的明顯增加,即休伯特指數(shù)第二差值圖中的明顯峰值。
?

D指數(shù)

在D指數(shù)的圖表中,我們尋找一個(gè)重要的拐點(diǎn)(D指數(shù)第二差值圖中的重要峰值),對(duì)應(yīng)于測(cè)量值的顯著增加。?


  1. ##

  2. ## *******************************************************************

  3. ## * 在所有指數(shù)中:

  4. ## * 10 proposed 2 as the best number of clusters

  5. ## * 8 proposed 3 as the best number of clusters

  6. ## * 2 proposed 4 as the best number of clusters

  7. ## * 1 proposed 5 as the best number of clusters

  8. ## * 1 proposed 8 as the best number of clusters

  9. ## * 1 proposed 14 as the best number of clusters

  10. ## * 1 proposed 15 as the best number of clusters

  11. ##

  12. ## ? ? ? ? ? ? ? ? ? ?***** 結(jié)論*****

  13. ##

  14. ## * 根據(jù)多數(shù)規(guī)則,集群的最佳數(shù)量是2

  15. ##

  16. ##

  17. ## *******************************************************************

畫一個(gè)直方圖,表示各種指數(shù)對(duì)聚類數(shù)量的投票情況。
在26個(gè)指數(shù)中,大多數(shù)(10個(gè))投票給2個(gè)聚類,8個(gè)投票給3個(gè)聚類,其余8個(gè)(26-10-8)投票給其他數(shù)量的聚類。
直方圖,斷點(diǎn)=15,因?yàn)槲覀兊乃惴ㄊ菣z查2到15個(gè)聚類的。?


  1. hist(Best.nc)

聚類數(shù)據(jù) :: 方法-3

卡林斯基指標(biāo)類似于尋找群組間方差/群組內(nèi)方差的比率。

  1. KM(Data, 1, 10) ?# 對(duì)聚類1至10的測(cè)試



  2. # sortg = TRUE:將iris對(duì)象(行)作為其組別成員的函數(shù)排序

  3. # 在熱圖中用顏色表示組成員類

  4. # 排序是為了產(chǎn)生一個(gè)更容易解釋的圖表。

  5. # 兩個(gè)圖。一個(gè)是熱圖,另一個(gè)是聚類數(shù)目與值(=BC/WC)。

modelData$results[2,] ? # 針對(duì)BC/WC值的聚類

  1. # 那么,這些數(shù)值中哪一個(gè)是最大的?BC/WC應(yīng)盡可能的大

  2. which.max(modelData$results[2,])

用Silhoutte圖對(duì)數(shù)據(jù)進(jìn)行聚類 :: 方法-4

先試著2個(gè)類

  1. # 計(jì)算并返回通過(guò)使用歐氏距離測(cè)量法計(jì)算的距離矩陣,計(jì)算數(shù)據(jù)矩陣中各行之間的距離。

  2. # 獲取silhoutte 系數(shù)

  3. silhouette (cluster, dis)

試用8個(gè)聚類

  1. # 計(jì)算并返回通過(guò)使用歐氏距離測(cè)量法計(jì)算的距離矩陣,計(jì)算數(shù)據(jù)矩陣中各行之間的距離。

  2. # 獲取silhoutte 系數(shù)

  3. silhouette (cluster, dis)

分析聚類趨勢(shì)

計(jì)算iris和隨機(jī)數(shù)據(jù)集的霍普金統(tǒng)計(jì)值

  1. # 1. 給定一個(gè)數(shù)字向量或數(shù)據(jù)框架的一列 根據(jù)其最小值和最大值生成統(tǒng)一的隨機(jī)數(shù)

  2. runif(length(x), min(x), (max(x)))


  3. # 2. ?通過(guò)在每一列上應(yīng)用函數(shù)生成隨機(jī)數(shù)據(jù)

  4. apply(iris[,-5], 2, genx)


  5. # 3. 將兩個(gè)數(shù)據(jù)集標(biāo)準(zhǔn)化

  6. scale(iris) ? # 默認(rèn), center = T, scale = T


  7. # 4. 計(jì)算數(shù)據(jù)集的霍普金斯統(tǒng)計(jì)數(shù)字

  8. hopkins_stat

  1. # 也可以用函數(shù)hopkins()計(jì)算。

  2. hopkins(iris)

  1. # 5. 計(jì)算隨機(jī)數(shù)據(jù)集的霍普金斯統(tǒng)計(jì)量

  2. hopkins_stat

最受歡迎的見(jiàn)解

1.R語(yǔ)言k-Shape算法股票價(jià)格時(shí)間序列聚類

2.R語(yǔ)言中不同類型的聚類方法比較

3.R語(yǔ)言對(duì)用電負(fù)荷時(shí)間序列數(shù)據(jù)進(jìn)行K-medoids聚類建模和GAM回歸

4.r語(yǔ)言鳶尾花iris數(shù)據(jù)集的層次聚類

5.Python Monte Carlo K-Means聚類實(shí)戰(zhàn)

6.用R進(jìn)行網(wǎng)站評(píng)論文本挖掘聚類

7.用于NLP的Python:使用Keras的多標(biāo)簽文本LSTM神經(jīng)網(wǎng)絡(luò)

8.R語(yǔ)言對(duì)MNIST數(shù)據(jù)集分析 探索手寫數(shù)字分類數(shù)據(jù)

9.R語(yǔ)言基于Keras的小數(shù)據(jù)集深度學(xué)習(xí)圖像分類


拓端tecdat|R語(yǔ)言聚類有效性:確定最優(yōu)聚類數(shù)分析IRIS鳶尾花數(shù)據(jù)和可視化的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
清苑县| 商城县| 永善县| 嵩明县| 永济市| 乐至县| 汾西县| 金平| 海安县| 隆回县| 宁明县| 谢通门县| 南涧| 台南县| 塔城市| 白银市| 湄潭县| 田东县| 綦江县| 宜春市| 阿鲁科尔沁旗| 江油市| 固镇县| 江华| 沅陵县| 华蓥市| 亳州市| 昂仁县| 启东市| 遂溪县| 睢宁县| 纳雍县| 容城县| 金昌市| 红原县| 广汉市| 广西| 新建县| 长宁县| 乳山市| 建始县|