<jupyter_start><jupyter_text>The blood transfusion datasetIn this notebook, we will present the "blood transfusion" dataset. Thisdataset is locally available in the directory `datasets` and it is stored asa comma separated value (CSV) file. We start by loading the entire dataset.<jupyter_code>import pandas as pd

blood_transfusion = pd.read_csv("../datasets/blood_transfusion.csv")<jupyter_output><empty_output><jupyter_text>We can have a first look at the at the dataset loaded.<jupyter_code>blood_transfusion.head()<jupyter_output><empty_output><jupyter_text>In this dataframe, we can see that the last column correspond to the targetto be predicted called `"Class"`. We will create two variables, `data` and`target` to separate the data from which we could learn a predictive modeland the `target` that should be predicted.<jupyter_code>data = blood_transfusion.drop(columns="Class")
target = blood_transfusion["Class"]<jupyter_output><empty_output><jupyter_text>Let's have a first look at the `data` variable.<jupyter_code>data.head()<jupyter_output><empty_output><jupyter_text>We observe four columns. Each record corresponds to a person that intendedto give blood. The information stored in each column are:* `Recency`: the time in months since the last time a person intended to  give blood;* `Frequency`: the number of time a person intended to give blood in the   past;* `Monetary`: the amount of blood given in the past (in c.c.);* `Time`: the time in months since the first time a person intended to give  blood.Now, let's have a look regarding the type of data that we are dealing inthese columns and if any missing values are present in our dataset.<jupyter_code>data.info()<jupyter_output><empty_output><jupyter_text>Our dataset is made of 748 samples. All features are represented with integernumbers and there is no missing values. We can have a look at each featuredistributions.<jupyter_code>_ = data.hist(figsize=(12, 10), bins=30, edgecolor="black", density=True)<jupyter_output><empty_output><jupyter_text>There is nothing shocking regarding the distributions. We only observe a highvalue range for the features `"Recency"`, `"Frequency"`, and `"Monetary"`. Itmeans that we have a few extreme high values for these features.Now, let's have a look at the target that we would like to predict for thistask.<jupyter_code>target.head()
import matplotlib.pyplot as plt

target.value_counts(normalize=True).plot.barh()
plt.xlabel("Number of samples")
_ = plt.title("Class distribution")<jupyter_output><empty_output><jupyter_text>We see that the target is discrete and contains two categories: whether aperson `"donated"` or `"not donated"` his/her blood. Thus the task to besolved is a classification problem. We should note that the class counts ofthese two classes is different.<jupyter_code>target.value_counts(normalize=True)<jupyter_output><empty_output><jupyter_text>Indeed, ~76% of the samples belong to the class `"not donated"`. It is ratherimportant: a classifier that would predict always this `"not donated"` classwould achieve an accuracy of 76% of good classification without using anyinformation from the data itself. This issue is known as class imbalance. Oneshould take care about the statistical performance metric used to evaluate amodel as well as the predictive model chosen itself.Now, let's have a naive analysis to see if there is a link between featuresand the target using a pair plot representation.<jupyter_code>import seaborn as sns

_ = sns.pairplot(blood_transfusion, hue="Class")<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup