Iml 51
Iml 51
Enrollment:226400307051
Subject : IML(4350702)
Faculty : J.A.Suthar
Introduction:
This project aims to predict vehicle fuel consumption using
machine learning, specifically **Polynomial Regression**. By
analyzing features like engine size, number of cylinders, highway
fuel efficiency, and emissions, the model can accurately forecast
fuel consumption. Additionally, it examines fuel consumption
trends over time, offering insights into changes in efficiency. This
model helps manufacturers, consumers, and policymakers make
better decisions, contributing to efforts in improving fuel efficiency
and reducing environmental impact.
1. Problem Definition
The goal of the project is to create a predictive model that can estimate
fuel consumption for vehicles given a set of features, such as:
- Engine size
- Number of cylinders
- Highway fuel consumption
- Combined fuel consumption
- Emissions
2. Dataset
The dataset (`Fuel_Consumption.csv`) contains information on different
vehicles and their corresponding fuel consumption and emissions. Key
columns include:
- ENGINE SIZE : Size of the engine in liters.
- CYLINDERS :Number of cylinders in the vehicle.
- HWY (L/100 km) : Fuel consumption on the highway.
- COMB (L/100 km) : Combined fuel consumption.
- EMISSIONS : Carbon emissions of the vehicle.
- FUEL CONSUMPTION : The target variable to predict, representing
fuel consumption.
- YEAR : The year the vehicle was manufactured, used for trend
analysis.
5.Expected Outcome
- The model will be able to accurately predict fuel consumption based on
vehicle characteristics.
- Insights into how fuel consumption has changed over the years will be
derived from the trend analysis.
- By comparing actual vs predicted fuel consumption, the model's
performance can be analyzed, and further improvements (e.g., adjusting
polynomial degrees or using other algorithms) can be considered.
CODE:
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler, PolynomialFeatures
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score, mean_squared_error
import matplotlib.pyplot as plt
csv_file_path = 'Fuel_Consumption.csv'
data = pd.read_csv(csv_file_path)
print("Data Preview:")
print(data.head())
features = ['ENGINE SIZE', 'CYLINDERS', 'HWY (L/100 km)', 'COMB
(L/100 km)', 'EMISSIONS']
target = 'FUEL CONSUMPTION'
year_column = 'YEAR'
X = data[features].copy()
y = data[target].copy()
X.fillna(0, inplace=True)
y.fillna(0, inplace=True)
poly = PolynomialFeatures(degree=2)
X_poly = poly.fit_transform(X)
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
model = LinearRegression()
model.fit(X_train_scaled, y_train)
y_pred = model.predict(X_test_scaled)
# Calculate and display R² score and RMSE
r2 = r2_score(y_test, y_pred)
rmse = np.sqrt(mean_squared_error(y_test, y_pred))
print(f"\nModel Accuracy (R² Score): {r2}")
print(f"Model RMSE (Root Mean Squared Error): {rmse}")
print("\nMake Predictions")
feature_values = []
for feature in features:
value = input(f"Enter value for {feature}: ")
feature_values.append(value)
input_data_poly = poly.transform(input_data)
input_data_scaled = scaler.transform(input_data_poly)
prediction = model.predict(input_data_scaled)
print(f"\nPredicted {target}: {prediction[0]}")
else:
print(f"Required columns are missing. Please ensure the dataset
contains the following columns: {', '.join(features)}, {target}.")
OUTPUT:
Conclusion :