鮮活數據數據可視化指南_數據可視化實用指南

鮮活數據數據可視化指南

Exploratory data analysis (EDA) is an essential part of the data science or the machine learning pipeline. In order to create a robust and valuable product using the data, you need to explore the data, understand the relations among variables, and the underlying structure of the data. One of the most effective tools in EDA is data visualization.

探索性數據分析(EDA)是數據科學或機器學習管道的重要組成部分。 為了使用數據創建強大而有價值的產品,您需要瀏覽數據,了解變量之間的關系以及數據的基礎結構。 數據可視化是EDA中最有效的工具之一。

Data visualizations tell us much more than plain numbers. They are also more likely to stick to your head. In this post, we will try to explore a customer churn dataset using the power of visualizations.

數據可視化告訴我們的不僅僅是單純的數字。 他們也更有可能堅持你的想法。 在本文中,我們將嘗試使用可視化功能探索客戶流失數據集 。

We will create many different visualizations and, on each one, try to introduce a feature of Matplotlib or Seaborn library.

我們將創建許多不同的可視化,并在每一個上嘗試引入Matplotlib或Seaborn庫的功能。

We start with importing related libraries and reading the dataset into a pandas dataframe.

我們首先導入相關的庫,然后將數據集讀取到pandas數據框中。

import pandas as pd
import numpy as npimport matplotlib.pyplot as plt
import seaborn as sns
sns.set(style='darkgrid')
%matplotlib inlinedf = pd.read_csv("/content/Churn_Modelling.csv")df.head()
Image for post

The dataset contains 10000 customers (i.e. rows) and 14 features about the customers and their products at a bank. The goal here is to predict whether a customer will churn (i.e. exited = 1) using the provided features.

該數據集包含10000個客戶(即行)和銀行中有關客戶及其產品的14個特征。 這里的目標是使用提供的功能預測客戶是否會流失(即退出= 1)。

Let’s start with a catplot which is a categorical plot of the Seaborn library.

讓我們從圖開始,這是Seaborn庫的分類圖。

sns.catplot(x='Gender', y='Age', data=df, hue='Exited', height=8, aspect=1.2)
Image for post

Finding: People between the ages of 45 and 60 are more likely to churn (i.e. leave the company) than other ages. There is not a considerable difference between females and males in terms of churning.

發現 :45至60歲的人比其他年齡段的人更容易流失(即離開公司)。 男性和女性在攪動方面沒有顯著差異。

The hue parameter is used to differentiate the data points based on a categorical variable.

hue參數用于基于分類變量來區分數據點。

The next visualization is the scatter plot which shows the relationship between two numerical variables. Let’s see if the estimated salary and balance of a customer are related.

下一個可視化是散點圖 ,它顯示了兩個數值變量之間的關系。 讓我們看看客戶的估計工資和余額是否相關。

plt.figure(figsize=(12,8))plt.title("Estimated Salary vs Balance", fontsize=16)sns.scatterplot(x='Balance', y='EstimatedSalary', data=df)
Image for post

We first used matplotlib.pyplot interface to create a Figure object and set the title. Then, we drew the actual plot on this figure object with Seaborn.

我們首先使用matplotlib.pyplot接口創建一個Figure對象并設置標題。 然后,我們使用Seaborn在此圖形對象上繪制了實際圖。

Finding: There is not a meaningful relationship or correlation between the estimated salary and balance. Balance seems to have a normal distribution (excluding the customers with zero balance).

調查結果 :估計的薪水和余額之間沒有有意義的關系或相關性。 余額似乎具有正態分布(不包括余額為零的客戶)。

The next visualization is the boxplot which shows the distribution of a variable in terms of median and quartiles.

下一個可視化效果是箱線圖 ,它以中位數和四分位數的形式顯示了變量的分布。

plt.figure(figsize=(12,8))ax = sns.boxplot(x='Geography', y='Age', data=df)ax.set_xlabel("Country", fontsize=16)
ax.set_ylabel("Age", fontsize=16)
Image for post

We also adjusted the font sizes of x and y axes using set_xlabel and set_ylabel.

我們還使用set_xlabelset_ylabel調整了x和y軸的字體大小

Here is the structure of boxplots:

這是箱線圖的結構:

Image for post
Image source)圖像來源 )

Median is the point in the middle when all points are sorted. Q1 (first or lower quartile) is the median of the lower half of the dataset. Q3 (third or upper quartile) is the median of the upper half of the dataset.

中點是對所有點進行排序時中間的點。 Q1(第一個或下一個四分位數)是數據集下半部分的中位數。 Q3(第三或上四分位數)是數據集上半部分的中位數。

Thus, boxplots give us an idea about the distribution and outliers. In the boxplot we created, there are many outliers (represented with dots) on top.

因此,箱線圖使我們對分布和異常值有了一個了解。 在我們創建的箱線圖中,頂部有許多離群值(以點表示)。

Finding: The distribution of the age variable is right-skewed. The mean is greater than the median due to the outliers on the upper side. There is not a considerable difference between countries.

結果 :年齡變量的分布右偏。 由于上側的異常值,平均值大于中位數。 各國之間沒有顯著差異。

Right-skewness can also be observed in the univariate distribution of a variable. Let’s create a distplot to observe the distribution.

右偏度也可以在變量的單變量分布中觀察到。 讓我們創建一個distplot來觀察分布。

plt.figure(figsize=(12,8))plt.title("Distribution of Age", fontsize=16)sns.distplot(df['Age'], hist=False)
Image for post

The tail on the right side is heavier than the one on the left. The reason is the outliers as we also observed on the boxplot.

右側的尾巴比左側的尾巴重。 原因是離群值,正如我們在箱線圖上所觀察到的。

The distplot also provides a histogram by default but we changed it using the hist parameter.

默認情況下,distplot還提供直方圖,但我們使用hist參數對其進行了更改。

Seaborn library also provides different types of pair plots which give an overview of pairwise relationships among variables. Let’s first take a random sample from our dataset to make the plots more appealing. The original dataset has 10000 observations and we will take a sample with 100 observations and 4 features.

Seaborn庫還提供了不同類型的成對圖,概述了變量之間的成對關系。 首先,我們從數據集中隨機抽取一個樣本,使圖更具吸引力。 原始數據集具有10000個觀測值,我們將抽取一個具有100個觀測值和4個特征的樣本。

subset=df[['CreditScore','Age','Balance','EstimatedSalary']].sample(n=100)g = sns.pairplot(subset, height=2.5)
Image for post

On the diagonal, we can see the histogram of variables. The other part of the grid represents pairwise relationships.

在對角線上,我們可以看到變量的直方圖。 網格的另一部分表示成對關系。

Another tool to observe pairwise relationships is the heatmap which takes a matrix and produces a color encoded plot. Heatmaps are mostly used to check correlations between features and the target variable.

觀察成對關系的另一個工具是熱圖 ,它采用矩陣并生成彩色編碼圖。 熱圖通常用于檢查要素與目標變量之間的相關性。

Let’s first create a correlation matrix of some features using the corr function of pandas.

首先,我們使用熊貓的corr函數創建一些要素的相關矩陣。

corr_matrix = df[['CreditScore','Age','Tenure','Balance',
'EstimatedSalary','Exited']].corr()

We can now plot this matrix.

現在我們可以繪制該矩陣。

plt.figure(figsize=(12,8))sns.heatmap(corr_matrix, cmap='Blues_r', annot=True)
Image for post

Finding: The “Age” and “Balance” columns are positively correlated with customer churn (“Exited”).

結果 :“年齡”和“平衡”列與客戶流失(“退出”)呈正相關。

As the amount of data increases, it gets trickier to analyze and explore it. There comes the power of visualizations which are great tools in exploratory data analysis when used efficiently and appropriately. Visualizations also help to deliver a message to your audience or inform them about your findings.

隨著數據量的增加,分析和探索數據變得更加棘手。 可視化的強大功能是有效和適當使用探索性數據分析的重要工具。 可視化還有助于向您的聽眾傳達信息或告知他們您的發現。

There is no one-fits-all kind of visualization method so certain tasks require different kinds of visualizations. Depending on the task, different options may be more suitable. What all visualizations have in common is that they are great tools for exploratory data analysis and the storytelling part of data science.

沒有一種萬能的可視化方法,因此某些任務需要不同類型的可視化。 根據任務,不同的選項可能更合適。 所有可視化的共同點在于,它們是探索性數據分析和數據科學講故事部分的出色工具。

Thank you for reading. Please let me know if you have any feedback.

感謝您的閱讀。 如果您有任何反饋意見,請告訴我。

翻譯自: https://towardsdatascience.com/a-practical-guide-for-data-visualization-9f1a87c0a4c2

鮮活數據數據可視化指南

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389811.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389811.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389811.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

2049. 統計最高分的節點數目

2049. 統計最高分的節點數目 給你一棵根節點為 0 的 二叉樹 ,它總共有 n 個節點,節點編號為 0 到 n - 1 。同時給你一個下標從 0 開始的整數數組 parents 表示這棵樹,其中 parents[i] 是節點 i 的父節點。由于節點 0 是根,所以 p…

Linux lsof命令詳解

lsof(List Open Files) 用于查看你進程開打的文件,打開文件的進程,進程打開的端口(TCP、UDP),找回/恢復刪除的文件。是十分方便的系統監視工具,因為lsof命令需要訪問核心內存和各種文件,所以需要…

史密斯臥推:杠鈴史密斯下斜臥推、上斜機臥推、平板臥推動作圖解

史密斯臥推:杠鈴史密斯下斜臥推、上斜機臥推、平板臥推動作圖解 史密斯臥推(smith press)是固定器械上完成的臥推,對于初級健身者來說,自由臥推(啞鈴臥推、杠鈴臥推)還不能很好地把握平衡性&…

圖像特征 可視化_使用衛星圖像可視化建筑區域

圖像特征 可視化地理可視化/菲律賓/遙感 (GEOVISUALIZATION / PHILIPPINES / REMOTE-SENSING) Big data is incredible! The way Big Data manages to bring sciences and business domains to new levels is almost sort of magical. It allows us to tap into a variety of a…

ELK入門01—Elasticsearch安裝

1. 安裝 首先從官網下載安裝包此處我們選擇2.4.6這個版本,然后下載tar壓縮包下載以后直接解壓,就算安裝完成了 tar zxvf elasticsearch-2.4.6.tar.gz 2. 配置 編輯elasticsearch配置文件 # 進入安裝目錄 cd elasticsearch-2.4.6 # 編輯配置文件 vi ./config/elastic…

375. 猜數字大小 II

375. 猜數字大小 II 我們正在玩一個猜數游戲,游戲規則如下: 我從 1 到 n 之間選擇一個數字。你來猜我選了哪個數字。如果你猜到正確的數字,就會 贏得游戲 。如果你猜錯了,那么我會告訴你,我選的數字比你的 更大或者更…

hdu_2048 錯排問題

錯排問題本質上就是一個動態規劃問題,其狀態轉移方程為: 記d[n]為n個人錯排情況的總數。 那么策略可以描述為:分析第n個人錯排的可能情況: 1)前n-1個人滿足錯排的情況,那么第n個人加入后還要錯排意味著第n個…

海量數據尋找最頻繁的數據_在數據中尋找什么

海量數據尋找最頻繁的數據Some activities are instinctive. A baby doesn’t need to be taught how to suckle. Most people can use an escalator, operate an elevator, and open a door instinctively. The same isn’t true of playing a guitar, driving a car, or anal…

OSChina 周四亂彈 —— 要成立復仇者聯盟了,來報名

2019獨角獸企業重金招聘Python工程師標準>>> Osc亂彈歌單(2018)請戳(這里) 【今日歌曲】 Devoes :分享吳若希的單曲《越難越愛 (Love Is Not Easy / TVB劇集《使徒行者》片尾曲)》: 《越難越愛 (Love Is No…

2023. 連接后等于目標字符串的字符串對

2023. 連接后等于目標字符串的字符串對 給你一個 數字 字符串數組 nums 和一個 數字 字符串 target ,請你返回 nums[i] nums[j] (兩個字符串連接)結果等于 target 的下標 (i, j) (需滿足 i ! j)的數目。 示例 1&…

webapi 找到了與請求匹配的多個操作(ajax報500,4的錯誤)

1、ajax報500,4的錯誤,然而多次驗證自己的后臺方法沒錯。然后跟蹤到如下圖的錯誤信息! 2、因為兩個函數都是無參的,返回值也一樣。如下圖 3,我給第一個函數加了一個參數后,就不報錯了,所以我想,…

可視化 nlp_使用nlp可視化尤利西斯

可視化 nlpMy data science experience has, thus far, been focused on natural language processing (NLP), and the following post is neither the first nor last which will include the novel Ulysses, by James Joyce, as its primary target for NLP and literary elu…

區分'方法'和'函數'

區分方法: 1在類中的叫方法,在類外面的叫函數 2在名字前加 對象名. 的叫方法, 在名字前加 類名. 或 只寫名字的 叫函數 通過代碼進行區分: 1 from types import MethodType,FunctionType 2 def check(arg): 3 if isinstance(arg,MethodType)#判斷第一個參數是否是第二個參數…

520. 檢測大寫字母

520. 檢測大寫字母 我們定義,在以下情況時,單詞的大寫用法是正確的: 全部字母都是大寫,比如 “USA” 。單詞中所有字母都不是大寫,比如 “leetcode” 。如果單詞不只含有一個字母,只有首字母大寫&#xf…

Java 打包 FatJar 方法小結

在函數計算(Aliyun FC)中發布一個 Java 函數,往往需要將函數打包成一個 all-in-one 的 zip 包或者 jar 包。Java 中這種打包 all-in-one 的技術常稱之為 Fatjar 技術。本文小結一下 Java 里打包 FatJar 的若干種方法。 什么是 FatJar FatJar 又稱作 uber-Jar&#x…

常見問題及解決方案(前端篇)

一、jquery validate 默認校驗規則序號 規則 描述1 requiredtrue 必須輸入的字段。2 remote "check.php" 使用 ajax 方法調用 check.php 驗證輸入值。3 emailtrue 必須輸入正確格式的電子郵件。4 urltrue 必須輸入正確格式的網址。5 datetrue 必須輸入正確格式的日期…

本地搜索文件太慢怎么辦?用Everything搜索秒出結果(附安裝包)

每次用電腦本地的搜索都慢的一批,后來發現了一個搜索利器 基本上搜索任何文件都不用等待。 并且頁面非常簡潔,也沒有任何廣告,用起來非常舒服。 軟件官網如下: voidtools 官網提供三個版本,用起來差別不大。 網盤鏈…

2024. 考試的最大困擾度

2024. 考試的最大困擾度 一位老師正在出一場由 n 道判斷題構成的考試,每道題的答案為 true (用 ‘T’ 表示)或者 false (用 ‘F’ 表示)。老師想增加學生對自己做出答案的不確定性,方法是 最大化 有 連續相…

小程序入口傳參:關于帶參數的小程序掃碼進入的方法

1.使用場景 1.醫院場景:比如每個醫生一個id,通過帶參數二維碼,掃碼二維碼就直接進入小程序醫生頁面 2.餐廳場景:比如每個菜一個二維碼,通過掃碼這個菜的二維碼,進入小程序后,可以直接點這道菜&a…

python的power bi轉換基礎

I’ve been having a great time playing around with Power BI, one of the most incredible things in the tool is the array of possibilities you have to transform your data.我在玩Power BI方面玩得很開心,該工具中最令人難以置信的事情之一就是您必須轉換數…