Seaborn Datasets For Data Science

Seaborn, a Python data visualization library, offers a range of built-in datasets that are perfect for practicing and demonstrating various data science concepts. These datasets are designed to be simple, intuitive, and easy to work with, making them ideal for beginners and experienced data scientists alike.

In this article, we’ll explore the different datasets available in Seaborn, their characteristics, advantages, and disadvantages, and how they can be used for various data analysis and visualization tasks.

Seaborn Datasets For Data Science

  • 1. Tips Dataset
  • 2. Iris Dataset
  • 3. Penguins Dataset
  • 4. Flights Dataset
  • 5. Diamonds Dataset
  • 6. Titanic Dataset
  • 7. Exercise Dataset
  • 8. MPG Dataset
  • 9. Planets Dataset

1. Tips Dataset

The Tips dataset contains information about tips received by waitstaff in a restaurant. It’s commonly used for regression and exploratory data analysis (EDA). The dataset includes features such as total bill amount, tip amount, gender of the person paying the bill, whether the person is a smoker, day of the week, time of day, and size of the party.

Advantages: Simple and intuitive, good for demonstrating basic statistical analysis and visualization.
Disadvantages: Small size limits complexity of analyses, limited to restaurant tipping context.

Features and Characteristics

  • total_bill: Total bill amount (numerical)
  • tip: Tip amount (numerical)
  • sex: Gender of the person paying the bill (categorical)
  • smoker: Whether the person is a smoker (categorical)
  • day: Day of the week (categorical)
  • time: Time of day (Lunch/Dinner) (categorical)
  • size: Size of the party (numerical)

How to load Tips Dataset?

import seaborn as sns
tips = sns.load_dataset("tips")
print(tips.head())
total_bill tip sex smoker day time size
16.99 1.01 Female No Sun Dinner 2
10.34 1.66 Male No Sun Dinner 3
21.01 3.50 Male No Sun Dinner 3
23.68 3.31 Male No Sun Dinner 2
24.59 3.61 Female No Sun Dinner 4

2. Iris Dataset

The Iris dataset is one of the most famous datasets used in pattern recognition literature. It contains measurements of iris flowers from three different species. The dataset includes features such as sepal length, sepal width, petal length, petal width, and species of the iris flower.

Advantages: Widely used and well-understood, excellent for classification and clustering demonstrations.
Disadvantages: Small dataset, limited to flower measurements.

Features and Characteristics

  • sepal_length: Sepal length in cm (numerical)
  • sepal_width: Sepal width in cm (numerical)
  • petal_length: Petal length in cm (numerical)
  • petal_width: Petal width in cm (numerical)
  • species: Species of the iris flower (categorical)

How to load Iris Dataset?

iris = sns.load_dataset("iris")
print(iris.head())
sepal_length sepal_width petal_length petal_width species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa

3. Penguins Dataset

The Penguins dataset provides measurements for three species of penguins. It includes features such as species of the penguin, island where the penguin was observed, bill length, bill depth, flipper length, body mass, and sex of the penguin.

Advantages: Good for classification and clustering, richer and more diverse than the iris dataset.
Disadvantages: Contains missing values, limited to penguin measurements.

Features and Characteristics

  • species: Species of the penguin (categorical)
  • island: Island where the penguin was observed (categorical)
  • bill_length_mm: Bill length in mm (numerical)
  • bill_depth_mm: Bill depth in mm (numerical)
  • flipper_length_mm: Flipper length in mm (numerical)
  • body_mass_g: Body mass in grams (numerical)
  • sex: Sex of the penguin (categorical)

How to load Penguins Dataset?

penguins = sns.load_dataset("penguins")
print(penguins.head())
species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g sex
Adelie Torgersen 39.1 18.7 181 3750 Male
Adelie Torgersen 39.5 17.4 186 3800 Female
Adelie Torgersen 40.3 18.0 195 3250 Female
Adelie Torgersen nan nan nan nan nan
Adelie Torgersen 36.7 19.3 193 3450 Female

4. Flights Dataset

The Flights dataset includes information about the number of passengers on flights over a period of years. It includes features such as year of the observation, month of the observation, and number of passengers.

Advantages: Suitable for time series analysis, simple and easy to understand.
Disadvantages: Limited to passenger data, data is somewhat outdated.

Features and Characteristics

  • year: Year of the observation (numerical)
  • month: Month of the observation (categorical)
  • passengers: Number of passengers (numerical)

How to load flights dataset?

flights = sns.load_dataset("flights")
print(flights.head())
year month passengers
1949 Jan 112
1949 Feb 118
1949 Mar 132
1949 Apr 129
1949 May 121

5. Diamonds Dataset

The Diamonds dataset contains information about diamonds, including their characteristics and prices. It includes features such as carat weight, cut, color, clarity, depth, table, price, length, width, and depth in mm.

Advantages: Real-world dataset with diverse features, suitable for regression and clustering tasks.
Disadvantages: Large dataset with many features may require preprocessing, limited to diamond data.

Features and Characteristics

  • carat: Carat weight of the diamond (numerical)
  • cut: Quality of the cut (Fair, Good, Very Good, Premium, Ideal) (categorical)
  • color: Diamond color, from D (best) to J (worst) (categorical)
  • clarity: A measurement of how clear the diamond is (categorical)
  • depth: Total depth percentage (numerical)
  • table: Width of the top of the diamond relative to the widest point (numerical)
  • price: Price in US dollars (numerical)
  • x: Length in mm (numerical)
  • y: Width in mm (numerical)
  • z: Depth in mm (numerical)

How to load diamonds dataset?

diamonds = sns.load_dataset("diamonds")
print(diamonds.head())
carat cut color clarity depth table price x y z
0.23 Ideal E SI2 61.5 55 326 3.95 3.98 2.43
0.21 Premium E SI1 59.8 61 326 3.89 3.84 2.31
0.23 Good E VS1 56.9 65 327 4.05 4.07 2.31
0.29 Premium I VS2 62.4 58 334 4.20 4.23 2.63
0.29 Very Good J SI2 63.3 58 335 4.34 4.35 2.75

6. Titanic Dataset

The Titanic dataset contains information about passengers on the Titanic, including whether they survived or not. It includes features such as whether the passenger survived, ticket class, gender of the passenger, age of the passenger, number of siblings/spouses aboard the Titanic, number of parents/children aboard the Titanic, passenger fare, and port of embarkation.

Advantages: Rich dataset with various features, suitable for survival prediction and demographic analysis.
Disadvantages: Contains missing values, historical dataset may not represent modern demographics.

Features and Characteristics

  • survived: Whether the passenger survived (0 = No, 1 = Yes) (categorical)
  • pclass: Ticket class (1st, 2nd, 3rd) (categorical)
  • sex: Gender of the passenger (categorical)
  • age: Age of the passenger (numerical)
  • sibsp: Number of siblings/spouses aboard the Titanic (numerical)
  • parch: Number of parents/children aboard the Titanic (numerical)
  • fare: Passenger fare (numerical)
  • embarked: Port of embarkation (C = Cherbourg, Q = Queenstown, S = Southampton) (categorical)

How to load Titanic Dataset?

titanic = sns.load_dataset("titanic")
print(titanic.head())
survived pclass sex age sibsp parch fare embarked
0 3 male 22.0 1 0 7.25 S
1 1 female 38.0 1 0 71.3 C
1 3 female 26.0 0 0 7.92 S
1 1 female 35.0 1 0 53.1 S
0 3 male 35.0 0 0 8.05 S

7. Exercise Dataset

The Exercise dataset contains information about individuals’ pulse measurements after different types of exercise. It includes features such as participant ID, type of diet, pulse rate, time after exercise, and type of exercise.

Advantages: Good for time series analysis, simple and easy to understand.
Disadvantages: Limited to pulse measurements, small dataset.

Features and Characteristics

  • id: Participant ID (numerical)
  • diet: Type of diet (Low Fat or High Fat) (categorical)
  • pulse: Pulse rate (numerical)
  • time: Time after exercise (numerical)
  • kind: Type of exercise (categorical)

How to load Exercise Dataset?

exercise = sns.load_dataset("exercise")
print(exercise.head())
id diet pulse time kind
1 low 85 1 rest
1 low 85 15 rest
1 low 88 30 rest
1 low 90 45 rest
1 low 92 60 rest

8. MPG Dataset

The MPG dataset contains information about miles per gallon for different car models and their attributes. It includes features such as miles per gallon, number of cylinders in the engine, engine displacement, engine horsepower, vehicle weight, acceleration, model year, origin of the car, and car model name.

Advantages: Real-world dataset with diverse features, suitable for regression analysis and predicting fuel efficiency.
Disadvantages: Some missing values in the horsepower column, large dataset with many features.

Features and Characteristics

  • mpg: Miles per gallon (numerical)
  • cylinders: Number of cylinders in the engine (numerical)
  • displacement: Engine displacement in cubic inches (numerical)
  • horsepower: Engine horsepower (numerical)
  • weight: Vehicle weight in pounds (numerical)
  • acceleration: Acceleration in seconds from 0 to 60 mph (numerical)
  • model_year: Model year (categorical)
  • origin: Origin of the car (1 = American, 2 = European, 3 = Japanese) (categorical)
  • name: Car model name (string)

How to load MPG Dataset?

mpg = sns.load_dataset("mpg")
print(mpg.head())
mpg cylinders displacement horsepower weight acceleration model_year origin name
18.0 8 307.0 130.0 3504 12.0 70 1 chevrolet chevelle …
15.0 8 350.0 165.0 3693 11.5 70 1 buick skylark 320
18.0 8 318.0 150.0 3436 11.0 70 1 plymouth satellite …
16.0 8 304.0 150.0 3433 12.0 70 1 amc rebel sst
17.0 8 302.0 140.0 3449 10.5 70 1 ford torino

9. Planets Dataset

The Planets dataset includes information about exoplanets, such as their orbital periods and masses. It includes features such as method of detecting the exoplanet, number of planets in the system, orbital period, mass of the planet, and distance from Earth.

Advantages: Unique dataset in the field of astronomy, suitable for exploring exoplanet characteristics and trends.
Disadvantages: Limited to exoplanetary data, small dataset compared to other astronomical datasets.

Features and Characteristics

  • method: Method of detecting the exoplanet (categorical)
  • number: Number of planets in the system (numerical)
  • orbital_period: Orbital period in Earth days (numerical)
  • mass: Mass of the planet in Jupiter masses (numerical)
  • distance: Distance from Earth in light-years (numerical)

How to load Planets Dataset?

planets = sns.load_dataset("planets")
print(planets.head())
method number orbital_period mass distance
Radial Velocity 1 269.3 7.1 77.4
Radial Velocity 1 874.8 2.2 56.95
Radial Velocity 1 763.0 2.6 19.84
Radial Velocity 1 326.0 19.4 110.62
Radial Velocity 1 516.0 10.5 119.47

Conclusion

Seaborn’s built-in datasets provide valuable resources for practicing various data science techniques, from basic exploratory data analysis to advanced machine learning tasks. Each dataset has its own characteristics, advantages, and disadvantages, making them suitable for different applications.

By exploring and analyzing these datasets, you can gain valuable insights into data visualization, statistical analysis, and machine learning algorithms. Experimenting with different datasets and techniques is key to improving your data science skills and understanding real-world data.