DSNotebook / MLDS

1 stars 0 forks source link

wine quality #3

Open DSNotebook opened 1 year ago

DSNotebook commented 1 year ago
In [1]:
C:\Users\ravik\Anaconda3\lib\site-packages\ipykernel\parentpoller.py:116: UserWarning: Parent poll failed.  If the frontend dies,
                the kernel may be left running.  Please let us know
                about your system (bitness, Python, etc.) at
                ipython-dev@scipy.org
  ipython-dev@scipy.org""")
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done   1 out of   1 | elapsed:    0.0s remaining:    0.0s
building tree 1 of 25
building tree 2 of 25
building tree 3 of 25
building tree 4 of 25
building tree 5 of 25
building tree 6 of 25
building tree 7 of 25
building tree 8 of 25
building tree 9 of 25
building tree 10 of 25
building tree 11 of 25
building tree 12 of 25
building tree 13 of 25
building tree 14 of 25
building tree 15 of 25
building tree 16 of 25
building tree 17 of 25
building tree 18 of 25
building tree 19 of 25
building tree 20 of 25
building tree 21 of 25
building tree 22 of 25
building tree 23 of 25
building tree 24 of 25
building tree 25 of 25
[Parallel(n_jobs=1)]: Done  25 out of  25 | elapsed:    0.8s finished
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done   1 out of   1 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done  25 out of  25 | elapsed:    0.0s finished
              precision    recall  f1-score   support

           3       1.00      1.00      1.00        23
           4       1.00      1.00      1.00       161
           5       1.00      1.00      1.00      1616
           6       1.00      1.00      1.00      2137
           7       1.00      1.00      1.00       796
           8       1.00      1.00      1.00       136
           9       1.00      1.00      1.00         3

    accuracy                           1.00      4872
   macro avg       1.00      1.00      1.00      4872
weighted avg       1.00      1.00      1.00      4872

Out[1]:
<matplotlib.axes._subplots.AxesSubplot at 0x208a080e978>
In [6]:
Out[6]:
  | list | name -- | -- | -- 0.12567 | alcohol

import matplotlib.pyplot as plt # To plot a graph from matplotlib import rcParams import numpy as np import pandas as pd import seaborn as sns import scipy as sc

sns.displot(df.TV)

from sklearn.linear_model import LinearRegression from sklearn.metrics import r2_score, mean_squared_error, mean_absolute_error from sklearn.model_selection import train_test_split from sklearn.preprocessing import scale from sklearn.model_selection import cross_val_score from collections import Counter from sklearn.preprocessing import MinMaxScaler,LabelEncoder

from sklearn.neural_network import MLPRegressor from sklearn.ensemble import RandomForestRegressor

import pickle import flask

#data=pd.read_csv("Advertising.csv")

file=r"C:\Users\ravik\Data Files\1. ST Academy - Crash course and Regression files\House_Price.csv" data=pd.read_csv(file)

Split the data

X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.20)#random_state=0

scale the data

minmax_scaler=MinMaxScaler() minmax_scaler.fit(X_train) X_train=minmax_scaler.transform(X_train)

X_test=minmax_scaler.transform(X_test)

In [3]:
In [4]:
Out[4]:
LinearRegression()
In [5]:

dump the model

pickle.dump(model_LR,open("Adverting_model_pickle.pkl",'wb'))

pickle.dump(minmax_scaler,open("Adverting_input_scaler.pkl",'wb'))

load the model

Adv_model=pickle.load(open("Adverting_model_pickle.pkl",'rb'))

input_scaler=pickle.load(open("Adverting_input_scaler.pkl",'rb'))

Directory structure Projectory Name / templates/ index.html/ app.py/ module.py

In [ ]:
In [ ]:
In [ ]:

Image

DSNotebook commented 1 year ago

Working file . Model should be dumped using pickle commnad not joblib

import numpy as np import pandas as pd

from flask import Flask, request, jsonify, render_template

import pickle

App = Flask(name)

model=pickle.load(open('wineQualitypredict.pkl','rb'))

input_scaler=pickle.load(open('wineQuality_input.pkl','rb'))

@App.route('/') def home(): return render_template('index.html') # Home page

@App.route('/predict', methods=['POST']) # Prediction def predict():

'''

For rendering results on HTML GUI
'''
int_features = [float(x) for x in request.form.values()]
final_features = [np.array(int_features)]

inp_data = input_scaler.transform([int_features])

feat=model.feature_importances_
feat
l=list(feat)
l=pd.DataFrame(l,columns=['list'])

bestfea=set(l.list)
featurename=l[l.list==feat.max()].iloc[:,1:]

prediction = model.predict(inp_data)      # 2-d array is reuqired as an input

output = str(round(prediction[0],2)) + ", Best feature index number :"+str(featurename) +'th'+'is :' + str(feat.max())

+ ", Radio - " + str(int_features[1])+", Newspaper - " + str(int_features[2])

return render_template('index.html', prediction_text='Predicted Wine quality is:{}'.format(output))

if name == "main": App.run(debug=True)