Video není dostupné.
Omlouváme se.
Deploy Machine Learning Model Flask
Vložit
- čas přidán 9. 04. 2021
- Deploy Machine Learning Model Flask
Github Code Link: github.com/sid...
GitHub Data: github.com/sid...
About this video: In this video, you will learn how to develop a machine learning model and how to deploy it using Flask
Large Language Model (LLM) - LangChain
LangChain: • LangChain Tutorial for...
Large Language Model (LLM) - LlamaIndex
LlamaIndex: • LlamaIndex Tutorial fo...
Machine Learning Model Deployment
ML Model Deployment: • ML Model Deployment us...
Spark with Python (PySpark)
PySpark: https: • PySpark with Python
Data Preprocessing (scikit-learn)
Data Preprocessing Python: • Data Preprocessing Python
Social Media Links
CZcams: / statswire
Twitter (X) : / statswire
#llm #ai #genai #generativeai #statswire #pyspark #python #pythonprogramming #pythontutorial #machinelearning #datascience
#ModelDeployment #MachineLearning #Flask
Please watch the video in full screen because the font size is a little small, also download the entire code from GitHub, the link is provided in the description so you can increase the font size and change the theme if you want in your local machine. Thank you for watching.
Here is the code link: github.com/siddiquiamir/ML-MODEL-DEPLOYMENT-USING-FLASK
🎯 Key points for quick navigation:
00:00 *Learn to create and deploy a machine learning model using Flask.*
00:14 *Steps: Build ML model, deploy with Flask, include `model.py` for the model and `app.py` for Flask application.*
00:28 *Create `model.py` for ML model, convert to pickle, and create `app.py` for Flask app.*
00:55 *`index.html` will contain HTML code, and `iris.csv` is the data for the model.*
01:10 *Use PyCharm IDE for development; other IDEs like Visual Studio or Spyder can also be used.*
01:22 *Create folder `ml_model_deployment` in C drive and place `iris.csv` and template folder inside.*
02:32 *`index.html` contains HTML fields for input independent variables which will be used for prediction.*
03:12 *Open PyCharm, navigate to the created folder, and start creating `model.py`.*
04:26 *Import necessary libraries like pandas, sklearn, and random forest classifier for ML model development.*
05:44 *Load `iris.csv` using pandas and display the first five rows to verify.*
07:24 *Identify independent variables (sepal length, sepal width, petal length, petal width) and dependent variable (class).*
09:13 *Split data into train and test sets; apply feature scaling on independent variables.*
11:41 *Instantiate random forest classifier and fit it on training data.*
13:19 *Create a pickle file of the model for later use in the Flask app.*
15:37 *Verify the files: `model.py`, `model.pkl`, `index.html`, and `iris.csv`.*
16:05 *Create `app.py` for the Flask application and import needed libraries.*
17:56 *Load the previously created pickle model within the Flask app for making predictions.*
19:07 *Define the homepage and prediction route for the Flask app.*
21:11 *Convert received form values to float and then to numpy arrays for prediction.*
23:51 *Return prediction results to be displayed on `index.html`.*
25:42 *Run the Flask app and access it via the browser to input values and make predictions.*
28:12 *Summary: Build ML model, create pickle file, set up Flask app, define prediction method, and ensure model deployment.*
Made with HARPA AI
Thank you
Thanks buddy. That helped me a lot.
Glad to hear it!
* Serving Flask app "__main__" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Restarting with watchdog (windowsapi)
An exception has occurred, use %tb to see the full traceback.
SystemExit: 1
Maybe you are using it in jupyter file like .ipynb , try using same code in .py file
Could you please clarify this moment:
'''return render_template("index.html",prediction_text = "The flower species is {}".format(prediction))'''
format(prediction) - displays the results as list, but I need to display the results as a table having all elements written from a new line /n. Is there some way to do it with format() function?
I am performing the same steps for my model. My site is getting created but when in give values to all the features and click predict, it gives me error saying that:- "ValueError: Specifying the columns using strings is only supported for pandas DataFrames
Traceback (most recent call last)". I have tried giving both float and int values to the features on the site but get the same error. Please help me!
Check if there are any missing values in the columns. Remove all missing values then follow all the steps you won't get this error
For a better page layout use the jinja template and CSS. You will get it online.
thank you very helpful
You're welcome!
Thank you, you save my assignment! 😂
You're welcome :-)
This is what I was looking for exactly
Thank you
Thank you so much brother for the great explanation and amazing stuff. Best wishes to success you all work in all possible ways. 🤩 I was able to deploy it using VS Code.
Thank you for your kind words and lovely wishes!
Thanks, but I have a doubt, what if u have 2 models, and user can choose one of these model, give the input, how to do this, basically we will be having 2 pickle files
Yes, you are correct we will have two pickle files. You can put them on two different ports. if they are connected to each other like taking the output of the model and giving it as an input to the other model then we can make only one final pickle file.
how could I access the website through any device and how do I make the data I plug in to be able to be used to retrain the model
Appreciate the efforts, thank you❤
You're welcome!
Thank you so much, it helped me to deploy in easy manner.
You're welcome!
Please also elaborate on html file content n how are we migrating between different html pages
HTML is a different concept in itself that's why I did not go deeper into it but you can find online resources to understand the basics.
Thank u sir.... Good Lecture and very helpful......
You're welcome!
Very good video sir. Thank You . I have one doubt templates folder how to make sir
Please let me know
Thanks for the tutorial. Can I use this if my model takes one image and several numerical features and then predicts? I mean how to handle the image part
I have not tried it with image, but ideally it should work with some minimal changes.
can i use the same procedure for the model developed using jupyter notebook
Yes, it should work.
Really learnt from this.
But one thing sir, during the prediction stage, u only converted to float but you didn't use standardScaler on the prediction variables as you have done for the training set.Hope this won't affect the answer?
Thank you, it would be good if you apply the same scaler object that you used to fit on the training data on unseen data you will get better results
Thanks for the quick reply.
That is the problem here sir, How do I apply it sir? + let's say during the training, we did some feature extraction like onehotencoding, how can we apply it to the unseen data?
Between, can you drop ur mail?
THANKS.
@@StatsWire ., Please I need a reply to the above comment sir
You'll have to store (i.e. pickle) your fitted LabelEncoders and OneHotEncoder. When you receive new data, you'll transform them via the already-fitted LabelEncoders and OneHotEncoder and then use your trained model to make the predictions. This way, the produced data will be in the exact format your models expects them to be
Hi sir,
1) please do let me know how to create a html of ml
2) this deployment is on local machine,please advise how to deploy on cloud like gcp,azure,aws..
3) please also send any links related to other projects for practice.
Thank you very much for your valuable information 😀....thanks & Regards
Hi
1) To create more beautiful html of ml you have to use jinja. This is the link jinja.palletsprojects.com/en/3.0.x/
2) You can deploy on cloud very easily, it's almost same you just need to create an account on heroku or aws. If you are comfortable with flask then you can deploy anywhere on cloud or azure, aws etc
3) You should also look at this video to know you can test on on postman. This is the video link: czcams.com/video/HxLm-kZlXgU/video.html
@@StatsWire thank you vvv much sir, ...plz do an example with Google cloud platform it will be really appreciable.thanks and regards
@@aa4734 Sure, I will make a video soon. Thank you for the great suggestion.
Can You Please help me .
Why am I getting this Error:
ValueError: Number of features of the model must match the input. Model n_features is 132 and input n_features is 131
Because there is mismatch between number of features in training data and prediction data. Make sure you have same number of columns in both train and prediction dataset.
@@StatsWire
Thanks just now solved it out
The issue was due to some reasons column name was inside trained model was different then name inside dataset
@@psgoat1111 Great you have solved the error on your own
Wonderful Explaination.
! am glad you liked it! Thank you
Very well explained. Good Job!
Glad you liked it
This is very help full for me
I'm glad you liked it. Thank you for your comment :-)
I am a newbie can u plzz tell me know what did actually request.forms.values() did in code on line no.17
It is getting the values in that line
Dear Sir, Thank you very much for the video. It is really good. One small request, instead of printing the final decision, can you please provide details on how to return the probabilities for each class for given input values
HI, yes, we can print probabilites. You can use this function predict_proba
anaconda navigator also contain pycharm .. should we open that one ?? or should we have to install pycharm seperatly
I'm not sure but it has spyder I guess. We have to install pycharm separately.
I want to implement disease Prediction using symptoms
In my Dataset I have 132 symptoms
Can u suggest me something so that
I can get 1 for selected symptoms and 0 for not selected symptoms
You can convert symptoms to 1 and 0 and then train your model
@@StatsWire
They are trained in 1 and 0 only
But while talking inputs I am not able to understand how to do so
@@psgoat1111 You have to convert your input data also into 1 and 0 then pass to the model
Hello
I was able to do exactly as was done in the tutorial with same data and all but when I try to open the link created I get error saying "template not found"
Please what can I do to resolve this
I guess you have not kept the HTML file in the correct location. Please check once.
Thanks. Just one thing, I think you are missing the preprocessing for the prediction part.
You're welcome. Yeah, that can be done. You can experiment with many more things.
Thank you for a wonderful explanation!
I am glad you liked it!
VSCODE error while running app.py. DLL load failed while importing _multiarray_umath: The specified module could not be found.
It is due to the conda path, you have to add Python.CondaPath in settings. Press Ctrl + Shift + P and select Terminal Configuration. Search for python.conda, and paste your conda path for example. C:\ProgramData\Anaconda3\Scripts\conda.exe
This was very helpful thank you
Glad it was helpful!
thank you Sir, Is this method also applicable in the domain of deep learning ?
Yes, it is.
Thanks. If I have categorical variables as X, how to handle them as predictors?
You need convert it to numerical first.
you are a life saver,,,thanks a lot. it was really helpful :)
You're welcome:)
To the point video, thanks bro!
You're welcome
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
This is what im getting after running on web. plz hepl me sir with this issue
Let me check
somewhere i read that there should be created a seperate environment for every project.. plz share link about the same (if you have already created the video on this issue) .
We can create a virtual environment also and then do the project. You can watch my video on pycaret installation where I've created a virtual environment.
@@StatsWire thank you
@@ddbshri You're welcome
Very nice tutorial
Thank you
Got this error while loading the model
Traceback (most recent call last):
File "C:/ML Model Deployment/app.py", line 7, in
model = pickle.load(open("model.pkl", "rb"))
_pickle.UnpicklingError: invalid load key, 'A'.
How to resolve. Please help
I think you did not pickle it correctly. Can you please try the steps again one by one and see if it still throws an error
@@StatsWire tried multiple times sir still it throws the same error
@@srigayathriarunachalam3370 This error is related to the code in app.py file. For this, we need to examine the code written inside the app.py file.
Informative 👍
Thank you
in which hosting website can we host
That depends where you want to host it. Mostly people host it locally.
hi can u explain how we will deploy wordcloud model
Hello, you can create an object of that word cloud model, make an HTML file, and then deploy it. You will have to make changes in the HTML.
Thank a lot Sir!!!
You're welcome!
Good day bro.I have a model that i created using jupyter notebook .Which root should i take
Convert it to .py file and then you can follow all the steps.
my ide is asking to register for the file type of model.pkl. how to resolve it?
Hi, can you please paste the error? So I can help you
metadata-generation-failed. this error shows on installing sklearn . what to do?
Please paste the exact error.
I was getting this error
"ValueError: X has 4 features, but DecisionTreeClassifier is expecting 3 features as input."
Because after training the model using on 3 features you are passing 4 features for prediction. Please see if you are passing only 3 variables. Go through the code again it's a minor error you will be able to correct it.
AttributeError: 'DecisionTreeClassifier' object has no attribute 'n_features_' I'm getting this error when I'm trying to run my app.py file. But thing is that I've saved the model that is RandomForestClassifier. So what is the error can u please help me. and thanks for your video. it makes easier to me to understand the whole code in Flask. Please help me with that error. thanks in advance.
Hello! DecisionTreeClassifier doesn't have such a method indeed.
I'm currently working on ML project on the topic of "Animal endangered species prediction"..but I'm don't know how to collect datasets for this
So, can you sir please guide me in the dataset part please..?!!!
Hope you will help me!!
Waiting for ur reply
Hi Harini, you can get the dataset online. You can find it on Kaggle or UCI
UCI: archive.ics.uci.edu/ml/index.php
Kaggle: www.kaggle.com
No words only ❤
Thank you:)
How did handle you the user input to be transformed to standard scaler ?
Using standard scaler
@@StatsWire No shit Sherlock
Nice video
Very nice
Thank you so much Sir.
You're welcome Susanth
Sir . I could create virtual environment using conda in the command prompt , but not able to integrate it with pPycharm. Could you please help me Sir ?
@@ssnayakmusic I think you should not face any problem. Can you tell what errors are you getting? May be I can refer you some videos based on that
Thanks 🙏
You're welcome
Hi Sir...Hi I'm deploying my first ML model using flask. I did exactly the same you explained in the video but when I'm trying to run app.py file using Spyder, it's saying "Restarting with windowsapi reloader" repetedely and not giving me the url. Please help
same problem i am facing, have you rectified yours please?
where was the deployment section ?
It is in the same video
model.pkl is not created. why?
Can you please try it again from start. It should work.
I want to know what happened to the feature scaling you did in the model.py
How the data that i give will be scaled??
Those features will come on the same scale and it will give you stable results otherwise your results would not be stable if the features are on the different scales
@@StatsWire let's say i am doing nlp.
Where my words are going through all processes like stop word removal lemmatization, tfidf etc.
How will these be applied to unseen data that i pass???
@@gracehim9154 You will have to pass your unseen data through all the steps you have done for the training data then only it will work. Like when you test your model that test data also goes through the same preprocessing steps along with the train data
Thanks a lot
You're welcome
Can we use jupyter notebook
It will be difficult to maintain all the files
bro pls make a video for deployment with heroku
Thank you for the suggestion. I will make it soon.
do we have to write something in "index.html"
It has HTML codes already written. You can download it from my github repository and use it. But if you want to add something extra then you can edit the index.html file
@@StatsWire thanks a lot
@@abhishekkumaragrawal1372 you're welcome
Good video bro but my model has both string and float variables then how to perform flask code plz help me
Thanks in advance
No problem even my model has both string and float you just have to first convert to one-hot encoding in machine learning, and in flask, I have converted it into float so you will not face any problem. Just follow the steps. You can see it here in app.py "float_features = [float(x) for x in request.form.values()]" we are converting all features into float. Do not worry just follow the steps.
@@StatsWire can you please provide ur code if it is in github 😊
@@umarfaruk-bq3qg Sure, this is the code link
github.com/siddiquiamir/ML-MODEL-DEPLOYMENT-USING-FLASK
@@StatsWire In this are u use one hot encoding bro?
By doing my app. py like this I get
value error: could not convert string to float :'Year'
Can u plz help me
Thanks in advance
First convert Year into int type in your model.py by typecasting for ex df["Year"] = int(df["Year"]) once you do that in app.py it will automatically convert this into float using the below function
float_features = [float(x) for x in request.form.values()]
how did u get that .csv file?
You can find code and csv file here: github.com/siddiquiamir/ML-MODEL-DEPLOYMENT-USING-FLASK
Great video but I was straining my eyes to see your screen. Fonts were too small and it was really dark
Sorry to hear that, I should have increased the font size I realized after reading your comment. Thanks for the constructive feedback, I will keep that in mind in future videos, and make good ones. I have posted the PyCharm code link please go and download it from GitHub, so you can see it on your system and change the font size as well as the dark theme to light one. Thank you again for the great feedback.
Thanks a lot. It was not too bad though. I just had to put the video in full screen to be able to follow. Really informative video and clear explanations 👍
@@davidobembe5302 Thank you for the feedback. I appreciate it.
I have got the jinja2.exceptions.TemplateNotFound error
Have you imported flask?
@@StatsWire even i have got the same error. i have imported flask
@@manasiraut8091 can you paste the exact error?
why the web can't be reached sir?
Maybe some problem with your port. Please try again.
how to create html file sir
It's very easy. You can write code in any IDE like sublime text and just write the file extension as .html that's it
while running the app i getting following error
Which error?
This is the development server don’t use the
This is development server
This is development server
Don’t use the production server
Hello Sir... I find this video very educative while following the video and trying,i encountered an error in the app.py. the error says "Traceback (most recent call last):
File "C:\ML Model Deployment\app.py", line 10, in
model = pickle.load(open("model.pkl", "rb"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
EOFError: Ran out of input
"
i wanted to see how your model.pkl file is but unfortunately i couldn't because it's not opening, and i noticed that my model.pkl file has nothing in it
Sir if you can help me solve this problem i will really appreciate
Thank you!
Can you check step by step where the problem is coming.
I did check Sir, but i can’t seem to find any problem
can you give that git repository link
Yes, I have just updated the github link. Please go on this link to download the code.
github.com/siddiquiamir/ML-MODEL-DEPLOYMENT-USING-FLASK
Thanks buddy🤗
@@krentwhite2668 You're welcome. A new video is coming today, how to test your model using postman after deploying on flask
you are awesome dude! keep it up... we will support🔥🔥🔥
@@krentwhite2668 Thank you