/ZDMP

Industry 4.0 Optimization with Machine Learning AI

Primary LanguagePythonApache License 2.0Apache-2.0

Required Repositories to complete the system



ZDMP System




Logo


Contributing · Issues

License   Version



Table of Contents

About The Project

The ZDMP project is a European project created by a consortium of 40 entities, whose main objective is to provide a reference digital platform for the achievement of the "zero defects" objective, with which it is intended to support quality improvement both both in processes and in products. Manufacturing high-quality products at low cost is the best way for Europe to maintain leadership in the manufacturing industry and remain competitive in a global marketplace. This industry is in the midst of a digital transformation process, due to the proliferation and increase of new technological solutions, which are incorporated into the production chain to make it more efficient (Smart Factories and industry 4.0).

This is a project that aims to provide a reference digital platform for the achievement of the "zero defects" objective, with which it is intended to support quality improvement both both in processes and in products. All of this content comes from iti.es ZDMP Datathon and Hackaton.

Requirements

Required Repositories to complete the system

Project

Components

Getting Started

To train and use the the core of the system you need to follow the next steps.

Prerequisites

"dependencies": [
    {
        "name": "pandas",
        "version": "1.5.2"
    },
    {
        "name": "scikit-learn",
        "version": "1.2.0"
    },
    {
        "name": "numpy",
        "version": "1.23.5"
    },
    {
        "name": "matplotlib",
        "version": "3.6.2"
    },
    {
        "name": "Flask",
        "version": "2.2.2"
    }
]

Installation

  1. Clone the repo
git clone https://github.com/ZhengLinLei/ZDMP.git
  1. Install components
git clone https://github.com/ZhengLinLei/ZDMP-datasets.git
git clone https://github.com/ZhengLinLei/ZDMP-client.git
  1. Install requirements
pip install -r requirements.txt
  1. Get datasets and locate it into the datasets folder

  2. Config the .ini

{
    "dataset": {
        "path": "datasets/batch_data.csv",
        "name": "batch_data",
        "predict": "datasets/predict.json",
        "batch_size": 32,
        "shuffle": true
    },
    "build": {
        "path": "build",
        "data": "data.png",
        "model": "model.pkl",
        "module": "pickle"
    },
    "server": {
        "host": "127.0.0.1",
        "port": 5000
    }
}

Usage

Analyze the data

To analyze the data run the below script, all analysis can be found in the src/ folder.

python src/data.py

And you will get the following output as image.

Data

Run the training and evaluation

To get the best model run the below script, all models can be found in the src/models folder.

python src/train_eval.py

After the training and evaluation process, the data will be printed.

               Method  Training MSE     Training R2             Test MSE                Test R2        Time
 0  Linear regression      0.026466        0.651201    2603143596.200458    -34521933304.644592          4s
 1      Random forest      0.054894        0.276561             0.053715               0.287655      1m 30s
 2        KNNeighbors      0.000056        0.999266             0.014994               0.801152      1m  2s
 3                SVM      0.044920        0.408009             0.043429               0.424063      6m  4s

Run the model training

After running the src/train_eval.py script, the data sciencetist can choose the best model to train it.

               Method  Training MSE     Training R2             Test MSE                Test R2        Time
 0  Linear regression      0.026466        0.651201    2603143596.200458    -34521933304.644592          4s ----> Worst model
 1      Random forest      0.054894        0.276561             0.053715               0.287655      1m 30s
 2        KNNeighbors      0.000056        0.999266             0.014994               0.801152      1m  2s ----> Best model
 3                SVM      0.044920        0.408009             0.043429               0.424063      6m  4s

Change the model variable in the src/train.py file to the best model.

# Import KNN model
from models.KNNeighbors import KNNModel

# Create the model
model = KNNModel()

To train the model run the below script.

python src/train.py

The model trainned will be saved in the build folder.

Run the server

To run the server run the below script.

python src/

The server will listen all the request to make predictions. The source of code of prediction can be found in the src/predict.py file.

# Create the route
@app.route('/predict', methods=['POST'])
def predict_api():
    # Get the data
    data = request.get_json(force=True)

    # Make prediction
    prediction = predict(data, os.path.join(CURRENT_PATH, CONFIG['model']['path']))

    # Return the prediction
    return jsonify(prediction)

Run the client

Read the ZDMP-Client (Pending to be updated) repository to know how to run the client. The client will send the request to the python server to make predictions.

Client Client Client

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

How to contribute:

  1. Fork the Project
  2. Clone your repository (git clone repo_url)
  3. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  4. Commit your Changes (git commit -m 'Add some AmazingFeature')
  5. Push to the Branch (git push origin feature/AmazingFeature)
  6. Open a Pull Request

License

Distributed under the Apache 2.0 License. See LICENSE for more information.

Contact

Project Link: https://github.com/ZhengLinLei/ZDMP

Acknowledgements

References