<jupyter_start><jupyter_text>Exploratory Data Analysis  1. Data Description- This dataset described whether an individual donates blood or not based on past donation history.- This is a dataset that originally from the paper *<NAME>, Yang, King-Jang, and <NAME>, "Knowledge discovery on RFM model using Bernoulli sequence," Expert Systems with Applications, 2008* and can be found on the UCI machine learning repository at: https://archive.ics.uci.edu/ml/datasets/Blood+Transfusion+Service+Center.  2. Load the Dataset<jupyter_code>import datapackage
import pandas as pd
from sklearn.model_selection import train_test_split
import altair as alt 
data_url = 'https://datahub.io/machine-learning/blood-transfusion-service-center/datapackage.json'

# to load Data Package into storage
package = datapackage.Package(data_url)

# to load only tabular data
resources = package.resources
for resource in resources:
    if resource.tabular:
        blood_df = pd.read_csv(resource.descriptor['path'])
blood_df.head()
X = blood_df.iloc[:,0:-1]
y = blood_df.iloc[:,-1]
# split training and testing
X_train, X_test, y_train, y_test = train_test_split(X,
                                                    y,
                                                    test_size=0.2, random_state = 123)
blood_df_train = X_train
blood_df_train = pd.merge(blood_df_train, y_train, left_index=True, right_index=True)
blood_df_train.head()
blood_df_train = blood_df_train.rename(columns={"V1": "since_last_don", "V2": "total_dons", "V3": "total_blood", "V4": "since_first_don"})<jupyter_output><empty_output><jupyter_text>3. Explore the Dataset<jupyter_code>blood_df_train.isna().any()<jupyter_output><empty_output><jupyter_text>> We can see that there are no missing values in our dataset.<jupyter_code>print(blood_df_train.shape)
print(blood_df_train.columns)<jupyter_output>(598, 5)
Index(['since_last_don', 'total_dons', 'total_blood', 'since_first_don',
       'Class'],
      dtype='object')<jupyter_text>> The dataset has 5 columns, 4 different features and our target which is whether they have donated or not, represented by a binary variable with 1 being not donated and 2 being donated. The `since_last_don` and `since_first_don` columns are time in months.<jupyter_code>#general summary for all data
blood_df_train.describe()
#Summary for positive class, which is not donated
blood_df_train[blood_df_train['Class']==1].describe()
#Summary for negative class, which is Donated
blood_df_train[blood_df_train['Class']==2].describe()<jupyter_output><empty_output><jupyter_text>Comparing the summary for donated vs not donated class. We can see that around 3 times as many people did not donate, than those who did.  4. Data Visualizations<jupyter_code>blood_df_train
alt.Chart(blood_df_train).mark_bar().encode(
    alt.X("since_last_don"),
    alt.Y("count()", title = "Number of Donors"),
).properties(title = "Donor Recency Distribution")
alt.Chart(blood_df_train).mark_bar().encode(
    alt.X("total_dons"),
    alt.Y("count()", title = "Number of Donors"),
).properties(title = "Donor Frequency Distribution")
alt.Chart(blood_df_train).mark_bar().encode(
    alt.X("total_blood"),
    alt.Y("count()", title = "Number of Donors"),
).properties(title = "Donor Monetary Distribution")
alt.Chart(blood_df_train).mark_bar(opacity = 0.7).encode(
    alt.X("since_first_don"),
    alt.Y('count()', stack=None),
    color=alt.Color('Class', scale=alt.Scale(scheme='goldorange'))
).properties(title = "Donor Recency Distribution")
alt.Chart(blood_df_train).mark_bar(opacity = 0.7).encode(
    alt.X("total_dons"),
    alt.Y('count()', stack=None),
    color=alt.Color('Class', scale=alt.Scale(scheme='goldorange'))
).properties(title = "Donor Frequency Distribution")
alt.Chart(blood_df_train).mark_bar(opacity = 0.7).encode(
    alt.X("total_blood"),
    alt.Y('count()', stack=None),
    color=alt.Color('Class', scale=alt.Scale(scheme='goldorange'))
).properties(title = "Donor Monetary Distribution")
alt.Chart(blood_df_train).mark_bar(opacity = 0.7).encode(
    alt.X("since_first_don"),
    alt.Y('count()', stack=None),
    color=alt.Color('Class', scale=alt.Scale(scheme='goldorange'))
).properties(title = "Donor Time Distribution")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13023037141513868, 'fraction_numerical': 0.009167842031029619, 'mean_word_length': 5.3224368499257055, 'pattern_counts': {'":': 4, '<': 22, '<?xml version=': 0, '>': 24, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '48617', 'license': 'MIT', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1349, 'n_words': 329, 'path': 'src/EDA.ipynb', 'repo_name': 'evelynmoorhouse/mds522_305', 'size': '4268'}