<jupyter_start><jupyter_text>Data visualization--Analysis Distribution of Risk  E.g. Age Group [18-25):Student, [25,35):Yonge, [35,60):Adult, [60, ): Senior]  For Job: 0 - unskilled and non-resident, 1 - unskilled and resident, 2 - skilled, 3 - highly skilled Use charts to visulize1. Age Group to Risk 2. Gender to Risk3. Housing to Risk4. Job to Risk5. Saving Accounts to Risk6. Credit Amount to Housing-boxplot7. Job to Credit Amount8. Age to Credit Amount9. Any other things that revelent to analysis the relations between any of the columns10. Correlation between them<jupyter_code>data["Age_group"]=pd.cut(data["Age"], [18,25,35,60,100], labels=["Student","Yonge","Adult","Senior"])
#1, Age Group to Risk
plt.figure(figsize=(10,5))
sns.countplot(x="Age_group", hue="Risk", data=data)
plt.show()<jupyter_output><empty_output><jupyter_text>From the first bar chart, it can be inferred that the company should target on the group of "Yong" and "Adult". These two groups occupied the largest amount of customers. When compared with relatives between good and bad risk(the orange and blue bar), the"student" group is highly risky while the "Senior" one is more reliable.<jupyter_code>#2, Gender to Risk
sns.countplot(x="Sex", hue="Risk", data=data, palette="pastel")
plt.show()<jupyter_output><empty_output><jupyter_text>As we can see from the bar chart, the major gender of their customer is male. And the man has more relative risk than women. For the male customer, the good risk amount in the male group is more than double the bad risk, while it is just double in the female group.<jupyter_code>#3, Housing to Risk
sns.countplot(x="Housing", hue="Risk", data=data,palette="ch:.25")
plt.show()<jupyter_output><empty_output><jupyter_text>From the overall bar in three groups, the group of own housing is the majority of our customers. Furthermore, this kind of person has a relatively good risk than other groups, when compared with the bad risk. On the opposite, the people who do not have any house are the riskiest among the three groups.<jupyter_code>#4, Job to Risk
data["Job_group"]=pd.cut(data["Job"], [-1,0.5,1.5,2.5,3.5], labels=["unskilled and non-resident","unskilled and resident","skilled","highly skilled"])
plt.figure(figsize=(10,5))
sns.countplot(x="Job_group", hue="Risk", data=data, palette="Set3")
plt.show()<jupyter_output><empty_output><jupyter_text>Based on the chart, the skilled group occupied the largest group of job. The risk of people in different job levels on good risks relatively higher than that on bad risk.<jupyter_code>#5, Saving Accounts to Risk
sns.countplot(x="Saving accounts", hue="Risk", data=data, palette="husl")
plt.show()<jupyter_output><empty_output><jupyter_text>From what we can see from the diagram, most borrowers have little or no money on saving accounts. But those quite rich and rich people are the safe group, whose good risk is higher relatively than bad risk.<jupyter_code>#6, Credit Amount to Housing
sns.catplot(x="Housing", y="Credit amount", kind="box", data=data, palette="husl")
plt.show()<jupyter_output><empty_output><jupyter_text>From this boxplot, these people who do not have a house to live in are more likely to borrow a high amount of money.  Other stable people (own a house or rent a house ) would be at a lower amount of credit.<jupyter_code>#7, Job to Credit Amount
sns.catplot(x="Job_group", y="Credit amount", kind="swarm",data=data, height=5, aspect=1.5)
plt.show()<jupyter_output>/usr/local/lib/python3.6/dist-packages/seaborn/categorical.py:1296: UserWarning: 15.5% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.
  warnings.warn(msg, UserWarning)
/usr/local/lib/python3.6/dist-packages/seaborn/categorical.py:1296: UserWarning: 42.7% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.
  warnings.warn(msg, UserWarning)<jupyter_text>As we can see clearly from the boxplot, High skilled people will borrow a higher amount of money to satisfied their needs.  For people who do not have skills, they would live at a lower live standard and borrow a lower credit amount. They should targeted on the skilled person.<jupyter_code>#8, Age to Credit Amount 
sns.catplot(x="Age_group", y="Credit amount", kind="box", data=data, showfliers = False, palette="pastel")
plt.show()<jupyter_output><empty_output><jupyter_text>The group of younger and adult would borrow a higher amount than that of student and senior.  From these four groups, young people would borrow the highest amount of money, while the senior would borrow the lowest one.<jupyter_code>#9, Any other things that revelent to analysis the relations between any of the columns
#Job, Credit Amount to Risk
data["Checking account"]=data["Checking account"].fillna("none")
sns.catplot(x="Job", y="Credit amount", hue="Risk", kind="box", data=data, palette="Set1")
plt.show()<jupyter_output><empty_output><jupyter_text>From the job type of 2 and 3, we can infer from the diagram that the high amount they borrow, the worse risk the debit would be. This principle would be the opposite of other groups. Moreover, a highly skilled group (job_type3) is highest on the credit amount.<jupyter_code>#10, Dummy variable
data=data.merge(pd.get_dummies(data["Sex"], drop_first=True, prefix="Sex"),left_index=True, right_index=True)
data=data.merge(pd.get_dummies(data["Housing"], drop_first=True, prefix="Housing"),left_index=True, right_index=True)
data=data.merge(pd.get_dummies(data["Saving accounts"], drop_first=True, prefix="Saving accounts"),left_index=True, right_index=True)
data=data.merge(pd.get_dummies(data["Checking account"], drop_first=True, prefix="Checking account"),left_index=True, right_index=True)
data=data.merge(pd.get_dummies(data["Purpose"], drop_first=True, prefix="Purpose"),left_index=True, right_index=True)
data=data.merge(pd.get_dummies(data["Risk"], drop_first=True, prefix="Risk"),left_index=True, right_index=True)
# remove the categorical variable
data.drop(columns=["Sex", "Housing", "Saving accounts", "Checking account", "Purpose", "Risk","Job_group","Age_group"],inplace=True)
#correlation heatmap
plt.figure(figsize=(15,15))
sns.heatmap(data.astype(float).corr(), mask=np.triu(data.astype(float).corr()), cmap = sns.diverging_palette(230, 20, as_cmap=True), annot=True, fmt='.1g', square=True, linewidths=.5, cbar_kws={"shrink": .5})<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11712552496500234, 'fraction_numerical': 0.016487789702908696, 'mean_word_length': 6.591499409681228, 'pattern_counts': {'":': 1, '<': 40, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '561540', 'license': 'Apache-2.0', 'n_tokens_mistral': 2124, 'n_tokens_neox': 1996, 'n_words': 705, 'path': '_notebooks/Data visualization.ipynb', 'repo_name': 'joery15/workshop', 'size': '6429'}