๐ Auto MPG Dataset
๐น Dataset Overview
| Feature | Description |
|---|
| Dataset Name | Auto MPG Dataset |
| Domain | Regression / Predictive Modeling |
| Number of Instances | 398 |
| Number of Attributes | 8 (including target) |
| Task | Predict fuel efficiency (MPG) |
๐ Context
The Auto MPG dataset is a classic dataset used in machine learning to predict a car’s fuel efficiency.
๐ฏ Target Variable
๐ Features (Attributes)
| No. | Attribute | Description |
|---|
| 1 | mpg ๐ฏ | Fuel efficiency (target variable) |
| 2 | cylinders | Number of engine cylinders |
| 3 | displacement | Engine size |
| 4 | horsepower | Engine power |
| 5 | weight | Vehicle weight |
| 6 | acceleration | Time to accelerate (0–60 mph approx.) |
| 7 | model_year | Year of manufacture |
| 8 | origin | Country of origin (1=USA, 2=Europe, 3=Asia) |
| 9 | car_name | Name of the car (categorical/text) |
⚠️ Data Characteristics
-
Some values (especially horsepower) may contain missing values (?)
-
car_name is textual → usually dropped or encoded
-
origin is categorical (numeric-coded)
๐งน Preprocessing Requirements
Typical steps:
-
Handle missing values (e.g., replace ? in horsepower)
-
Convert data types (string → numeric)
-
Drop irrelevant columns (car_name)
-
Encode categorical variables if needed
-
Feature scaling (optional)
๐ Example Use Cases
๐ฅ Dataset Source
Commonly available from:
import seaborn as sns
df = sns.load_dataset('mpg')
Upload the file to colab
Run the python code below and understand the data file
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Reading the data file
df = pd.read_csv("/content/auto-mpg.csv")
#print the datframe
print(df)
#printing the shape
print(df.shape)
#printing top 10 and bottom 10 rows
print(df.head(10))
print(df.tail(10))
#printing the columns
print(df.columns)
#print a feature value
print(df['mpg'])
# Selecting one input feature and target feature (dependent) for 150 rows only
X = df['displacement'].values.reshape(-1,1)
y = df['mpg'].values.reshape(-1, 1)
#visualizing these values
plt.scatter(X, y)
plt.xlabel("Displacement")
plt.ylabel("Miles per gallon")
plt.title("Scatter Plot of Miles per gallon vs displacement")
plt.show()
#printing the statistical summary
print(df.describe())
Output
mpg cylinders displacement horsepower weight acceleration \
0 18.0 8 307.0 130 3504 12.0
1 15.0 8 350.0 165 3693 11.5
2 18.0 8 318.0 150 3436 11.0
3 16.0 8 304.0 150 3433 12.0
4 17.0 8 302.0 140 3449 10.5
.. ... ... ... ... ... ...
393 27.0 4 140.0 86 2790 15.6
394 44.0 4 97.0 52 2130 24.6
395 32.0 4 135.0 84 2295 11.6
396 28.0 4 120.0 79 2625 18.6
397 31.0 4 119.0 82 2720 19.4
model year origin car name
0 70 1 chevrolet chevelle malibu
1 70 1 buick skylark 320
2 70 1 plymouth satellite
3 70 1 amc rebel sst
4 70 1 ford torino
.. ... ... ...
393 82 1 ford mustang gl
394 82 2 vw pickup
395 82 1 dodge rampage
396 82 1 ford ranger
397 82 1 chevy s-10
[398 rows x 9 columns]
(398, 9)
mpg cylinders displacement horsepower weight acceleration model year \
0 18.0 8 307.0 130 3504 12.0 70
1 15.0 8 350.0 165 3693 11.5 70
2 18.0 8 318.0 150 3436 11.0 70
3 16.0 8 304.0 150 3433 12.0 70
4 17.0 8 302.0 140 3449 10.5 70
5 15.0 8 429.0 198 4341 10.0 70
6 14.0 8 454.0 220 4354 9.0 70
7 14.0 8 440.0 215 4312 8.5 70
8 14.0 8 455.0 225 4425 10.0 70
9 15.0 8 390.0 190 3850 8.5 70
origin car name
0 1 chevrolet chevelle malibu
1 1 buick skylark 320
2 1 plymouth satellite
3 1 amc rebel sst
4 1 ford torino
5 1 ford galaxie 500
6 1 chevrolet impala
7 1 plymouth fury iii
8 1 pontiac catalina
9 1 amc ambassador dpl
mpg cylinders displacement horsepower weight acceleration \
388 26.0 4 156.0 92 2585 14.5
389 22.0 6 232.0 112 2835 14.7
390 32.0 4 144.0 96 2665 13.9
391 36.0 4 135.0 84 2370 13.0
392 27.0 4 151.0 90 2950 17.3
393 27.0 4 140.0 86 2790 15.6
394 44.0 4 97.0 52 2130 24.6
395 32.0 4 135.0 84 2295 11.6
396 28.0 4 120.0 79 2625 18.6
397 31.0 4 119.0 82 2720 19.4
model year origin car name
388 82 1 chrysler lebaron medallion
389 82 1 ford granada l
390 82 3 toyota celica gt
391 82 1 dodge charger 2.2
392 82 1 chevrolet camaro
393 82 1 ford mustang gl
394 82 2 vw pickup
395 82 1 dodge rampage
396 82 1 ford ranger
397 82 1 chevy s-10
Index(['mpg', 'cylinders', 'displacement', 'horsepower', 'weight',
'acceleration', 'model year', 'origin', 'car name'],
dtype='object')
0 18.0
1 15.0
2 18.0
3 16.0
4 17.0
...
393 27.0
394 44.0
395 32.0
396 28.0
397 31.0
Name: mpg, Length: 398, dtype: float64
mpg cylinders displacement weight acceleration \
count 398.000000 398.000000 398.000000 398.000000 398.000000
mean 23.514573 5.454774 193.425879 2970.424623 15.568090
std 7.815984 1.701004 104.269838 846.841774 2.757689
min 9.000000 3.000000 68.000000 1613.000000 8.000000
25% 17.500000 4.000000 104.250000 2223.750000 13.825000
50% 23.000000 4.000000 148.500000 2803.500000 15.500000
75% 29.000000 8.000000 262.000000 3608.000000 17.175000
max 46.600000 8.000000 455.000000 5140.000000 24.800000
model year origin
count 398.000000 398.000000
mean 76.010050 1.572864
std 3.697627 0.802055
min 70.000000 1.000000
25% 73.000000 1.000000
50% 76.000000 1.000000
75% 79.000000 2.000000
max 82.000000 3.000000
Comments
Post a Comment