数据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.mzph.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) 出现。当另一个信封的宽度和高度都比这个信封大的时候,这个信封就可以放进另一个信封里,如同俄罗斯套娃一样。 请计算最多能有多少个信封能组成一组“俄罗斯套娃”信封&#…