Kaggle放大招:簡單幾步實現(xiàn)海量數(shù)據(jù)分析及可視化
近期,Kaggle發(fā)布了新的數(shù)據(jù)分析及可視化工具——Kaggle Kerneler bot,用戶只需上傳數(shù)據(jù)集,便可用Python為用戶自動獲取相關的深度數(shù)據(jù)分析結果。本文將帶領讀者體驗一下這款便捷而又高效的工具。
Kaggle Kerneler bot是一個自動生成的kernel,其中包含了演示如何讀取數(shù)據(jù)以及分析工作的starter代碼。用戶可以進入任意一個已經發(fā)布的項目,點擊頂部的“Fork Notebook”來編輯自己的副本。接下來,小編將以最熱門的兩個項目作為例子,帶領讀者了解該如何使用這款便捷的工具。
好的開始是成功的一半!
要開始這個探索性分析(exploratory analysis),首先需要導入一些庫并定義使用matplotlib繪制數(shù)據(jù)的函數(shù)。但要注意的是,并不是所有的數(shù)據(jù)分析結果圖像都能夠呈現(xiàn)出來,這很大程度上取決于數(shù)據(jù)本身(Kaggle Kerneler bot只是一個工具,不可能做到Jeff Dean或者Kaggle比賽選手們那么***的結果)。
In [1]:
- from mpl_toolkits.mplot3d import Axes3D
- from sklearn.decomposition import PCA
- from sklearn.preprocessing import StandardScaler
- import matplotlib.pyplot as plt plotting
- import numpy as np linear algebra
- import os accessing directory structure
- import pandas as pd data processing, CSV file I/O (e.g. pd.read_csv)
在本例中,一共輸入了12個數(shù)據(jù)集。
In [2]:
- print(os.listdir(&39;../input&39;))
- print(os.listdir(&39;../input/moeimouto-faces/moeimouto-faces/007_nagato_yuki&39;))
- print(os.listdir(&39;../input/moeimouto-faces/moeimouto-faces/046_alice_margatroid&39;))
- print(os.listdir(&39;../input/moeimouto-faces/moeimouto-faces/065_sanzenin_nagi&39;))
- print(os.listdir(&39;../input/moeimouto-faces/moeimouto-faces/080_koizumi_itsuki&39;))
- print(os.listdir(&39;../input/moeimouto-faces/moeimouto-faces/096_golden_darkness&39;))
- print(os.listdir(&39;../input/moeimouto-faces/moeimouto-faces/116_pastel_ink&39;))
- print(os.listdir(&39;../input/moeimouto-faces/moeimouto-faces/140_seto_san&39;))
- print(os.listdir(&39;../input/moeimouto-faces/moeimouto-faces/144_kotegawa_yui&39;))
- print(os.listdir(&39;../input/moeimouto-faces/moeimouto-faces/164_shindou_chihiro&39;))
- print(os.listdir(&39;../input/moeimouto-faces/moeimouto-faces/165_rollo_lamperouge&39;))
- print(os.listdir(&39;../input/moeimouto-faces/moeimouto-faces/199_kusugawa_sasara&39;))
- print(os.listdir(&39;../input/moeimouto-faces/moeimouto-faces/997_ana_coppola&39;))
接下里,用戶在編輯界面中會看到四個已經編好的代碼塊,它們定義了繪制數(shù)據(jù)的函數(shù)。而在發(fā)布后的頁面,這些代碼塊會被隱藏,如下圖所示,只需單擊已發(fā)布界面中的“code”按鈕就可以顯示隱藏的代碼。

準備就緒!讀取數(shù)據(jù)!
首先,讓我們先看一下輸入中的***個數(shù)據(jù)集:
In [7]:
- nRowsRead = 100 specify &39;None&39; if want to read whole file
- color.csv may have more rows in reality, but we are only loading/previewing the first 100 rows
- df1 = pd.read_csv(&39;../input/moeimouto-faces/moeimouto-faces/080_koizumi_itsuki/color.csv&39;, delimiter=&39;,&39;, nrows = nRowsRead)
- df1.dataframeName = &39;color.csv&39;
- nRow, nCol = df1.shape
- print(f&39;There are {nRow} rows and {nCol} columns&39;)

那么數(shù)據(jù)長什么樣子呢?
In [8]:
- df1.head(5)
Out [8]:

數(shù)據(jù)可視化:僅需簡單幾行!
樣本的柱狀圖:
In [9]:
- plotHistogram(df1, 10, 5)

二維和三維的PCA圖:
In [10]:
- plotPCA(df1, 2) 2D PCA
- plotPCA(df1, 3) 3D PCA


同理,更換數(shù)據(jù)集文件的路徑,也可以得到其它數(shù)據(jù)對應的結果。
當然,除了上述幾種可視化的結果外,根據(jù)輸入數(shù)據(jù)以及需求的不同,也可以得到其它數(shù)據(jù)分析可視化結果,例如:
相關矩陣:
In [11]:
- plotCorrelationMatrix(df1, 8)

散射和密度圖:
In [12]:
- plotScatterMatrix(df1, 20, 10)

針對數(shù)據(jù)分析、數(shù)據(jù)可視化工作,Kaggle kerneler bot應當說是相當?shù)谋憬莺透咝Я?。那么你是否也想嘗試一下呢?