Code
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from palmerpenguins import load_penguins
from sklearn.datasets import load_digits, load_iris
from sklearn.linear_model import LinearRegression, LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.multiclass import OneVsRestClassifier
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler, label_binarize
# Load the Palmer Penguins dataset
penguin_df = load_penguins()[['flipper_length_mm', 'species']].dropna().copy()
# Create a binary label: 1 if Gentoo, 0 otherwise
penguin_df['is_gentoo'] = (penguin_df['species'] == 'Gentoo').astype(int)
penguin_df['class_name'] = np.where(
penguin_df['is_gentoo'] == 1,
'Gentoo',
'Not Gentoo'
)
# Use the same colours for the two classes in every figure.
not_gentoo_color = 'tab:red' # y = 0
gentoo_color = 'tab:blue' # y = 1
model_color = 'black'
# Separate features (X) and labels (y)
penguin_X = penguin_df[['flipper_length_mm']]
penguin_y = penguin_df['is_gentoo']
# Plot the distribution of flipper lengths by binary species label
plt.figure(figsize=(10, 6))
sns.histplot(
data=penguin_df,
x='flipper_length_mm',
hue='class_name',
hue_order=['Not Gentoo', 'Gentoo'],
kde=True,
bins=30,
palette={
'Not Gentoo': not_gentoo_color,
'Gentoo': gentoo_color,
}
)
plt.title('Distribution of Flipper Length (Gentoo vs. Others)')
plt.xlabel('Flipper Length (mm)')
plt.ylabel('Frequency')
plt.show()


















