44 KiB
Seaborn Exercises¶
Imports¶
Run the cell below to import the libraries
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
The Data¶
DATA SOURCE: https://www.kaggle.com/rikdifos/credit-card-approval-prediction
Data Information:
Credit score cards are a common risk control method in the financial industry. It uses personal information and data submitted by credit card applicants to predict the probability of future defaults and credit card borrowings. The bank is able to decide whether to issue a credit card to the applicant. Credit scores can objectively quantify the magnitude of risk.
Feature Information:
application_record.csv | ||
---|---|---|
Feature name | Explanation | Remarks |
ID |
Client number | |
CODE_GENDER |
Gender | |
FLAG_OWN_CAR |
Is there a car | |
FLAG_OWN_REALTY |
Is there a property | |
CNT_CHILDREN |
Number of children | |
AMT_INCOME_TOTAL |
Annual income | |
NAME_INCOME_TYPE |
Income category | |
NAME_EDUCATION_TYPE |
Education level | |
NAME_FAMILY_STATUS |
Marital status | |
NAME_HOUSING_TYPE |
Way of living | |
DAYS_BIRTH |
Birthday | Count backwards from current day (0), -1 means yesterday |
DAYS_EMPLOYED |
Start date of employment | Count backwards from current day(0). If positive, it means the person currently unemployed. |
FLAG_MOBIL |
Is there a mobile phone | |
FLAG_WORK_PHONE |
Is there a work phone | |
FLAG_PHONE |
Is there a phone | |
FLAG_EMAIL |
Is there an email | |
OCCUPATION_TYPE |
Occupation | |
CNT_FAM_MEMBERS |
Family size |
df = pd.read_csv('application_record.csv')
df.head()
df.info()
TASKS¶
Recreate the plots shown in the markdown image cells. Each plot also contains a brief description of what it is trying to convey. Note, these are meant to be quite challenging. Start by first replicating the most basic form of the plot, then attempt to adjust its styling and parameters to match the given image.¶
In general do not worry about coloring,styling, or sizing matching up exactly. Instead focus on the content of the plot itself. Our goal is not to test you on recognizing figsize=(10,8) , its to test your understanding of being able to see a requested plot, and reproducing it.
NOTE: You may need to perform extra calculations on the pandas dataframe before calling seaborn to create the plot.
TASK: Recreate the Scatter Plot shown below¶
The scatterplot attempts to show the relationship between the days employed versus the age of the person (DAYS_BIRTH) for people who were not unemployed. Note, to reproduce this chart you must remove unemployed people from the dataset first. Also note the sign of the axis, they are both transformed to be positive. Finally, feel free to adjust the alpha and linewidth parameters in the scatterplot since there are so many points stacked on top of each other.
# CODE HERE TO RECREATE THE PLOT SHOWN ABOVE
TASK: Recreate the Distribution Plot shown below:¶
Note, you will need to figure out how to calculate "Age in Years" from one of the columns in the DF. Think carefully about this. Don't worry too much if you are unable to replicate the styling exactly.
# CODE HERE TO RECREATE THE PLOT SHOWN ABOVE
TASK: Recreate the Categorical Plot shown below:¶
This plot shows information only for the bottom half of income earners in the data set. It shows the boxplots for each category of NAME_FAMILY_STATUS column for displaying their distribution of their total income. Note: You will need to adjust or only take part of the dataframe before recreating this plot. You may want to explore the order parameter to get the xticks in the exact order shown here
# CODE HERE
TASK: Recreate the Heat Map shown below:¶
This heatmap shows the correlation between the columns in the dataframe. You can get correlation with .corr() , also note that the FLAG_MOBIL column has NaN correlation with every other column, so you should drop it before calling .corr().
# CODE HERE