Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

Repository files navigation

Penguins: A Machine Learning Example with the Palmer Penguins Dataset

This repository showcases essential machine learning workflows in Python using the famous Palmer Penguins dataset. The focus is on data preprocessing, exploration, visualization, and classification of penguin species with a KNeighborsClassifier.

Overview

The aim is to demonstrate the basic steps of a data science project—from data exploration and cleaning to model training and evaluation, entirely in Python.

Requirements

  • Python 3.x
  • numpy
  • pandas
  • seaborn
  • scikit-learn

note that sklearn is decprecated, use scikit-learn instead

To install required packages:

pip install numpy pandas seaborn scikit-learn

Dataset

The Palmer Penguins dataset provides physiological measurements and contextual information about three Antarctic penguin species: Adelie, Chinstrap, and Gentoo. The dataset can be loaded directly via Seaborn.

penguinDataset

Loading and Inspecting Data

import numpy as np
import pandas as pd
import seaborn as sns

df = sns.load_dataset("penguins")

Exploratory Data Analysis and Visualization

  • Overview and handling of missing values (via dropna)
  • Visualization: pairplot colored by species using Seaborn
sns.pairplot(data=df, hue="species")
penguinPairPlot

Feature Engineering

  • Remove non-numerical columns (island, sex)
  • Use only numerical features
df = df.drop(['island', 'sex'], axis=1)
df = df.dropna()

Modeling

  • Target variable: species
  • Features: bill length/depth, flipper length, body mass
from sklearn.model_selection import train_test_split

X = df.drop("species", axis=1)

y = df["species"]
features labels
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=119)

from sklearn.neighbors import KNeighborsClassifier

clf = KNeighborsClassifier(n_neighbors=3)
clf.fit(X_train, y_train)

Evaluation

  • Predictions and accuracy
from sklearn.metrics import accuracy_score

predictions = clf.predict(X_test)

print(accuracy_score(y_test, predictions)) # about 0.88

Results

The KNN model classifies penguin species in the test set with approximately 88% accuracy.

Contributors

Created by Klaus Fischer.

References

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages