數據eda_銀行數據EDA:逐步

數據eda

This banking data was retrieved from Kaggle and there will be a breakdown on how the dataset will be handled from EDA (Exploratory Data Analysis) to Machine Learning algorithms.

該銀行數據是從Kaggle檢索的,將詳細介紹如何將數據集從EDA(探索性數據分析)轉換為機器學習算法。

腳步: (Steps:)

  1. Identification of variables and data types

    識別變量和數據類型
  2. Analyzing the basic metrics

    分析基本指標
  3. Non-Graphical Univariate Analysis

    非圖形單變量分析
  4. Graphical Univariate Analysis

    圖形單變量分析
  5. Bivariate Analysis

    雙變量分析
  6. Correlation Analysis

    相關分析

資料集: (Dataset:)

The dataset that will be used is from Kaggle. The dataset is a bank loan dataset, making the goal to be able to detect if someone will fully pay or charge off their loan.

將使用的數據集來自Kaggle 。 該數據集是銀行貸款數據集,其目標是能夠檢測某人是否將完全償還或償還其貸款。

The dataset consist of 100,000 rows and 19 columns. The predictor (dependent variable) will be “Loan Status,” and the features (independent variables) will be the remaining columns.

數據集包含100,000行和19列。 預測變量(因變量)將為“貸款狀態”,要素(因變量)將為剩余的列。

變量識別: (Variable Identification:)

Image for post

The very first step is to determine what type of variables we’re dealing with in the dataset.

第一步是確定數據集中要處理的變量類型。

df.head()
Image for post

We can see that there are some numeric and string (object) data types in our dataset. But to be certain, you can use:

我們可以看到我們的數據集中有一些數字和字符串(對象)數據類型。 但可以肯定的是,您可以使用:

df.info()  # Shows data types for each column
Image for post

This will give you further information about your variables, helping you figure out what will need to be changed in order to help your machine learning algorithm be able to interpret your data.

這將為您提供有關變量的更多信息,幫助您確定需要更改哪些內容,以幫助您的機器學習算法能夠解釋您的數據。

分析基本指標 (Analyzing Basic Metrics)

This will be as simple as using:

這就像使用以下命令一樣簡單:

df.describe().T
Image for post

This allows you to look at certain metrics, such as:

這使您可以查看某些指標,例如:

  1. Count — Amount of values in that column

    計數-該列中的值數量
  2. Mean — Avg. value in that column

    均值-平均 該列中的值
  3. STD(Standard Deviation) — How spread out your values are

    STD(標準偏差)—您的價值觀分布如何
  4. Min — The lowest value in that column

    最小值-該列中的最小值
  5. 25% 50% 70%— Percentile

    25%50%70%—百分位數
  6. Max — The highest value in that column

    最大值-該列中的最大值

From here you can identify what your values look like, and you can detect if there are any outliers.

在這里,您可以確定值的外觀,并可以檢測是否存在異常值。

From doing the .describe() method, you can see that there are some concerning outliers in Current Loan Amount, Credit Score, Annual Income, and Maximum Open Credit.

通過執行.describe()方法,您可以看到在當前貸款額,信用評分,年收入和最大未結信貸中存在一些與異常有關的問題。

非圖形單變量分析 (Non-Graphical Univariate Analysis)

Image for post

Univariate Analysis is when you look at statistical data in your columns.

單變量分析是當您查看列中的統計數據時。

This can be as simple as doing df[column].unique() or df[column].value_counts(). You’re trying to get as much information from your variables as possible.

這可以像執行df [column] .unique()或df [column] .value_counts()一樣簡單。 您正在嘗試從變量中獲取盡可能多的信息。

You also want to find your null values

您還想找到空值

df.isna().sum()
Image for post

This will show you the amount of null values in each column, and there are an immense amount of missing values in our dataset. We will look further into the missing values when doing Graphical Univariate Analysis.

這將向您顯示每列中的空值數量,并且我們的數據集中有大量的缺失值。 在進行圖形單變量分析時,我們將進一步研究缺失值。

圖形單變量分析 (Graphical Univariate Analysis)

Here is when we look at our variables using graphs.

這是我們使用圖形查看變量的時候。

We can use a bar plot in order to look at our missing values:

我們可以使用條形圖來查看缺失值:

fig, ax = plt.subplots(figsize=(15, 5))x = df.isna().sum().index
y = df.isna().sum()
ax.bar(x=x, height=y)
ax.set_xticklabels(x, rotation = 45)
plt.tight_layout();
Image for post

Moving past missing values, we can also use histograms to look at the distribution of our features.

超越缺失值后,我們還可以使用直方圖查看特征的分布。

df["Years of Credit History"].hist(bins=200)
Image for post
Histogram of Years of Credit History
信用歷史年直方圖

From this histogram you are able to detect if there are any outliers by seeing if it is left or right skew, and the one that we are looking at is a slight right skew.

從此直方圖中,您可以通過查看它是否是左偏斜或右偏斜來檢測是否存在異常值,而我們正在查看的是一個稍微偏斜的偏斜。

We ideally want our histograms for each feature to be close to a normal distribution as possible.

理想情況下,我們希望每個功能的直方圖盡可能接近正態分布。

# Checking credit score
df["Credit Score"].hist(bins=30)
Image for post

As we do the same thing for Credit Score, we can see that there is an immense right skew that rest in the thousands. This is very concerning because for our dataset, Credit Score is supposed to be at a 850 cap.

當我們對信用評分執行相同的操作時,我們可以看到存在成千上萬的巨大右偏。 這非常令人擔憂,因為對于我們的數據集而言,信用評分應設置為850上限。

Lets take a closer look:

讓我們仔細看看:

# Rows with a credit score greater than 850, U.S. highest credit score.
df.loc[df["Credit Score"] > 850]
Image for post
Using loc method to see rows with a Credit Score higher than 850
使用loc方法查看信用評分高于850的行

When using the loc method you are able to see all of the rows with a credit score greater than 850. We can see that this might be a human error because there are 0’s added on to the end of the values. This will be an easy fix once we get to processing the data.

使用loc方法時,您可以看到所有信用評分大于850的行。我們可以看到這可能是人為錯誤,因為在值的末尾添加了0。 一旦我們開始處理數據,這將是一個簡單的修復。

Another way to detect outliers are to use box plots and scatter plots.

檢測離群值的另一種方法是使用箱形圖和散點圖。

fig, ax = plt.subplots(4, 3)# Setting height and width of subplots
fig.set_figheight(15)
fig.set_figwidth(30)# Adding spacing between boxes
fig.tight_layout(h_pad=True, w_pad=True)sns.boxplot(bank_df["Number of Open Accounts"], ax=ax[0, 0])
sns.boxplot(bank_df["Current Loan Amount"], ax=ax[0, 1])
sns.boxplot(bank_df["Monthly Debt"], ax=ax[0, 2])
sns.boxplot(bank_df["Years of Credit History"], ax=ax[1, 0])
sns.boxplot(bank_df["Months since last delinquent"], ax=ax[1, 1])
sns.boxplot(bank_df["Number of Credit Problems"], ax=ax[1, 2])
sns.boxplot(bank_df["Current Credit Balance"], ax=ax[2, 0])
sns.boxplot(bank_df["Maximum Open Credit"], ax=ax[2, 1])
sns.boxplot(bank_df["Bankruptcies"], ax=ax[2, 2])
sns.boxplot(bank_df["Tax Liens"], ax=ax[3, 0])plt.show()
Image for post
Box plot of all numerical columns
所有數字列的箱形圖
fig, ax = plt.subplots(4, 3)# Setting height and width of subplots
fig.set_figheight(15)
fig.set_figwidth(30)# Adding spacing between boxes
fig.tight_layout(h_pad=True, w_pad=True)sns.scatterplot(data=bank_df["Number of Open Accounts"], ax=ax[0, 0])
sns.scatterplot(data=bank_df["Current Loan Amount"], ax=ax[0, 1])
sns.scatterplot(data=bank_df["Monthly Debt"], ax=ax[0, 2])
sns.scatterplot(data=bank_df["Years of Credit History"], ax=ax[1, 0])
sns.scatterplot(data=bank_df["Months since last delinquent"], ax=ax[1, 1])
sns.scatterplot(data=bank_df["Number of Credit Problems"], ax=ax[1, 2])
sns.scatterplot(data=bank_df["Current Credit Balance"], ax=ax[2, 0])
sns.scatterplot(data=bank_df["Maximum Open Credit"], ax=ax[2, 1])
sns.scatterplot(data=bank_df["Bankruptcies"], ax=ax[2, 2])
sns.scatterplot(data=bank_df["Tax Liens"], ax=ax[3, 0])plt.show()
Image for post
Scatter plot of numeric data
數值數據的散點圖

相關分析 (Correlation Analysis)

Correlation is when you want to detect how one variable reacts to another. What you don’t want is multicollinearity and to check for that you can use:

關聯是當您要檢測一個變量對另一個變量的React時。 您不想要的是多重共線性,并且可以使用以下方法進行檢查:

# Looking at mulitcollinearity
sns.heatmap(df.corr())
Image for post

翻譯自: https://medium.com/analytics-vidhya/bank-data-eda-step-by-step-67a61a7f1122

數據eda

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

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

相關文章

結構型模式之組合

重新看組合/合成(Composite)模式,發現它并不像自己想象的那么簡單,單純從整體和部分關系的角度去理解還是不夠的,并且還有一些通俗的模式講解類的書,由于其舉的例子太過“通俗”,以致讓人理解產…

計算機網絡原理筆記-三次握手

三次握手協議指的是在發送數據的準備階段,服務器端和客戶端之間需要進行三次交互: 第一次握手:客戶端發送syn包(synj)到服務器,并進入SYN_SEND狀態,等待服務器確認; 第二次握手:服務器收到syn包…

VB2010 的隱式續行(Implicit Line Continuation)

VB2010 的隱式續行(Implicit Line Continuation)許多情況下,您可以讓 VB 后一行繼續前一行的語句,而不必使用下劃線(_)。下面列舉出隱式續行語法的使用情形。1、逗號“,”之后PublicFunctionGetUsername(By…

flutter bloc_如何在Flutter中使用Streams,BLoC和SQLite

flutter blocRecently, I’ve been working with streams and BLoCs in Flutter to retrieve and display data from an SQLite database. Admittedly, it took me a very long time to make sense of them. With that said, I’d like to go over all this in hopes you’ll w…

leetcode 303. 區域和檢索 - 數組不可變

給定一個整數數組 nums,求出數組從索引 i 到 j(i ≤ j)范圍內元素的總和,包含 i、j 兩點。 實現 NumArray 類: NumArray(int[] nums) 使用數組 nums 初始化對象 int sumRange(int i, int j) 返回數組 nums 從索引 i …

Bigmart數據集銷售預測

Note: This post is heavy on code, but yes well documented.注意:這篇文章講的是代碼,但確實有據可查。 問題描述 (The Problem Description) The data scientists at BigMart have collected 2013 sales data for 1559 products across 10 stores in…

Android控制ScrollView滑動速度

翻閱查找ScrollView的文檔并搜索了一下沒有發現直接設置的屬性和方法,這里通過繼承來達到這一目的。 /*** 快/慢滑動ScrollView * author農民伯伯 * */public class SlowScrollView extends ScrollView {public SlowScrollView(Context context, Att…

數據特征分析-帕累托分析

帕累托分析(貢獻度分析):即二八定律 目的:通過二八原則尋找屬于20%的關鍵決定性因素。 隨機生成數據 df pd.DataFrame(np.random.randn(10)*10003000,index list(ABCDEFGHIJ),columns [銷量]) #避免出現負數 df.sort_values(銷量,ascending False,i…

leetcode 304. 二維區域和檢索 - 矩陣不可變(前綴和)

給定一個二維矩陣,計算其子矩形范圍內元素的總和,該子矩陣的左上角為 (row1, col1) ,右下角為 (row2, col2) 。 上圖子矩陣左上角 (row1, col1) (2, 1) ,右下角(row2, col2) (4, 3),該子矩形內元素的總和為 8。 示…

算法訓練營 重編碼_編碼訓練營后如何找到工作

算法訓練營 重編碼by Roxy Ayaz由Roxy Ayaz 編碼訓練營后如何找到工作 (How to get a job after a coding bootcamp) Getting a tech job after a coding bootcamp is very possible, but not necessarily pain-free.在編碼訓練營之后獲得技術工作是很有可能的,但不…

dt決策樹_決策樹:構建DT的分步方法

dt決策樹介紹 (Introduction) Decision Trees (DTs) are a non-parametric supervised learning method used for classification and regression. The goal is to create a model that predicts the value of a target variable by learning simple decision rules inferred f…

讀C#開發實戰1200例子記錄-2017年8月14日10:03:55

C# 語言基礎應用,注釋 "///"標記不僅僅可以為代碼段添加說明,它還有一項更重要的工作,就是用于生成自動文檔。自動文檔一般用于描述項目,是項目更加清晰直觀。在VisualStudio2015中可以通過設置項目屬性來生成自動文檔。…

iOS端(騰訊Bugly)閃退異常上報撲獲日志集成與使用指南

app已經上架并且有三次更新版本,今天市場部和顧客約談時,發現顧客的iphone 6 plus iOS 9.0.2上運行app點擊登錄按鈕時直接閃退,無法進入app里,這個問題還是第一次遇到,我下載了相應的模擬器版本, 并在上面運…

數據特征分析-正太分布

期望值,即在一個離散性隨機變量試驗中每次可能結果的概率乘以其結果的總和。 若隨機變量X服從一個數學期望為μ、方差為σ^2的正態分布,記為N(μ,σ^2),其概率密度函數為正態分布的期望值μ決定了其位置,其標準差σ決定…

leetcode 338. 比特位計數

給定一個非負整數 num。對于 0 ≤ i ≤ num 范圍中的每個數字 i ,計算其二進制數中的 1 的數目并將它們作為數組返回。 示例 1: 輸入: 2 輸出: [0,1,1] 示例 2: 輸入: 5 輸出: [0,1,1,2,1,2] 解題思路 偶數:和偶數除以2以后的數字,具有相…

r語言調用數據集中的數據集_自然語言數據集中未解決的問題

r語言調用數據集中的數據集Garbage in, garbage out. You don’t have to be an ML expert to have heard this phrase. Models uncover patterns in the data, so when the data is broken, they develop broken behavior. This is why researchers allocate significant reso…

為什么不應該使用(長期存在的)功能分支

Isn’t the git history in the picture above nice to work with? There are probably many problems in that repository, but one of them is most definitely the use of feature branches. Let’s see how such a bad thing became such a common practice.上面圖片中的g…

(轉) Spring 3 報org.aopalliance.intercept.MethodInterceptor問題解決方法

http://blog.csdn.net/henuhaigang/article/details/13678023 轉自CSDN博客,因為一個jar包沒引入困擾我好長時間 ,當時正在做spring AOP 的一個小測試,總在報錯,最后發現自己是問題3,引入一個jar包得到了解決 一 開發環…

數據特征分析-相關性分析

相關性分析是指對兩個或多個具備相關性的變量元素進行分析,從而衡量兩個變量的相關密切程度。 相關性的元素之間需要存在一定的聯系或者概率才可以進行相關性分析。 相關系數在[-1,1]之間。 一、圖示初判 通過pandas做散點矩陣圖進行初步判斷 df1 pd.DataFrame(np.…

leetcode 354. 俄羅斯套娃信封問題(dp+二分)

給定一些標記了寬度和高度的信封,寬度和高度以整數對形式 (w, h) 出現。當另一個信封的寬度和高度都比這個信封大的時候,這個信封就可以放進另一個信封里,如同俄羅斯套娃一樣。 請計算最多能有多少個信封能組成一組“俄羅斯套娃”信封&#…