![]() |
Machine learning is a widely employed method for making predictions. Numerous algorithms are accessible in different libraries for predictive tasks. In this article, we’ll construct a placement prediction model using Random Forest Classifier with historical data and later we will store that model to .pkl file to integrate it with our Flask app using Python. Placement Prediction in ML using FlaskThe motive behind this project is to predict the chance or probability of students getting placed in campus placement drives. Our motive would be to create a full working application that would make predictions. For all this, we require a basic knowledge of Flask, HTML, and Machine Learning. We’ve taken historical campus placement data and constructed a robust model that can forecast your chances of getting placed. Topics Covered
Steps for Creating a Placement Prediction AppStep 1: Create a virtual environmentOpen Anaconda Navigator and Launch vs-code or open any other IDE like Pycharm. To create a virtual Environment write the following code in the terminal.
![]() ing1: to create an environment Step 2: Create a Predictive modelplacement.py In this code, a dataset (‘Placement_Data_Full_Class.csv’) is loaded using pandas, and Label Encoding is applied to convert categorical variables (gender, ssc_b, hsc_b, hsc_s, degree_t, workex, specialisation, status) into numerical format. Missing values in the ‘salary’ column are filled with the median. The dataset is split into features (X) and target variable (y). A RandomForestClassifier with 26 estimators is trained on the training set, and the resulting model is saved as ‘placement.pkl’ using the pickle module. Dataset: Dataset link Python3
Now, paste the above code into your .py file and run it using python <Name of File>.py in the terminal. After running the code, a .pkl file would be generated. Output ![]() img2: .pkl file generated Step 3: Setting up GUIfront.html: This code creates a Flask web application that lets users input data. When users submit the form, the data is used to make predictions with a pre-trained machine learning model. The results are then displayed on a webpage. The ‘placement.pkl’ model is loaded using the ‘pickle’ library. HTML
Output home.html: The page displays a result message, which can be either “Congratulations!!!” in green if the prediction is positive or “Sorry!” in red if the prediction is negative. This code also converts the numeric values(input values) into human readable text(e.g., ‘0’ for gender becomes ‘Female’). HTML
Output Step 4: App Codeapp.py: This app.py creates a Flask web application to serve a machine learning model. Users input data through a form, and the code passes this data to the model to make predictions. The results are then displayed on a web page. The pickle library is used to load the pre-trained model, and Flask handles the web interface and routing. Python3
Step 5: Running the app on local host.Just write “python app.py” on the terminal and this would be generated. After that just click on the “http://127.0.0.1:5000” and you would be redirected to a webpage, which would the homepage of the application. ![]() app running on local host After filling all the information click on predict. Output ![]() Final Prediction And your model is ready to predict. Video Demonstration |
Reffered: https://www.geeksforgeeks.org
Python |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |