Skip to content

madhurimarawat/Machine-Learning-Projects-In-Python

Repository files navigation

Machine-Learning-Projects-In-Python

This repository contains machine learning projects in the Python programming language.


Mode of Execution Used PyCharm Flask API

Pycharm

--> Visit the official website of pycharm: PyCharm

--> Download according to the platform that will be used like Linux, Macos or Windows.

--> Follow the setup wizard and sign up for the free version (trial version) or else continue with the premium or paid version.

--> First, in pycharm we have the concept of virtual environment. In virtual environment we can install all the required libraries or frameworks.

--> Each project has its own virtual environment, so thath we can install requirements like Libraries or Framworks for that project only.

--> After this we can create a new file, various file types are available in pycharm like script files, text files and also Jupyter Notebooks.

--> After selecting the required file type, we can continue the execution of that file by saving it and using this shortcut shift+F10 (In Windows).

--> Output is given in Console while installation happens in terminal in Pycharm.

Flask Server

--> Flask is a micro web framework written in Python.

--> It is classified as a microframework because it does not require particular tools or libraries.

--> Flask supports extensions that can add application features as if they were implemented in Flask itself. --> To install flask in your system, just run this command-

pip install flask

Running Project in Flask Server

Make Sure all depencies are already satisfied before running the app.

  1. Ensure that you are in the project home directory.Create the machine learning model by running below command -

    --> This machine_learning_model.py file contains the code for the amachine learning model.
python machine_learning_model.py

This would create a serialized version of our model into a file model.pkl

  1. Run app.py using below command to start Flask API

    --> This app.py file contains the code for the flask app
python app.py

By default, flask will run on port 5000.

  1. Navigate to URL http://localhost:5000

You should be able to view the homepage as below :

Homepage
Enter valid numerical values in all the input boxes and hit Predict. Here I have entered 8.

If everything goes well, Predicted Value will be shown on the HTML page!

Screenshot 2023-08-26 133516

๐ŸŒŸ Project and Models will change but this process will remain the same for all flask projects.


About Projects ๐Ÿ“‘

Complete Description about the project and resources used.

Project Structure

Each project has four major parts :

  1. machine_learning_mode.py - This contains code for Machine Learning model to predict output based on input from a dataset file.
  2. app.py - This contains Flask APIs that receives details through GUI or API calls, computes the precited value based on our model and returns it.
  3. templates - This folder contains the HTML template to allow user to enter details and displays the predicted value.
  4. static- This folder contains the css for the HTML file.

Linear Regression Salary Prediction

--> First ML model is constructed using linear regression for the dataset.

--> Then this model is saved using pickle in disk with the extention .pkl(Pickle File).

--> The Homepage is designed for flask app.

--> After this the flask app code is written.

--> Finally we can run this app in the flask Server.

Dataset Used

Salary Dataset

--> Dataset is taken from: Salary Dataset

--> Contains Salary data for Regression.

--> The dataset has 2 columns-Years of Experience and Salary and 30 entries.

--> Column Years of Experience is used to find regression for Salary.

--> Dataset is already cleaned,no preprocessing required.

Algorithm Used

Linear Regression

--> Regression: It predicts the continuous output variables based on the independent input variable. like the prediction of house prices based on different parameters like house age, distance from the main road, location, area, etc.

--> It computes the linear relationship between a dependent variable and one or more independent features.

--> The goal of the algorithm is to find the best linear equation that can predict the value of the dependent variable based on the independent variables.

Naive Bayes Classifier Diabetes Prediction

--> First ML model is constructed using Naive Bayes Classifier for the dataset.

--> Then this model is saved using pickle in disk with the extention .pkl(Pickle File).

--> The Homepage is designed for flask app.

--> After this the flask app code is written.

--> Finally we can run this app in the flask Server.

Dataset Used

Naive bayes classification data

--> Dataset is taken from:

--> Contains diabetes data for classification.

--> The dataset has 3 columns-glucose, blood pressure and diabetes and 995 entries.

--> Column glucose and blood pressure data is to classify whether the patient has diabetes or not.

--> Dataset is already cleaned,no preprocessing required.

Algorithm Used

Naive Bayes Classifiers

--> Naive Bayes classifiers are a collection of classification algorithms based on Bayesโ€™ Theorem.

--> It is not a single algorithm but a family of algorithms where all of them share a common principle, i.e. every pair of features being classified is independent of each other.

--> The fundamental Naive Bayes assumption is that each feature makes an independent and equal contribution to the outcome.

Random Forest Car Evaluation

--> First ML model is constructed using Naive Bayes Classifier for the dataset.

--> Then this model is saved using joblib in disk with the extention .pkl(Pickle File).

--> The Homepage is designed for flask app.

--> After this the flask app code is written.

--> Finally we can run this app in the flask Server.

Dataset Used

Cars Evaluation Dataset

--> Dataset is taken from: Cars Evaluation Dataset

--> Contains information about cars with respect to features like Attribute Values:

1. buying v-high, high, med, low 2.maint v-high, high, med, low 3.doors 2, 3, 4, 5-more 4. persons 2, 4, more 5. lug_boot small, med, big 6.safety low, med, high
--> Target categories are:

1. unacc 1210 (70.023 %) 2. acc 384 (22.222 %) 3. good 69 ( 3.993 %) 4. v-good 65 ( 3.762 %)
--> Contains Values in string format.

--> Dataset is not cleaned, preprocessing is required.

Algorithm Used

Random Forest

--> It is based on the concept of ensemble learning, which is a process of combining multiple classifiers to solve a complex problem and to improve the performance of the model.

--> Instead of relying on one decision tree, the random forest takes the prediction from each tree and based on the majority votes of predictions, and it predicts the final output.

--> The greater number of trees in the forest leads to higher accuracy and prevents the problem of overfitting.

Libraries Used ๐Ÿ“š

Short Description about all libraries used in Project.

To install python library this command is used-

pip install library_name
  • NumPy (Numerical Python) โ€“ Enables with collection of mathematical functions to operate on array and matrices.
  • Pandas (Panel Data/ Python Data Analysis) - This library is mostly used for analyzing, cleaning, exploring, and manipulating data.
  • Matplotlib - It is a data visualization and graphical plotting library.
  • Scikit-learn - It is a machine learning library that enables tools for used for many other machine learning algorithms such as classification, prediction, etc.
  • Pickle- The pickle module is used for implementing binary protocols for serializing and de-serializing a Python object structure.
  • Joblib- Joblib is a set of tools to provide lightweight pipelining in Python. In particular transparent disk-caching of functions and lazy re-evaluation (memoize pattern) and easy simple parallel computing.

Additional Resources ๐Ÿงฎ๐Ÿ“š๐Ÿ““๐ŸŒ

To see more of my machine learning models, visit my repository: https://github.com/madhurimarawat/Machine-Learning-Using-Python


Thanks for Visiting ๐Ÿ˜„