
CDA數(shù)據(jù)分析師 出品
作者: tukey
數(shù)據(jù)科學(xué)愛好者知道,在將原始數(shù)據(jù)輸入到機(jī)器學(xué)習(xí)模型之前,需要對其進(jìn)行大量數(shù)據(jù)預(yù)處理。為此,需要遵循一系列標(biāo)準(zhǔn)來準(zhǔn)備數(shù)據(jù),具體取決于手頭問題的類型(回歸或分類)。這個過程的一個主要部分涉及以所有可能的方式評估數(shù)據(jù)集,以找到有價值的相關(guān)性(彼此和目標(biāo)之間的特征依賴性)并排除噪聲(不一致或異常值,即不合格的數(shù)據(jù)點(diǎn))。要探索任何數(shù)據(jù)集,Python 是可用的最強(qiáng)大的數(shù)據(jù)分析工具之一,此外,還有同樣強(qiáng)大的 Python 庫可以更好地可視化數(shù)據(jù)。
因此,為了使數(shù)據(jù)更有意義或從可用數(shù)據(jù)中提取更多價值,必須快速解釋和分析它。這是Python數(shù)據(jù)可視化庫通過生成圖形表示和讓數(shù)據(jù)說話所擅長的地方。通過這種方式,我們可以發(fā)現(xiàn)大量數(shù)據(jù)背后所有可能的趨勢和模式。
今天,數(shù)據(jù)科學(xué)和機(jī)器學(xué)習(xí)不僅僅適用于具有強(qiáng)大計算機(jī)科學(xué)背景的人。相反,歡迎來自不同行業(yè)的專業(yè)人士對數(shù)據(jù)有著相同的熱情,盡管他們具有一些統(tǒng)計知識,但這種趨勢正在增加。這就是為什么來自不同背景和教育背景的人傾向于嘗試數(shù)據(jù)科學(xué)和人工智能必須提供的東西。
但是對于剛剛開始使用機(jī)器學(xué)習(xí)的初學(xué)者來說,理解數(shù)據(jù)的選擇太多是具有挑戰(zhàn)性的,有時甚至是壓倒性的。我們都希望我們的數(shù)據(jù)看起來很漂亮并且可以展示,以便更快地做出決策。總體而言,EDA可能是一個耗時的過程,因為我們仔細(xì)查看多個圖以找出哪些特征是重要的并對結(jié)果產(chǎn)生重大影響。此外,我們尋找方法來處理缺失值和/或異常值、修復(fù)數(shù)據(jù)集中的不平衡以 及許多此類具有挑戰(zhàn)性的任務(wù)。因此,在選擇滿足 EDA 需求的最佳庫時,這是一個艱難的選擇。因此,對于任何開始機(jī)器學(xué)習(xí)之旅的人來說,從自動化 EDA 庫開始都是一種很好的學(xué)習(xí)體驗。這些庫提供了良好的數(shù)據(jù)整體視圖,并且易于使用。只需幾行簡單的 Python 代碼,這些庫就可以節(jié)省時間,并使新手能夠更加專注于了解如何使用這些不同的圖來理解數(shù)據(jù)。但是,初學(xué)者肯定需要對這些庫生成的圖有基本的了解。
在本文中,我們將為初學(xué)者討論三個有趣的自動EDA Python 庫。對于這個初學(xué)者友好的教程,我們將使用來自sklearn 的內(nèi)置“iris”數(shù)據(jù)集。
我們將首先導(dǎo)入包和庫
#loading the datasetfrom sklearn import datasets import pandas as pd print("pandas:",pd. version )
?pandas: 1.3.2
data = datasets.load_iris()df = pd.DataFrame(data.data,columns=data.feature_names) df['target'] = pd.Series(data.target)df.head()
如果我們不使用 AutoEDA,這里有一個通常用于 EDA 的命令列表,用于打印有關(guān) DataFrame/數(shù)據(jù)集的不同信息(不一定按相同的順序)。
查看我們必須使用多少命令才能在數(shù)據(jù)中找到洞察力。AutoEDA 庫可以通過幾行 Python 代碼快速完成所有這些以及更多工作。但在我們開始之前,讓我們先檢查安裝的 Python 版本,因為這些庫需要 Python >=3.6。要獲取版本信息,請在 Colab 中使用以下命令。
# python versionimport sys sys.version
'3.7.6 (default, Jan 8 2020, 19:59:22) n[GCC 7.3.0]'
確認(rèn)好了符合條件的Python 版本,現(xiàn)在就可以自動進(jìn)行EDA探索數(shù)據(jù)分析。
01、Pandas Pro?ling 3.0.0
import pandas_profiling print("pandas_profiling:",pandas_profiling. version )
pandas_profiling: 3.0.0
從報告中,初學(xué)者可以很容易地理解 iris 數(shù)據(jù)集中有 5 個變量——4 個數(shù)字變量,結(jié)果變量是分類變量。此外,數(shù)據(jù)集中有 150 個樣本并且沒有缺失值。
#Generating PandasProfiling Reportreport = pandas_profiling.ProfileReport(df) report
02、Sweetviz 2.1.3
這也是一個開源 Python 庫,僅使用兩行代碼即可執(zhí)行深入空格的 EDA。該庫為數(shù)據(jù)集生成的報告以 .html 文件形式提供,可以在任何瀏覽器中打開。使用 Sweetviz,我們可以檢查數(shù)據(jù)集特征如何與目標(biāo)值相關(guān)聯(lián)。
可視化測試和訓(xùn)練數(shù)據(jù)并比較它們。我們可以使用analyze()、compare() 或compare_intra() 來評估數(shù)據(jù)并生成報告繪制數(shù)值和分類變量的相關(guān)性。
總結(jié)有關(guān)缺失值、重復(fù)數(shù)據(jù)條目和頻繁條目的信息以及數(shù)值分析,即解釋統(tǒng)計值與前面的部分類似,我們將首先導(dǎo)入 pandas 來讀取和處理數(shù)據(jù)集。
接下來,我們只需導(dǎo)入 sweetviz 來探索數(shù)據(jù)。
import sweetviz as sv print("sweetviz :",sv. version )
sweetviz : 2.1.3
這就是經(jīng)典的的 Sweetviz 報告的樣式
#Generating Sweetviz reportreport = sv.analyze(df)report.show_html("iris_EDA_report.html") # specify a name for the report
| | [ 0%] 00:00 -> (? left)Report iris_EDA_report.html was generated! NOTEBOOK/COLAB USERS: the web browser MAY not pop
生成的這些 .html 報告您可以在當(dāng)前目錄下找到,然后可以在瀏覽器中打開報告。
03、AutoViz 0.0.83
另一個開源 Python EDA 庫,只需一行代碼即可快速分析任何數(shù)據(jù)。
# pip install autoviz# pip install wordcloud
from autoviz.AutoViz_Class import AutoViz_ClassAV = AutoViz_Class()
Imported AutoViz_Class version: 0.0.84. Call using: AV = AutoViz_Class()AV.AutoViz(filename, sep=',', depVar='', dfte=None, header=0, verbose=0,lowess=False,chart_format='svg',max_rows_analyzed=150000,max_cols Note: verbose=0 or 1 generates charts and displays them in your local Jupyter notebook.verbose=2 does not show plot but creates them and saves them in AutoViz_Plots directory
由于我們使用的是庫中的數(shù)據(jù)集,因此我們使用 'dfte' 選項而不是 EDA 的文件名。
#Generating AutoViz Report #this is the default command when using a file for the datasetfilename = "" sep = ","dft = AV.AutoViz( filename,sep=",",
depVar="", dfte=None, header=0, verbose=0, lowess=False, chart_format="svg",max_rows_analyzed=150000,max_cols_analyzed=30,)
Dataname input must be a filename with path to that file or a Dataframe Not able to read or load file. Please check your inputs and try again...
#Generating AutoViz Reportfilename = "" # empty string ("") as filename since no file is being used for the datasep = ","dft = AV.AutoViz( '',sep=",",depVar="", dfte=df, header=0,verbose=0, lowess=False, chart_format="svg",max_rows_analyzed=150000,max_cols_analyzed=30,
Shape of your Data Set loaded: (150, 5)############## C L A S S I F Y I N G V A R I A B L E S ####################Classifying variables in data set...Number of Numeric Columns = 4Number of Integer-Categorical Columns = 1 Number of String-Categorical Columns = 0 Number of Factor-Categorical Columns = 0 Number of String-Boolean Columns = 0 Number of Numeric-Boolean Columns = 0 Number of Discrete String Columns = 0 Number of NLP String Columns = 0Number of Date Time Columns = 0 Number of ID Columns = 0Number of Columns to Delete = 05 Predictors classified...This does not include the Target column(s)No variables removed since no ID or low-information variables found in data set Number of All Scatter Plots = 10
depVar="", dfte=None, header=0, verbose=0, lowess=False, chart_format="svg",max_rows_analyzed=150000,max_cols_analyzed=30,)
Dataname input must be a filename with path to that file or a Dataframe Not able to read or load file. Please check your inputs and try again...
#Generating AutoViz Reportfilename = "" # empty string ("") as filename since no file is being used for the datasep = ","dft = AV.AutoViz( '',sep=",",depVar="", dfte=df, header=0,verbose=0, lowess=False, chart_format="svg",max_rows_analyzed=150000,max_cols_analyzed=30,
Shape of your Data Set loaded: (150, 5)############## C L A S S I F Y I N G V A R I A B L E S ####################Classifying variables in data set...Number of Numeric Columns = 4Number of Integer-Categorical Columns = 1 Number of String-Categorical Columns = 0 Number of Factor-Categorical Columns = 0 Number of String-Boolean Columns = 0 Number of Numeric-Boolean Columns = 0 Number of Discrete String Columns = 0 Number of NLP String Columns = 0Number of Date Time Columns = 0 Number of ID Columns = 0Number of Columns to Delete = 05 Predictors classified...This does not include the Target column(s)No variables removed since no ID or low-information variables found in data set Number of All Scatter Plots = 10
Number of Columns to Delete = 05 Predictors classified...This does not include the Target column(s)No variables removed since no ID or low-information variables found in data set Number of All Scatter Plots = 10
Time to run AutoViz (in seconds) = 6.979###################### VISUALIZATION Completed ########################
AutoViz 報告包括有關(guān)數(shù)據(jù)集形狀的信息以及所有可能的圖表,包括條形圖、小提琴圖、相關(guān)矩陣(熱圖)、配對圖等。所有這些信息與一行代碼肯定對任何初學(xué)者都有用。
因此,我們使用三個 AutoEDA 庫以最少的代碼自動化了一個小數(shù)據(jù)集的數(shù)據(jù)分析。以上所有代碼都可以在原文鏈接中訪問。
結(jié)語
從初學(xué)者的?度來看,Pandas Pro?ling、Sweetviz 和 AutoViz 似乎是最簡單的生成報告以及呈現(xiàn)數(shù)據(jù)集洞察力的工具。在開始做數(shù)據(jù)探索時,我經(jīng)常使用這些庫以最少的代碼快速發(fā)現(xiàn)有趣的數(shù)據(jù)規(guī)律和趨勢。希望對你有用!
數(shù)據(jù)分析咨詢請掃描二維碼
若不方便掃碼,搜微信號:CDAshujufenxi
SQL Server 中 CONVERT 函數(shù)的日期轉(zhuǎn)換:從基礎(chǔ)用法到實戰(zhàn)優(yōu)化 在 SQL Server 的數(shù)據(jù)處理中,日期格式轉(zhuǎn)換是高頻需求 —— 無論 ...
2025-09-18MySQL 大表拆分與關(guān)聯(lián)查詢效率:打破 “拆分必慢” 的認(rèn)知誤區(qū) 在 MySQL 數(shù)據(jù)庫管理中,“大表” 始終是性能優(yōu)化繞不開的話題。 ...
2025-09-18CDA 數(shù)據(jù)分析師:表結(jié)構(gòu)數(shù)據(jù) “獲取 - 加工 - 使用” 全流程的賦能者 表結(jié)構(gòu)數(shù)據(jù)(如數(shù)據(jù)庫表、Excel 表、CSV 文件)是企業(yè)數(shù)字 ...
2025-09-18DSGE 模型中的 Et:理性預(yù)期算子的內(nèi)涵、作用與應(yīng)用解析 動態(tài)隨機(jī)一般均衡(Dynamic Stochastic General Equilibrium, DSGE)模 ...
2025-09-17Python 提取 TIF 中地名的完整指南 一、先明確:TIF 中的地名有哪兩種存在形式? 在開始提取前,需先判斷 TIF 文件的類型 —— ...
2025-09-17CDA 數(shù)據(jù)分析師:解鎖表結(jié)構(gòu)數(shù)據(jù)特征價值的專業(yè)核心 表結(jié)構(gòu)數(shù)據(jù)(以 “行 - 列” 規(guī)范存儲的結(jié)構(gòu)化數(shù)據(jù),如數(shù)據(jù)庫表、Excel 表、 ...
2025-09-17Excel 導(dǎo)入數(shù)據(jù)含缺失值?詳解 dropna 函數(shù)的功能與實戰(zhàn)應(yīng)用 在用 Python(如 pandas 庫)處理 Excel 數(shù)據(jù)時,“缺失值” 是高頻 ...
2025-09-16深入解析卡方檢驗與 t 檢驗:差異、適用場景與實踐應(yīng)用 在數(shù)據(jù)分析與統(tǒng)計學(xué)領(lǐng)域,假設(shè)檢驗是驗證研究假設(shè)、判斷數(shù)據(jù)差異是否 “ ...
2025-09-16CDA 數(shù)據(jù)分析師:掌控表格結(jié)構(gòu)數(shù)據(jù)全功能周期的專業(yè)操盤手 表格結(jié)構(gòu)數(shù)據(jù)(以 “行 - 列” 存儲的結(jié)構(gòu)化數(shù)據(jù),如 Excel 表、數(shù)據(jù) ...
2025-09-16MySQL 執(zhí)行計劃中 rows 數(shù)量的準(zhǔn)確性解析:原理、影響因素與優(yōu)化 在 MySQL SQL 調(diào)優(yōu)中,EXPLAIN執(zhí)行計劃是核心工具,而其中的row ...
2025-09-15解析 Python 中 Response 對象的 text 與 content:區(qū)別、場景與實踐指南 在 Python 進(jìn)行 HTTP 網(wǎng)絡(luò)請求開發(fā)時(如使用requests ...
2025-09-15CDA 數(shù)據(jù)分析師:激活表格結(jié)構(gòu)數(shù)據(jù)價值的核心操盤手 表格結(jié)構(gòu)數(shù)據(jù)(如 Excel 表格、數(shù)據(jù)庫表)是企業(yè)最基礎(chǔ)、最核心的數(shù)據(jù)形態(tài) ...
2025-09-15Python HTTP 請求工具對比:urllib.request 與 requests 的核心差異與選擇指南 在 Python 處理 HTTP 請求(如接口調(diào)用、數(shù)據(jù)爬取 ...
2025-09-12解決 pd.read_csv 讀取長浮點(diǎn)數(shù)據(jù)的科學(xué)計數(shù)法問題 為幫助 Python 數(shù)據(jù)從業(yè)者解決pd.read_csv讀取長浮點(diǎn)數(shù)據(jù)時的科學(xué)計數(shù)法問題 ...
2025-09-12CDA 數(shù)據(jù)分析師:業(yè)務(wù)數(shù)據(jù)分析步驟的落地者與價值優(yōu)化者 業(yè)務(wù)數(shù)據(jù)分析是企業(yè)解決日常運(yùn)營問題、提升執(zhí)行效率的核心手段,其價值 ...
2025-09-12用 SQL 驗證業(yè)務(wù)邏輯:從規(guī)則拆解到數(shù)據(jù)把關(guān)的實戰(zhàn)指南 在業(yè)務(wù)系統(tǒng)落地過程中,“業(yè)務(wù)邏輯” 是連接 “需求設(shè)計” 與 “用戶體驗 ...
2025-09-11塔吉特百貨孕婦營銷案例:數(shù)據(jù)驅(qū)動下的精準(zhǔn)零售革命與啟示 在零售行業(yè) “流量紅利見頂” 的當(dāng)下,精準(zhǔn)營銷成為企業(yè)突圍的核心方 ...
2025-09-11CDA 數(shù)據(jù)分析師與戰(zhàn)略 / 業(yè)務(wù)數(shù)據(jù)分析:概念辨析與協(xié)同價值 在數(shù)據(jù)驅(qū)動決策的體系中,“戰(zhàn)略數(shù)據(jù)分析”“業(yè)務(wù)數(shù)據(jù)分析” 是企業(yè) ...
2025-09-11Excel 數(shù)據(jù)聚類分析:從操作實踐到業(yè)務(wù)價值挖掘 在數(shù)據(jù)分析場景中,聚類分析作為 “無監(jiān)督分組” 的核心工具,能從雜亂數(shù)據(jù)中挖 ...
2025-09-10統(tǒng)計模型的核心目的:從數(shù)據(jù)解讀到?jīng)Q策支撐的價值導(dǎo)向 統(tǒng)計模型作為數(shù)據(jù)分析的核心工具,并非簡單的 “公式堆砌”,而是圍繞特定 ...
2025-09-10