
數(shù)據(jù)挖掘成果固化_聚類(lèi)分析_數(shù)據(jù)分析師
--聚類(lèi)樣本數(shù)據(jù)模擬
--BY:@ETwise
--輸入表1:cluster_sample
--輸入表2:cluster_center
--20141213
create table cluster_sample
(
serv_id NUMBER ,
label_1 number,
label_2 number,
label_3 number,
label_4 number
);
INSERT INTO cluster_sample (serv_id,label_1,label_2,label_3,label_4) VALUES (1,2,3,4,5);
INSERT INTO cluster_sample (serv_id,label_1,label_2,label_3,label_4) VALUES (2,2.5,4.2,4.2,5.2);
INSERT INTO cluster_sample (serv_id,label_1,label_2,label_3,label_4) VALUES (3,3.2,4.1,2.3,5.1);
INSERT INTO cluster_sample (serv_id,label_1,label_2,label_3,label_4) VALUES (4,1.1,1.2,2.2,3.2);
INSERT INTO cluster_sample (serv_id,label_1,label_2,label_3,label_4) VALUES (5,1.7,1.75,1.35,4.1);
INSERT INTO cluster_sample (serv_id,label_1,label_2,label_3,label_4) VALUES (6,1.5,1.2,0.62,3.38);
INSERT INTO cluster_sample (serv_id,label_1,label_2,label_3,label_4) VALUES (7,1.3,0.65,-0.11,3);
INSERT INTO cluster_sample (serv_id,label_1,label_2,label_3,label_4) VALUES (8,1.1,0.1,-0.84,2.62);
INSERT INTO cluster_sample (serv_id,label_1,label_2,label_3,label_4) VALUES (9,0.9,-0.45,-1.57,2.24);
INSERT INTO cluster_sample (serv_id,label_1,label_2,label_3,label_4) VALUES (11,0.5,-1.55,-3.03,1.48);
INSERT INTO cluster_sample (serv_id,label_1,label_2,label_3,label_4) VALUES (12,0.3,-2.1,-3.76,1.1);
INSERT INTO cluster_sample (serv_id,label_1,label_2,label_3,label_4) VALUES (13,0.1,-2.65,-4.49,0.72);
INSERT INTO cluster_sample (serv_id,label_1,label_2,label_3,label_4) VALUES (14,-0.1,-3.2,-5.22,0.34);
INSERT INTO cluster_sample (serv_id,label_1,label_2,label_3,label_4) VALUES (15,-0.3,-3.75,-5.95,-0.04);
INSERT INTO cluster_sample (serv_id,label_1,label_2,label_3,label_4) VALUES (16,-0.5,-4.3,-6.68,-0.42);
--創(chuàng)建聚類(lèi)分析所得到的中心點(diǎn)數(shù)據(jù)
create table cluster_center
(
row_1 number,
row_2 number,
row_3 number,
row_4 number,
type_id VARCHAR2(20) not null
);
INSERT INTO cluster_center (row_1,row_2,row_3,row_4,type_id) VALUES (0,0,0,0,'t1');
INSERT INTO cluster_center (row_1,row_2,row_3,row_4,type_id) VALUES (1,1,1,1,'t2');
INSERT INTO cluster_center (row_1,row_2,row_3,row_4,type_id) VALUES (2,2,2,2,'t3');
INSERT INTO cluster_center (row_1,row_2,row_3,row_4,type_id) VALUES (3,3,3,3,'t4');
--聚類(lèi)分析成果系統(tǒng)固化相關(guān)說(shuō)明(K-means)
--第一步:對(duì)計(jì)算每個(gè)點(diǎn)與各個(gè)中心點(diǎn)的距離,并對(duì)應(yīng)得到相應(yīng)的分類(lèi)type_id
select serv_id,
sqrt(power((label_1 - row_1), 2) + power((label_2 - row_2), 2) +
power((label_3 - row_3), 2) + power((label_4 - row_4), 2)) OS,
type_id
from cluster_sample a, cluster_center b
;
--第二步:使用開(kāi)窗函數(shù)對(duì)各serv_id的各個(gè)中心點(diǎn)的距離進(jìn)行升序排序,并打上相應(yīng)的編號(hào)
select serv_id,
os,
row_number() over(partition by serv_id order by os asc) myrow_1,
type_id
from (select serv_id,
sqrt(power((label_1 - row_1), 2) +
power((label_2 - row_2), 2) +
power((label_3 - row_3), 2) +
power((label_4 - row_4), 2)) OS,
type_id
from cluster_sample a, cluster_center b)
;
--第三步:提取各個(gè)serv_id的最小距離數(shù)據(jù),即可得到各個(gè)serv_id的類(lèi)別
select *
from (select serv_id,
os,
row_number() over(partition by serv_id order by os asc) myrow_1,
type_id
from (select serv_id,
sqrt(power((label_1 - row_1), 2) +
power((label_2 - row_2), 2) +
power((label_3 - row_3), 2) +
power((label_4 - row_4), 2)) OS,
type_id
from cluster_sample a, cluster_center b))
where myrow_1 = 1
;
--其他辦法:一步到位,直接代入中心點(diǎn)進(jìn)行計(jì)算
select serv_id,
case
when least(os1, os2, os3, os4) = os1 then
't1'
when least(os1, os2, os3, os4) = os2 then
't2'
when least(os1, os2, os3, os4) = os3 then
't3'
when least(os1, os2, os3, os4) = os4 then
't4'
else
'-1'
end type_id
from (select serv_id,
sqrt(power((label_1 - 0), 2) + power((label_2 - 0), 2) +
power((label_3 - 0), 2) + power((label_4 - 0), 2)) os1,
sqrt(power((label_1 - 1), 2) + power((label_2 - 1), 2) +
power((label_3 - 1), 2) + power((label_4 - 1), 2)) os2,
sqrt(power((label_1 - 2), 2) + power((label_2 - 2), 2) +
power((label_3 - 2), 2) + power((label_4 - 2), 2)) os3,
sqrt(power((label_1 - 3), 2) + power((label_2 - 3), 2) +
power((label_3 - 3), 2) + power((label_4 - 3), 2)) os4
from cluster_sample t)
;
數(shù)據(jù)分析咨詢(xún)請(qǐng)掃描二維碼
若不方便掃碼,搜微信號(hào):CDAshujufenxi
2025被稱(chēng)為“AI元年”,而AI,與數(shù)據(jù)密不可分。網(wǎng)易公司創(chuàng)始人丁磊在《AI思維:從數(shù)據(jù)中創(chuàng)造價(jià)值的煉金術(shù)》一書(shū)中指出:AI思維, ...
2025-07-17數(shù)據(jù)分析師的技能圖譜:從數(shù)據(jù)到價(jià)值的橋梁? 在數(shù)據(jù)驅(qū)動(dòng)決策的時(shí)代,數(shù)據(jù)分析師如同 “數(shù)據(jù)翻譯官”,將冰冷的數(shù)字轉(zhuǎn)化為清晰的 ...
2025-07-17Pandas 寫(xiě)入指定行數(shù)據(jù):數(shù)據(jù)精細(xì)化管理的核心技能? 在數(shù)據(jù)處理的日常工作中,我們常常需要面對(duì)這樣的場(chǎng)景:在龐大的數(shù)據(jù)集里精 ...
2025-07-17解碼 CDA:數(shù)據(jù)時(shí)代的通行證? 在數(shù)字化浪潮席卷全球的今天,當(dāng)企業(yè)決策者盯著屏幕上跳動(dòng)的數(shù)據(jù)曲線(xiàn)尋找增長(zhǎng)密碼,當(dāng)科研人員在 ...
2025-07-17CDA 精益業(yè)務(wù)數(shù)據(jù)分析:數(shù)據(jù)驅(qū)動(dòng)業(yè)務(wù)增長(zhǎng)的實(shí)戰(zhàn)方法論 在企業(yè)數(shù)字化轉(zhuǎn)型的浪潮中,“數(shù)據(jù)分析” 已從 “加分項(xiàng)” 成為 “必修課 ...
2025-07-16MySQL 中 ADD KEY 與 ADD INDEX 詳解:用法、差異與優(yōu)化實(shí)踐 在 MySQL 數(shù)據(jù)庫(kù)表結(jié)構(gòu)設(shè)計(jì)中,索引是提升查詢(xún)性能的核心手段。無(wú)論 ...
2025-07-16解析 MySQL Update 語(yǔ)句中 “query end” 狀態(tài):含義、成因與優(yōu)化指南? 在 MySQL 數(shù)據(jù)庫(kù)的日常運(yùn)維與開(kāi)發(fā)中,開(kāi)發(fā)者和 DBA 常會(huì) ...
2025-07-16如何考取數(shù)據(jù)分析師證書(shū):以 CDA 為例? ? 在數(shù)字化浪潮席卷各行各業(yè)的當(dāng)下,數(shù)據(jù)分析師已然成為企業(yè)挖掘數(shù)據(jù)價(jià)值、驅(qū)動(dòng)決策的 ...
2025-07-15CDA 精益業(yè)務(wù)數(shù)據(jù)分析:驅(qū)動(dòng)企業(yè)高效決策的核心引擎? 在數(shù)字經(jīng)濟(jì)時(shí)代,企業(yè)面臨著前所未有的數(shù)據(jù)洪流,如何從海量數(shù)據(jù)中提取有 ...
2025-07-15MySQL 無(wú)外鍵關(guān)聯(lián)表的 JOIN 實(shí)戰(zhàn):數(shù)據(jù)整合的靈活之道? 在 MySQL 數(shù)據(jù)庫(kù)的日常操作中,我們經(jīng)常會(huì)遇到需要整合多張表數(shù)據(jù)的場(chǎng)景 ...
2025-07-15Python Pandas:數(shù)據(jù)科學(xué)的瑞士軍刀? ? 在數(shù)據(jù)驅(qū)動(dòng)的時(shí)代,面對(duì)海量、復(fù)雜的數(shù)據(jù),如何高效地進(jìn)行處理、分析和挖掘成為關(guān)鍵。 ...
2025-07-15用 SQL 生成逆向回滾 SQL:數(shù)據(jù)操作的 “后悔藥” 指南? 在數(shù)據(jù)庫(kù)操作中,誤刪數(shù)據(jù)、錯(cuò)改字段或誤執(zhí)行批量更新等問(wèn)題時(shí)有發(fā)生。 ...
2025-07-14t檢驗(yàn)與Wilcoxon檢驗(yàn)的選擇:何時(shí)用t.test,何時(shí)用wilcox.test? t 檢驗(yàn)與 Wilcoxon 檢驗(yàn)的選擇:何時(shí)用 t.test,何時(shí)用 wilcox. ...
2025-07-14AI 浪潮下的生存與進(jìn)階: CDA數(shù)據(jù)分析師—開(kāi)啟新時(shí)代職業(yè)生涯的鑰匙(深度研究報(bào)告、發(fā)展指導(dǎo)白皮書(shū)) 發(fā)布機(jī)構(gòu):CDA數(shù)據(jù)科 ...
2025-07-13LSTM 模型輸入長(zhǎng)度選擇技巧:提升序列建模效能的關(guān)鍵? 在循環(huán)神經(jīng)網(wǎng)絡(luò)(RNN)家族中,長(zhǎng)短期記憶網(wǎng)絡(luò)(LSTM)憑借其解決長(zhǎng)序列 ...
2025-07-11CDA 數(shù)據(jù)分析師報(bào)考條件詳解與準(zhǔn)備指南? ? 在數(shù)據(jù)驅(qū)動(dòng)決策的時(shí)代浪潮下,CDA 數(shù)據(jù)分析師認(rèn)證愈發(fā)受到矚目,成為眾多有志投身數(shù) ...
2025-07-11數(shù)據(jù)透視表中兩列相乘合計(jì)的實(shí)用指南? 在數(shù)據(jù)分析的日常工作中,數(shù)據(jù)透視表憑借其強(qiáng)大的數(shù)據(jù)匯總和分析功能,成為了 Excel 用戶(hù) ...
2025-07-11尊敬的考生: 您好! 我們誠(chéng)摯通知您,CDA Level I和 Level II考試大綱將于 2025年7月25日 實(shí)施重大更新。 此次更新旨在確保認(rèn) ...
2025-07-10BI 大數(shù)據(jù)分析師:連接數(shù)據(jù)與業(yè)務(wù)的價(jià)值轉(zhuǎn)化者? ? 在大數(shù)據(jù)與商業(yè)智能(Business Intelligence,簡(jiǎn)稱(chēng) BI)深度融合的時(shí)代,BI ...
2025-07-10SQL 在預(yù)測(cè)分析中的應(yīng)用:從數(shù)據(jù)查詢(xún)到趨勢(shì)預(yù)判? ? 在數(shù)據(jù)驅(qū)動(dòng)決策的時(shí)代,預(yù)測(cè)分析作為挖掘數(shù)據(jù)潛在價(jià)值的核心手段,正被廣泛 ...
2025-07-10