Skip to main content

Flask Deplyment of ML Models

 

from flask import Flask, request import numpy as np
import pickle
import pandas as pd
import flasgger
from flasgger import Swagger
app=Flask(__name__)
Swagger(app)
pickle_in = open("classifier.pkl","rb")
classifier=pickle.load(pickle_in)
@app.route('/')
def welcome():
return "Welcome All"
@app.route('/predict',methods=["Get"])
def predict_note_authentication():
"""Let's Authenticate the Banks Note
This is using docstrings for specifications.
---
parameters:
- name: variance
in: query
type: number
required: true
- name: skewness
in: query
type: number
required: true
- name: curtosis
in: query
type: number
required: true
- name: entropy
in: query
type: number
required: true
responses:
200:
description: The output values
"""
variance=request.args.get("variance")
skewness=request.args.get("skewness")
curtosis=request.args.get("curtosis")
entropy=request.args.get("entropy")
prediction=classifier.predict([[variance,skewness,curtosis,entropy]])
print(prediction)
return "Hello The answer is"+str(prediction)
@app.route('/predict_file',methods=["POST"])
def predict_note_file():
"""Let's Authenticate the Banks Note
This is using docstrings for specifications.
---
parameters:
- name: file
in: formData
type: file
required: true
responses:
200:
description: The output values
"""
df_test=pd.read_csv(request.files.get("file"))
print(df_test.head())
prediction=classifier.predict(df_test)
return str(list(prediction))
if __name__=='__main__':
app.run(host='0.0.0.0',port=8000)

Comments

Popular posts from this blog

Class Weights for Handling Imbalanced Datasets

In scikit-learn, a lot of classifiers come with a built-in method of handling imbalanced classes. If we have highly imbalanced classes and have not addressed it during preprocessing, we have the option of using the class_weight parameter to weight the classes to make certain we have a balanced mix of each class. Specifically, the balanced argument will automatically weigh classes inversely proportional to their frequency. import numpy as np import pandas as pd import seaborn as sns import warnings from imblearn.over_sampling import SMOTE from imblearn.pipeline import make_pipeline from pylab import rcParams from sklearn.linear_model import LogisticRegression from sklearn.metrics import accuracy_score from sklearn.metrics import precision_score , recall_score from sklearn.metrics import f1_score , roc_auc_score , roc_curve from sklearn.model_selection import train_test_split from sklearn.model_selection import GridSearchCV In [2]:...

Data Science and Data Scientist

Data Science:- When we combine domain expertise and scientific methods with technology, we get Data Science. Data Science Data Scientist:- Data Scientists collect data and explore, analyze, and visualize it. They apply mathematical and statistical models to find patterns and solutions in the data. Data Scientist