Skip to content

Commit bf8ae5e

Browse files
authored
Merge pull request #307 from adityajai25/new
Prediction of CO2 emission
2 parents 5536127 + 5e51d05 commit bf8ae5e

File tree

9 files changed

+229
-0
lines changed

9 files changed

+229
-0
lines changed

Diff for: MachineLearning Projects/prediction-of-CO2-emission/FuelConsumption.csv

+1
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# prediction-of-CO2-emission
2+
3+
This repository contains a CO2 Emission Prediction Model developed using machine learning techniques. The model is designed to predict the CO2 emissions based on various input features. This Readme file provides an overview of the project, instructions for running the model, and additional information.
4+
5+
## Table of Contents
6+
- [Project Overview](#project-overview)
7+
- [Installation](#installation)
8+
- [Usage](#usage)
9+
- [Dataset](#dataset)
10+
- [Model Training](#model-training)
11+
- [Evaluation](#evaluation)
12+
- [Contributing](#contributing)
13+
- [License](#license)
14+
15+
## Project Overview
16+
The objective of this project is to build a machine learning model that can predict CO2 emissions based on certain features such as vehicle characteristics, fuel type, and engine size. The model is trained on a labeled dataset and uses regression techniques to make predictions.
17+
18+
## Installation
19+
To use the CO2 Emission Prediction Model, follow these steps:
20+
21+
1. Clone this repository to your local machine or download the source code as a ZIP file.
22+
2. Make sure you have Python 3.x installed on your system.
23+
3. Install the required dependencies by running the following command:
24+
25+
pip install -r requirements.txt
26+
27+
28+
## Usage
29+
1. Prepare your input data in a compatible format. Refer to the [Dataset](#dataset) section for more information on the input format.
30+
2. Run the prediction script using the following command:
31+
32+
python predict.py --input <path_to_input_data>
33+
34+
Replace `<path_to_input_data>` with the actual path to your input data file.
35+
3. The model will process the input data and generate CO2 emission predictions. The results will be displayed on the console.
36+
37+
## Dataset
38+
The CO2 Emission Prediction Model is trained on a dataset containing historical data of vehicles and their corresponding CO2 emissions. The dataset includes the following features:
39+
40+
- Vehicle make
41+
- Vehicle model
42+
- Vehicle type (e.g., car, truck, SUV)
43+
- Fuel type (e.g., petrol, diesel)
44+
- Engine size (in liters)
45+
46+
Each data point in the dataset consists of these features along with the CO2 emission value. The dataset is split into training and testing sets for model evaluation.
47+
48+
## Model Training
49+
The CO2 Emission Prediction Model is built using a machine learning algorithm such as linear regression or random forest regression. The training process involves the following steps:
50+
51+
1. Load the dataset and preprocess the data.
52+
2. Split the data into training and testing sets.
53+
3. Train the model using the training data.
54+
4. Evaluate the model performance on the testing data.
55+
56+
The trained model is then saved for later use in the prediction phase.
57+
58+
## Evaluation
59+
The performance of the CO2 Emission Prediction Model is evaluated using various metrics such as mean squared error (MSE), mean absolute error (MAE), and coefficient of determination (R-squared). These metrics provide insights into how well the model predicts the CO2 emissions.
60+
61+
## Contributing
62+
If you want to contribute to this project, you can follow these steps:
63+
64+
1. Fork this repository.
65+
2. Create a new branch for your feature or bug fix.
66+
3. Make your changes and commit them.
67+
4. Push your changes to your forked repository.
68+
5. Submit a pull request, describing your changes in detail and referencing any relevant issues.
69+
70+
## License
71+
The CO2 Emission Prediction Model is released under the [MIT License](LICENSE). You are free to use, modify, and distribute the code in this repository, subject to the terms and conditions of the license.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#import libraries
2+
import numpy as np
3+
from flask import Flask, request, jsonify, render_template
4+
import pickle
5+
6+
#Initialize the flask App
7+
app = Flask(__name__)
8+
model = pickle.load(open('model.pkl', 'rb'))
9+
10+
#default page of our web-app
11+
@app.route('/')
12+
def home():
13+
return render_template('index.html')
14+
15+
#To use the predict button in our web-app
16+
@app.route('/predict',methods=['POST'])
17+
def predict():
18+
'''
19+
For rendering results on HTML GUI
20+
'''
21+
int_features = [float(x) for x in request.form.values()]
22+
final_features = [np.array(int_features)]
23+
prediction = model.predict(final_features)
24+
25+
output = round(prediction[0], 2)
26+
27+
return render_template('index.html', prediction_text='CO2 Emission of the vehicle is :{}'.format(output))
28+
29+
if __name__ == "__main__":
30+
app.run(debug=True)
586 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pandas as pd
2+
from sklearn.linear_model import LinearRegression
3+
import pickle
4+
5+
df = pd.read_csv("FuelConsumption.csv")
6+
7+
# take a look at the dataset
8+
#df.head()
9+
10+
#use required features
11+
cdf = df[['ENGINESIZE','CYLINDERS','FUELCONSUMPTION_COMB','CO2EMISSIONS']]
12+
13+
#Training Data and Predictor Variable
14+
# Use all data for training (tarin-test-split not used)
15+
x = cdf.iloc[:, :3]
16+
y = cdf.iloc[:, -1]
17+
18+
19+
regressor = LinearRegression()
20+
21+
#Fitting model with trainig data
22+
regressor.fit(x, y)
23+
24+
# Saving model to disk
25+
# Pickle serializes objects so they can be saved to a file, and loaded in a program again later on.
26+
pickle.dump(regressor, open('model.pkl','wb'))
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
prediction-of-CO2-emission
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
html{
2+
background-color: #755139;
3+
overflow:hidden;
4+
}
5+
6+
.form-container {
7+
background-color: #755139;
8+
height: 100vh;
9+
width: 100vw;
10+
display: flex;
11+
align-items: center;
12+
justify-content: center;
13+
}
14+
15+
.form-wrapper {
16+
background-color: #F2EDD7;
17+
padding: 20px 60px;
18+
border-radius: 10px;
19+
display: flex;
20+
flex-direction: column;
21+
align-items: center;
22+
}
23+
24+
.logo {
25+
color: darkblue;
26+
font-weight: bold;
27+
font-size: 24px;
28+
}
29+
30+
form {
31+
display: flex;
32+
flex-direction: column;
33+
gap: 15px;
34+
}
35+
36+
input {
37+
background-color: #F2EDD7;
38+
color: darkblue;
39+
font-weight: bold;
40+
padding: 15px;
41+
border: none;
42+
outline: none;
43+
width: 250px;
44+
border-bottom: 1px solid #755139;
45+
&::placeholder {
46+
color: rgb(159, 113, 53);
47+
font-weight: none;
48+
}
49+
}
50+
51+
button {
52+
background-color: #755139;
53+
color: white;
54+
border-radius: 5%;
55+
padding: 10px;
56+
font-weight: bold;
57+
border: none;
58+
cursor: pointer;
59+
}
60+
61+
label {
62+
display: flex;
63+
align-items: center;
64+
gap: 10px;
65+
color: darkblue;
66+
font-size: 12px;
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<title>CO2 Emission Predictor</title>
6+
<link href='https://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'>
7+
<link href='https://fonts.googleapis.com/css?family=Arimo' rel='stylesheet' type='text/css'>
8+
<link href='https://fonts.googleapis.com/css?family=Hind:300' rel='stylesheet' type='text/css'>
9+
<link href='https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300' rel='stylesheet' type='text/css'>
10+
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
11+
</head>
12+
13+
<body>
14+
<div class = "form-container">
15+
<div class = "form-wrapper">
16+
<span class='logo'>Predict CO2 Emission of Vehicles</span>
17+
<span class='title'>Enter the following values to predict the CO2 emission from the vehicle</span>
18+
<form action="{{ url_for('predict')}}"method="post">
19+
<input type="text" name="enginesize" placeholder="Engine Size" required />
20+
<input type="text" name="cylinders" placeholder="Cylinders" required />
21+
<input type="text" name="fuel" placeholder="Fuel" required="required" />
22+
<button type="submit">Predict</button>
23+
</form>
24+
</div>
25+
<br>
26+
<br>
27+
{{ prediction_text }}
28+
29+
</div>
30+
31+
32+
</body>
33+
</html>

0 commit comments

Comments
 (0)