99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁(yè)精彩閱讀python實(shí)現(xiàn)六大分群質(zhì)量評(píng)估指標(biāo)(蘭德系數(shù)、互信息、輪廓系數(shù))
python實(shí)現(xiàn)六大分群質(zhì)量評(píng)估指標(biāo)(蘭德系數(shù)、互信息、輪廓系數(shù))
2017-05-19
收藏

python實(shí)現(xiàn)六大分群質(zhì)量評(píng)估指標(biāo)(蘭德系數(shù)、互信息、輪廓系數(shù))

1 R語(yǔ)言中的分群質(zhì)量——輪廓系數(shù)
因?yàn)橄惹皯T用R語(yǔ)言,那么來(lái)看看R語(yǔ)言中的分群質(zhì)量評(píng)估,節(jié)選自筆記︱多種常見(jiàn)聚類模型以及分群質(zhì)量評(píng)估(聚類注意事項(xiàng)、使用技巧):
沒(méi)有固定標(biāo)準(zhǔn),一般會(huì)3-10分群?;蛘哂靡恍┲笜?biāo)評(píng)價(jià),然后交叉驗(yàn)證不同群的分群指標(biāo)。
一般的指標(biāo):輪廓系數(shù)silhouette(-1,1之間,值越大,聚類效果越好)(fpc包),蘭德指數(shù)rand;R語(yǔ)言中有一個(gè)包用30種方法來(lái)評(píng)價(jià)不同類的方法(NbClust),但是速度較慢
商業(yè)上的指標(biāo):分群結(jié)果的覆蓋率;分群結(jié)果的穩(wěn)定性;分群結(jié)果是否從商業(yè)上易于理解和執(zhí)行
輪廓系數(shù)旨在將某個(gè)對(duì)象與自己的簇的相似程度和與其他簇的相似程度進(jìn)行比較。輪廓系數(shù)最高的簇的數(shù)量表示簇的數(shù)量的最佳選擇。

一般來(lái)說(shuō),平均輪廓系數(shù)越高,聚類的質(zhì)量也相對(duì)較好。在這,對(duì)于研究區(qū)域的網(wǎng)格單元,最優(yōu)聚類數(shù)應(yīng)該是2,這時(shí)平均輪廓系數(shù)的值最高。但是,聚類結(jié)果(k=2)的 SSE 值太大了。當(dāng) k=6 時(shí),SEE 的值會(huì)低很多,但此時(shí)平均輪廓系數(shù)的值非常高,僅僅比 k=2 時(shí)的值低一點(diǎn)。因此,k=6 是最佳的選擇。
2 python中的分群質(zhì)量
主要參考來(lái)自官方文檔:Clustering
部分內(nèi)容來(lái)源于:機(jī)器學(xué)習(xí)評(píng)價(jià)指標(biāo)大匯總
個(gè)人比較偏好的三個(gè)指標(biāo)有:Calinski-Harabaz Index(未知真實(shí)index的模型評(píng)估)、Homogeneity, completeness and V-measure(聚類數(shù)量情況)、輪廓系數(shù)
1.1 Adjusted Rand index 調(diào)整蘭德系數(shù)

>>> from sklearn import metrics
>>> labels_true = [0, 0, 0, 1, 1, 1]
>>> labels_pred = [0, 0, 1, 1, 2, 2]

>>> metrics.adjusted_rand_score(labels_true, labels_pred)  
0.24
1.2 Mutual Information based scores 互信息

Two different normalized versions of this measure are available, Normalized Mutual Information(NMI) and Adjusted Mutual Information(AMI). NMI is often used in the literature while AMI was proposed more recently and is normalized against chance:

>>> from sklearn import metrics
>>> labels_true = [0, 0, 0, 1, 1, 1]
>>> labels_pred = [0, 0, 1, 1, 2, 2]

>>> metrics.adjusted_mutual_info_score(labels_true, labels_pred)  
0.22504
  
1.3 Homogeneity, completeness and V-measure
同質(zhì)性homogeneity:每個(gè)群集只包含單個(gè)類的成員。
完整性completeness:給定類的所有成員都分配給同一個(gè)群集。
>>> from sklearn import metrics
>>> labels_true = [0, 0, 0, 1, 1, 1]
>>> labels_pred = [0, 0, 1, 1, 2, 2]

>>> metrics.homogeneity_score(labels_true, labels_pred)  
0.66...

>>> metrics.completeness_score(labels_true, labels_pred)
0.42...
兩者的調(diào)和平均V-measure:
>>> metrics.v_measure_score(labels_true, labels_pred)    
0.51...
1.4 Fowlkes-Mallows scores
The Fowlkes-Mallows score FMI is defined as the geometric mean of the pairwise precision and recall:

>>> from sklearn import metrics
>>> labels_true = [0, 0, 0, 1, 1, 1]
>>> labels_pred = [0, 0, 1, 1, 2, 2]
>>>
>>> metrics.fowlkes_mallows_score(labels_true, labels_pred)  
0.47140...
1.5 Silhouette Coefficient 輪廓系數(shù)

>>> import numpy as np
>>> from sklearn.cluster import KMeans
>>> kmeans_model = KMeans(n_clusters=3, random_state=1).fit(X)
>>> labels = kmeans_model.labels_
>>> metrics.silhouette_score(X, labels, metric='euclidean')
...                                                      
0.55...
1.6 Calinski-Harabaz Index
這個(gè)計(jì)算簡(jiǎn)單直接,得到的Calinski-Harabasz分?jǐn)?shù)值ss越大則聚類效果越好。Calinski-Harabasz分?jǐn)?shù)值ss的數(shù)學(xué)計(jì)算公式是:

 也就是說(shuō),類別內(nèi)部數(shù)據(jù)的協(xié)方差越小越好,類別之間的協(xié)方差越大越好,這樣的Calinski-Harabasz分?jǐn)?shù)會(huì)高。
 在scikit-learn中, Calinski-Harabasz Index對(duì)應(yīng)的方法是metrics.calinski_harabaz_score.
在真實(shí)的分群label不知道的情況下,可以作為評(píng)估模型的一個(gè)指標(biāo)。
同時(shí),數(shù)值越小可以理解為:組間協(xié)方差很小,組與組之間界限不明顯。
與輪廓系數(shù)的對(duì)比,筆者覺(jué)得最大的優(yōu)勢(shì):快!相差幾百倍!毫秒級(jí)
>>> import numpy as np
>>> from sklearn.cluster import KMeans
>>> kmeans_model = KMeans(n_clusters=3, random_state=1).fit(X)
>>> labels = kmeans_model.labels_
>>> metrics.calinski_harabaz_score(X, labels)  
560.39...

數(shù)據(jù)分析咨詢請(qǐng)掃描二維碼

若不方便掃碼,搜微信號(hào):CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個(gè)參數(shù)驗(yàn)證碼對(duì)象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個(gè)配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺(tái)檢測(cè)極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時(shí)表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說(shuō)明請(qǐng)參見(jiàn):http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計(jì)時(shí)完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請(qǐng)輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請(qǐng)輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }