<jupyter_start><jupyter_text>1. Problem statement - We are tasked by a Fintech company to analyze mobile app behavior data to help direct customers to paid subscription services.   - The task is to identify which users are most likely NOT to enroll. - This notebook is for EDA  2. Importing libraries<jupyter_code>import pandas as pd
from dateutil import parser
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sn
# pd.set_option('display.max_columns', 12)
# pd.set_option('display.width', 1000)<jupyter_output><empty_output><jupyter_text>3. Read and View Data<jupyter_code>dataset = pd.read_csv('appdata10.csv')
dataset.head(5)<jupyter_output><empty_output><jupyter_text>4. Data distribution - Numerical Variables<jupyter_code>dataset.describe()<jupyter_output><empty_output><jupyter_text>5. Data quality check<jupyter_code>dataset.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 50000 entries, 0 to 49999
Data columns (total 12 columns):
user                    50000 non-null int64
first_open              50000 non-null object
dayofweek               50000 non-null int64
hour                    50000 non-null object
age                     50000 non-null int64
screen_list             50000 non-null object
numscreens              50000 non-null int64
minigame                50000 non-null int64
used_premium_feature    50000 non-null int64
enrolled                50000 non-null int64
enrolled_date           31074 non-null object
liked                   50000 non-null int64
dtypes: int64(8), object(4)
memory usage: 4.6+ MB<jupyter_text>6. Feature engineering<jupyter_code>dataset["hour"] = dataset.hour.str.slice(1, 3).astype(int)
dataset.head(5)<jupyter_output><empty_output><jupyter_text>Drop coumns<jupyter_code>dataset2 = dataset.copy().drop(columns = ['user', 'screen_list', 'enrolled_date',
                                           'first_open', 'enrolled'])
dataset2.head()<jupyter_output><empty_output><jupyter_text>8. Data distribution - Histograms<jupyter_code>f = plt.figure(figsize=(15,6))
f.suptitle('Histograms of Numerical Columns', fontsize=15)

for i in range(1, dataset2.shape[1] + 1):    
    plt.subplot(2, 4, i)
    #get current plot axes
    f = plt.gca()
#     f.axes.get_yaxis().set_visible(False)
    #set column name as title
    f.set_title(dataset2.columns.values[i - 1])

    vals = np.size(dataset2.iloc[:, i - 1].unique())
    
    plt.hist(dataset2.iloc[:, i - 1], bins=vals, color='#3F5D7D')
plt.tight_layout(rect=[0, 0.03, 1, 0.95])
plt.savefig('app_data_hist.jpg')<jupyter_output><empty_output><jupyter_text>9. Correlation with Response Variable<jupyter_code>dataset2.corrwith(dataset.enrolled).plot.bar(figsize=(12, 7),
                  title = 'Correlation with Reposnse Variable',
                  fontsize = 10, rot = 0,
                  grid = True)
plt.savefig('app_data_corr.jpg')<jupyter_output><empty_output><jupyter_text>10. Correlation matrix<jupyter_code>## Correlation Matrix
sn.set(style="white", font_scale=1.2)

# Compute the correlation matrix
corr = dataset2.corr()

# Generate a mask for the upper triangle
mask = np.zeros_like(corr, dtype=np.bool) #return a zero array with same size as corr
#set upper triangle as 0
mask[np.triu_indices_from(mask)] = True #Return the indices for the upper-triangle of arr

# Set up the matplotlib figure
f, ax = plt.subplots(figsize=(12, 8))
f.suptitle("Correlation Matrix", fontsize = 15)

# Generate a custom diverging colormap
cmap = sn.diverging_palette(220, 50, n=12, as_cmap=True)

# Draw the heatmap with the mask and correct aspect ratio
hmap = sn.heatmap(corr, mask=mask, cmap=cmap, vmax=.3, center=0,
            square=True, linewidths=.5, cbar_kws={"shrink": .5})
hmap.set_xticklabels(hmap.get_xticklabels(), rotation=15, horizontalalignment='right')
plt.savefig('app_data_corr_matrix.jpg')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11025244719216898, 'fraction_numerical': 0.04533745492014426, 'mean_word_length': 3.971830985915493, 'pattern_counts': {'":': 1, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '478513', 'license': 'MIT', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1287, 'n_words': 317, 'path': 'enrollment_prediction/App_enrollment_prediction_EDA.ipynb', 'repo_name': 'luke4u/Customer_Behaviour_Prediction', 'size': '3882'}