<jupyter_start><jupyter_text>Load Data<jupyter_code>import seaborn as sns
sns.set()
import pandas as pd

df = pd.read_csv("../data/all.csv")
print (list(enumerate(df.columns)))
df['duration_min'] = df['duration_ms']/10**3/60

df = df.astype({'key': 'Int64', 'mode':'Int64', 'time_signature':'Int64'})


columns = ['Track_ID','Track_Name','Artists', 'Age','key','mode', 'time_signature', 
           'popularity','duration_min', 'danceability', 'energy', 'loudness',  'speechiness',
           'acousticness', 'instrumentalness', 'liveness', 'valence', 'tempo']

df = df[columns]
print (list(enumerate(df.columns)))
df.head(3)<jupyter_output><empty_output><jupyter_text>Inspect Linear Relationship between Variables<jupyter_code>#df.loc[:, 'Age':].corr() 

import matplotlib.pyplot as plt

plt.figure(figsize=(10,10)) 

numerical_columns = ['Age', 'popularity','duration_min', 'danceability', 'energy', 'loudness',  'speechiness',
           'acousticness', 'instrumentalness', 'liveness', 'valence', 'tempo']

df_num = df[numerical_columns]

sns.heatmap(df_num.corr(), 
            vmin=-1, vmax=1, cmap=sns.diverging_palette(20,200,as_cmap=True),
            annot = True, fmt=".1f")

plt.savefig('../figures/variable_correlation.png')<jupyter_output><empty_output><jupyter_text>Summary for Variable Correlation- `Age` is most positively correlated to `popularity` and `duration`, and most negatively related to `accousticness`.- `Energey` and `loudness` are the two most correlated variables.  Inspect Non-Linear Relationship between Variables<jupyter_code>sns.scatterplot(data= df, x='energy', y='loudness')
sns.boxplot(x="Age", y="popularity", data=df.dropna(), showfliers=False)
plt.savefig('../figures/age_vs_popularity.png')

sns.boxplot(x="Age", y="duration_min", data=df.dropna()); # keep outliers
sns.boxplot(x="Age", y="duration_min", data=df.dropna(), showfliers = False);   # remove outliers
plt.savefig('../figures/age_vs_song_duration.png')

df_age = df.groupby('Age').mean()
df_age.columns
plt.figure(figsize=(6,6)) 
sns.lineplot(data=df_age[['mode','danceability','valence']],markers=True, dashes=False)
plt.ylabel("Average");
plt.savefig('../figures/age_vs_mode.png')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18284424379232506, 'fraction_numerical': 0.011738148984198645, 'mean_word_length': 6.6678200692041525, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '636747', 'license': 'MIT', 'n_tokens_mistral': 857, 'n_tokens_neox': 791, 'n_words': 133, 'path': 'notebooks/2.2_Variables_Relation.ipynb', 'repo_name': 'ncchen55414/ChildrenSongRecommendation', 'size': '2215'}