Using Python ML for Predictive Analytics

Hands-On Lab

 

Photo of John Marx

John Marx

Training Architect

Length

01:00:00

Difficulty

Beginner

This lab guides the student through Python examples that utilize metrics gathered from Prometheus. The Python Sci-Learn library is used for a Linear Regression example.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Using Python ML for Predictive Analytics

Introduction

This lab guides the student through Python examples that utilize metrics gathered from Prometheus. The Python Sci-Learn library is used for a Linear Regression example.

Solution

Start by logging in to the Kube Master Public IP using the credentials provided on the hands-on lab page:

ssh cloud_user@KUBE_MASTER_PUBLIC_IP

Install pip3

  1. The command to install pip3 is:

    sudo apt install python3-pip

Install Sci-Kit and Pandas Python modules

  1. Use the pip3 command to install Sci-Kit Learn:

    pip3 install scikit-learn

    And:

    pip3 install pandas

Review and run the check.py program

  1. To review the code, you can navigate to the GitHub repository and view the check.py file. The link is:

    https://github.com/linuxacademy/content-aiops-essentials/blob/master/check.py
  2. The command to run the program is:

    python3 check.py

Review and run the predictcpu.py and predictmem.py programs

  1. To review the programs, you may use the following links:

    For predictcpu:

    https://github.com/linuxacademy/content-aiops-essentials/blob/master/predictcpu.py

    For predictmem:

    https://github.com/linuxacademy/content-aiops-essentials/blob/master/predictmem.py
  2. To run the programs, the command is:

    python3 predictcpu.py

    And:

    python3 predictmem.py

Change the number of replicas to project

  1. To change the number of replicas to project, edit the following file:

    vi promql2.csv

    And then change the data column for replicas to the values you want to project.

Conclusion

Congratulations, you've completed this hands-on lab!