<jupyter_start><jupyter_text>Module 7.2 | Apply Data Storytelling to Lending Club loan data Guiding Principles for EDA/ Visualizations1. Graphical Integrity2. Keep it simple3. Use the right display4. Use color strategically5. Tell a story with DataGuiding Principles for Effective Storytelling1. Audience (Know Your Audience)2. Engaging & Memorable3. Answer concise questions4. Carefully designed story (Beginning, Middle, End)5. Moves audience (call to action)Guiding Principles for Effective Presentations1. Clarity of Message (1 big idea)2. Clarity of Slides3. Clarity of DeliveryIMAC(Inferential Goal,Model,Algorithms, Conclusion & Checking)All models are wrong, some are useful. Data Source -- https://www.kaggle.com/wendykan/lending-club-loan-data<jupyter_code>%autosave 60
#import necessary modules
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
pd.set_option('max_columns', None)

import nltk
import collections as co
from wordcloud import WordCloud, STOPWORDS

%matplotlib inline
#read loans.csv as a dataframe
loans_df = pd.read_csv('loan.csv',low_memory=False, engine='c')
loans_df.info()
loans_df.head()
loans_df.describe()<jupyter_output><empty_output><jupyter_text>Q1. What is the the distribution of loans by loan amount?<jupyter_code>sns.set_style("ticks")

fig, axs = plt.subplots(2,1,figsize=(20,20))

sns.distplot(loans_df.loan_amnt, ax=axs[0], hist=True, kde=True, bins=40)
axs[0].set(xlabel='Loan Amount', 
       ylabel='% Distribution',title='Density Plot of Loan Amount')

sns.violinplot(loans_df.loan_amnt, ax=axs[1], color='0.6')
axs[1].set(xlabel='Loan Amount', 
       ylabel='Distribution',title='Violin Plot of Loan Amount')

sns.despine()

plt.show()
loans_df['loan_status'].unique()
#define a function to classify loan status into one of the following bins ('Fully Paid', 'Default', 'Current')
def loan_status_bin(text):
    if text in ('Fully Paid', 'Does not meet the credit policy. Status:Fully Paid'):
        return 'Fully Paid'
    elif text in ('Current', 'Issued'):
        return 'Current'
    elif text in ('Charged Off', 'Default', 'Does not meet the credit policy. Status:Charged Off'):
        return 'Default'
    elif text in ('Late (16-30 days)', 'Late (31-120 days)', 'In Grace Period'):
        return 'Late'
    else:
        'UNKNOWN STATUS'
#create a new attribute 'loan_status_bin' in the dataframe
loans_df['loan_status_bin']=loans_df['loan_status'].apply(loan_status_bin)
loans_df['loan_status_bin'].unique()<jupyter_output><empty_output><jupyter_text>Q2. What is the distribution of loans by loan status represented as a pie plot, and a violin plot?<jupyter_code>sns.set_style("ticks")
fig, axs = plt.subplots(1,2,figsize=(18,8))

loans_df.groupby('loan_status_bin').size().plot(kind='pie', ax=axs[0]);
axs[0].set(title='Pie Plot of Loan Status bin')

sns.violinplot(x=loans_df['term'], y=loans_df['loan_amnt'], hue=loans_df['loan_status_bin'], ax=axs[1])
axs[1].set(xlabel='Loan Status bin', 
       ylabel='Loan Amount',title='Violin Plot of Loan Term, Loan Status and Loan Amount')
axs[1].legend(loc=4)


sns.despine()

plt.show()<jupyter_output><empty_output><jupyter_text>Q3. Why are people borrowing money?<jupyter_code>plt.rcParams['figure.figsize'] = (16,16)
list_wc = list()
loans_df['title'].apply(lambda x: list_wc.append(x))
string_wc=str(list_wc)

wordcloud = WordCloud(stopwords=STOPWORDS, background_color='white', max_words=200, width=800, height=400).generate(string_wc)

plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()<jupyter_output><empty_output><jupyter_text>Q4. Who is borrowing money?<jupyter_code>int_rate, emp_length, home_ownership, addr_state, dti, term<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12754010695187165, 'fraction_numerical': 0.018449197860962566, 'mean_word_length': 6.208092485549133, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '6573', 'license': 'MIT', 'n_tokens_mistral': 1377, 'n_tokens_neox': 1301, 'n_words': 335, 'path': 'springboard_modules/the art of storytelling (Lending Club).ipynb', 'repo_name': 'tanaysd/Data-Science-Springboard', 'size': '3740'}