Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 1 10:23:24 2021

@author: Acer
"""
from flask import Flask, render_template, request , jsonify
import requests
import numpy as np
import sklearn
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression
from joblib import load

app = Flask(__name__)
app.config['SECRET_KEY']='mukul'

@app.route('/',methods=['GET'])
def Home():
return render_template('mainpafe.html')



standard_to = StandardScaler()
@app.route("/predict", methods=['POST'])
def predict():

if request.method == 'POST':
Highway_mpg=float(request.form['milage'])
engine_size=int(request.form['size_of_the_engine'])
curb_weight=int(request.form['weight_of_a_car'])
horse_power=int(request.form['power'])
model =load('model_final.joblib')
prediction=model.predict([[Highway_mpg,engine_size,curb_weight,horse_power]])
output=round(prediction[0],2)
if output<0:
return render_template('mainpafe.html',prediction_texts="Sorry you cannot sell this car")
else:
return render_template('mainpafe.html',prediction_text="You Can Sell The Car at ${}".format(output))
else:
return render_template('mainpafe.html')

if __name__=="__main__":
app.run()
69 changes: 69 additions & 0 deletions final_work.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-
"""final2.ipynb

Automatically generated by Colaboratory.

Original file is located at
https://colab.research.google.com/drive/1Z01aBybX4M0oInJkPut3yzwSX0GI63EL
"""

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
path = 'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/DA0101EN/automobileEDA.csv'
df = pd.read_csv(path)
df.head()

from sklearn.linear_model import LinearRegression
#Create the linear regression object
lm = LinearRegression()
lm

Z = df[['horsepower', 'curb-weight', 'engine-size', 'highway-mpg']]
#Fit the linear model
lm.fit(Z, df['price'])

lm.fit(Z, df['price'])
# Find the R^2
lm.score(Z, df['price'])

from sklearn.metrics import mean_squared_error
# Produce a prediction
Y_predict_multifit = lm.predict(Z)
# Compare the predicted results with the actual results
# The mean square error of price and predicted value using multifit is:
mean_squared_error(df['price'], Y_predict_multifit)

import pandas as pd
import numpy as np

# Import clean data
path = 'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/DA0101EN/module_5_auto.csv'
df = pd.read_csv(path)

df.to_csv('module_5_auto.csv')
df = df._get_numeric_data()
df.head()

y_data = df['price']
x_data=df.drop('price',axis=1)

from sklearn.model_selection import train_test_split

x_train, x_test, y_train, y_test = train_test_split(x_data, y_data, test_size=0.15, random_state=1)

print("number of test samples :", x_test.shape[0])
print("number of training samples:",x_train.shape[0])

lr = LinearRegression()
lr.fit(x_train[['horsepower', 'curb-weight', 'engine-size', 'highway-mpg']], y_train)

yhat_train = lr.predict(x_train[['horsepower', 'curb-weight', 'engine-size', 'highway-mpg']])
yhat_train[0:5]

yhat_test = lr.predict(x_test[['horsepower', 'curb-weight', 'engine-size', 'highway-mpg']])
yhat_test[0:5]

import pickle
filename='model_1.sav'
pickle.dump(lr,open(filename,'wb'))
Binary file added model_1.sav
Binary file not shown.
13 changes: 13 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Flask==1.1.1
gunicorn==19.9.0
itsdangerous==1.1.0
jinja2==2.10.1
MarkupSafe==1.1.1
Werkzeug==0.15.5
numpy>=1.9.2
scipy>=0.15.1
scikit-learn>=0.18
matplotlib>=1.4.3
pandas>=0.19
tldextract==3.1.0

152 changes: 152 additions & 0 deletions templates/mainpafe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

</head>


<body>

<div style="color:white">

<form action="{{ url_for('predict')}}" method="post">
<h1>PRICE PREDICION</h1>
<h2></h2>
<h3>Hihgway milage</h3><input id="first" name="milage" type="number ">
<h3>Engine Size</h3><br><input id="second" name="size_of_the_engine" required="number">
<h3>Curb weight</h3><input id="third" name="weight_of_a_car" required="number">
<h3>Horse Power</h3><br><input id="fourth" name="power" required="number">

<br><br><button id="sub" type="submit ">Calculate</button>
<br>




</form>



<br><br><h3>{{ prediction_text }}<h3>
</div>




<style>
body {
background-color:green;
text-align: center;
padding: 0px;
}

#research {
font-size: 18px;
width: 100px;
height: 23px;
top: 23px;
}

#box {
border-radius: 60px;
border-color: 45px;
border-style: solid;
font-family: cursive;
text-align: center;
background-color: rgb(168, 131, 61);
font-size: medium;
position: absolute;
width: 700px;
bottom: 9%;
height: 850px;
right: 30%;
padding: 0px;
margin: 0px;
font-size: 14px;
}

#fuel {
width: 83px;
height: 43px;
text-align: center;
border-radius: 14px;
font-size: 20px;
}

#fuel:hover {
background-color: coral;
}

#research {
width: 99px;
height: 43px;
text-align: center;
border-radius: 14px;
font-size: 18px;
}

#research:hover {
background-color: coral;
}

#resea {
width: 99px;
height: 43px;
text-align: center;
border-radius: 14px;
font-size: 18px;
}

#resea:hover {
background-color: coral;
}

#sub {
width: 120px;
height: 43px;
text-align: center;
border-radius: 14px;
font-size: 18px;
}

#sub:hover {
background-color: darkcyan;
}

#first {
border-radius: 14px;
height: 25px;
font-size: 20px;
text-align: center;
font-family: serif;
}

#second {
border-radius: 14px;
height: 25px;
font-size: 20px;
text-align: center;
}

#third {
border-radius: 14px;
height: 25px;
font-size: 20px;
text-align: center;
}

#fourth {
border-radius: 14px;
height: 25px;
font-size: 20px;
text-align: center;
}
</style>
</body>

</html>