diff --git a/app.py b/app.py new file mode 100644 index 0000000..45009de --- /dev/null +++ b/app.py @@ -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() \ No newline at end of file diff --git a/final_work.py b/final_work.py new file mode 100644 index 0000000..f52852f --- /dev/null +++ b/final_work.py @@ -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')) \ No newline at end of file diff --git a/model_1.sav b/model_1.sav new file mode 100644 index 0000000..928e45c Binary files /dev/null and b/model_1.sav differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f5389d9 --- /dev/null +++ b/requirements.txt @@ -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 + diff --git a/templates/mainpafe.html b/templates/mainpafe.html new file mode 100644 index 0000000..aaf593b --- /dev/null +++ b/templates/mainpafe.html @@ -0,0 +1,152 @@ + + + + + + + Document + + + + + + + +
+ +
+

PRICE PREDICION

+

+

Hihgway milage

+

Engine Size


+

Curb weight

+

Horse Power


+ +

+
+ + + + +
+ + + +

{{ prediction_text }}

+

+ + + + + + + + \ No newline at end of file