轉帖|使用教程|編輯:我只采一朵|2017-07-20 17:23:39.000|閱讀 8969 次
概述:在本文中,主要講解下如何使用Elastic search和Kibana實現(xiàn)EDA。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
探索性數(shù)據(jù)分析(EDA)幫助我們認識底層的數(shù)據(jù)基結構及其動力學,以此來最大限度發(fā)掘出數(shù)據(jù)的可能性。EDA是提取重要變量和檢測異常值的關鍵。盡管存在著很多種機器學習算法,但EDA仍被視為理解和推動業(yè)務的最關鍵算法之一。
其實有很多種方式都能夠執(zhí)行實現(xiàn)EDA,例如Python的matplotlib、seaborn庫,R語言的ggplot2,而且網(wǎng)絡上有很多很好的資源,例如John W. Tukey的“探索性數(shù)據(jù)分析”, Roger D. Peng 的“用R進行探索性數(shù)據(jù)分析”等,不勝枚舉。
在本文中,我主要講解下如何使用Elastic search和Kibana實現(xiàn)EDA。
原文作者:Supreeth Manyam
1. Elastic search
2. Kibana
3. 創(chuàng)建數(shù)據(jù)表
4. 搜索欄
Elastic Search是一個開放源碼,RESTful分布式和可擴展的搜索引擎。由于其簡單的設計和分布式特性,Elastic Search從大量級數(shù)據(jù)(PB)中進行簡單或復雜的查詢、提取結果都非常迅速。另外相較于傳統(tǒng)數(shù)據(jù)庫被模式、表所約束,Elastic Search工作起來也更加容易。
Elastic Search提供了一個具有HTTP Web界面和無模式JSON文檔的分布式、多租戶的全文搜索引擎。
ES安裝
安裝和初始化是相對簡單的,如下所示:
Elasticsearch實例在默認配置的瀏覽器中進行本地運行。
Kibana是一個基于Elasticsearch的開源數(shù)據(jù)挖掘和可視化工具,它可以幫助用戶更好地理解數(shù)據(jù)。它在Elasticsearch集群索引的內容之上提供可視化功能。
安裝
安裝和初始化的過程與Elasticsearch類似:
Kibana實例在默認配置的瀏覽器中進行本地運行.
將運行Kibana的終端保持打開狀態(tài),可以保證實例不斷的運行。你也可以使用nohup模式在后臺運行實例。
使用ES和Kibana創(chuàng)建儀表板主要有三個步驟。接下來我將會用貸款預測的實際問題的數(shù)據(jù)來示例如何創(chuàng)建一個儀表板。請注冊該問題,以便能夠下載數(shù)據(jù)。請檢查數(shù)據(jù)字典以獲得更多詳細信息。
注:在本文中,我將使用python讀取數(shù)據(jù)并將數(shù)據(jù)插入到Elasticsearch中,并通過Kibana進行可視化。
讀取數(shù)據(jù)
import pandas as pd
train_data_path = '../loan_prediction_data/train_u6lujuX_CVtuZ9i.csv' test_data_path = '../loan_prediction_data/test_Y3wMUE5_7gLdaTN.csv' train = pd.read_csv(train_data_path); print(train.shape) test = pd.read_csv(test_data_path); print(test.shape)
結果:
(614, 13) (367, 12)
3.1 數(shù)據(jù)索引
Elasticsearch將數(shù)據(jù)索引到其內部數(shù)據(jù)格式,并將其存儲在類似于JSON對象的基本數(shù)據(jù)結構中。請找到下面的Python代碼,將數(shù)據(jù)插入到ES當中。
請如下所示安裝pyelasticsearch庫以便通過Python索引。
pip install pyelasticsearch
from time import time from pyelasticsearch import ElasticSearch CHUNKSIZE=100 index_name_train = "loan_prediction_train" doc_type_train = "av-lp_train" index_name_test = "loan_prediction_test" doc_type_test = "av-lp_test"
def index_data(data_path, chunksize, index_name, doc_type): f = open(data_path) csvfile = pd.read_csv(f, iterator=True, chunksize=chunksize) es = ElasticSearch('//localhost:9200/') try : es.delete_index(index_name) except : pass es.create_index(index_name) for i,df in enumerate(csvfile): records=df.where(pd.notnull(df), None).T.to_dict() list_records=[records[it] for it in records] try : es.bulk_index(index_name, doc_type, list_records) except : print("error!, skiping chunk!") pass
index_data(train_data_path, CHUNKSIZE, index_name_train, doc_type_train) # Indexing train data
index_data(test_data_path, CHUNKSIZE, index_name_test, doc_type_test) # Indexing test data
DELETE /loan_prediction_train [status:404 request:0.010s]
DELETE /loan_prediction_test [status:404 request:0.009s]
3.2 鏈接Kibana
對loan_prediction_test重復上述4個步驟。 現(xiàn)在kibana已經(jīng)與訓練數(shù)據(jù)鏈接,并測試數(shù)據(jù)是否已經(jīng)存在于elastic search中。
3.3可視化
例一
選擇垂直條形圖,并選擇繪制Loan_status分布的訓練索引。
將y軸作為計數(shù),x軸代表貸款狀態(tài)
Voila!! Dashboard 生成啦!
例二
例三
類似的性別分布。這一次我們將使用餅圖。
最后,創(chuàng)建所有可視化的儀表板將如下所示!
是不是很漂亮!
剩下將由你來探索更多的elasticsearch和Kibana了,并創(chuàng)建多種多樣的可視化效果。
搜索欄允許用戶通過字符串來搜索來數(shù)據(jù),這便有助于我們理解數(shù)據(jù)中的更改,并在一個特定屬性中進行更改,這對于可視化來說是不容易的。
舉例
觀點:大多數(shù)信用記錄為0的客戶沒有收到貸款(貸款狀態(tài)為N = 92.1%)
以上為全文。
原文地址:
本文轉載自:36大數(shù)據(jù)
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn